otsdaq  3.07.00
FEVInterface.h
1 #ifndef _ots_FEVInterface_h_
2 #define _ots_FEVInterface_h_
3 
4 #define TRACEMF_USE_VERBATIM 1 // for trace longer path filenames
5 #include "artdaq/DAQdata/Globals.hh"
6 
7 #include "otsdaq/Configurable/Configurable.h"
8 #include "otsdaq/FECore/FESlowControlsWorkLoop.h"
9 #include "otsdaq/FiniteStateMachine/VStateMachine.h"
10 #include "otsdaq/WorkLoopManager/WorkLoop.h"
11 
12 #include "otsdaq/CoreSupervisors/CoreSupervisorBase.h"
13 
14 #include "otsdaq/SupervisorInfo/AllSupervisorInfo.h" //to send errors to Gateway, e.g.
15 
16 #include "otsdaq/FECore/FESlowControlsChannel.h"
17 #include "otsdaq/SOAPUtilities/SOAPMessenger.h" //for xdaq::ApplicationDescriptor communication
18 
19 #include <array>
20 #include <iostream>
21 #include <string>
22 #include <vector>
23 
24 #include "otsdaq/Macros/CoutMacros.h"
25 
26 #define __ARGS__ \
27  [[maybe_unused]] const frontEndMacroStruct_t & feMacroStruct, \
28  [[maybe_unused]] FEVInterface::frontEndMacroConstArgs_t argsIn, \
29  [[maybe_unused]] FEVInterface::frontEndMacroArgs_t argsOut
30 
31 #define __GET_ARG_IN_NO_DEFAULT__(X, Y) getFEMacroConstArgumentValue<Y>(argsIn, X)
32 #define __GET_ARG_IN_DEFAULT__(X, Y, D) getFEMacroConstArgumentValue<Y>(argsIn, X, D)
33 #define GET_4TH_ARG(arg1, arg2, arg3, arg4, ...) arg4
34 #define __GET_ARG_IN_CHOOSER__(...) \
35  GET_4TH_ARG(__VA_ARGS__, __GET_ARG_IN_DEFAULT__, __GET_ARG_IN_NO_DEFAULT__, )
36 #define __GET_ARG_IN__(...) __GET_ARG_IN_CHOOSER__(__VA_ARGS__)(__VA_ARGS__)
37 #define __GET_ARG_OUT__(X, Y) getFEMacroArgumentValue<Y>(argsOut, X)
38 
39 #define __SET_ARG_IN__(X, Y) FEVInterface::emplaceFEMacroArgumentValue(argsIn, X, Y)
40 #define __SET_ARG_OUT__(X, Y) FEVInterface::setFEMacroArgumentValue(argsOut, X, Y)
41 
42 // clang-format off
43 #define PLOTLY_PLOT "Plotly_Plot"
66 
67 namespace ots
68 {
69 class FEVInterfacesManager;
70 
80 class FEVInterface : public WorkLoop, public Configurable, public VStateMachine
81 {
82  friend class FEVInterfacesManager;
83 
84  public:
86  const std::string& interfaceUID,
87  const ConfigurationTree& theXDAQContextConfigTree,
88  const std::string& configurationPath);
89 
90  virtual ~FEVInterface(void);
91 
92  virtual void setParentPointers(CoreSupervisorBase* supervisor,
93  FEVInterfacesManager* manager);
94 
95  FEVInterfacesManager* parentInterfaceManager_ = nullptr;
96 
97  const std::string& getInterfaceUID (void) const { return interfaceUID_; }
98  const std::string& getInterfaceType (void) const { return interfaceType_; }
99 
100  virtual void universalRead (char* address, char* returnValue) = 0;
101  virtual void universalWrite (char* address, char* writeValue) = 0;
102  const unsigned int& getUniversalAddressSize (void) { return universalAddressSize_; }
103  const unsigned int& getUniversalDataSize (void) { return universalDataSize_; }
104  virtual void universalBlockRead (char* address, char* returnValue, unsigned int numberOfBytes) { throw std::runtime_error("UNDEFINED BLOCK READ"); /* to make compiler happy, use params */ __COUTV__((void*)address); __COUTV__((void*)returnValue); __COUTV__(numberOfBytes); }
106  virtual void universalBlockWrite (char* address, char* writeValue, unsigned int numberOfBytes) { throw std::runtime_error("UNDEFINED BLOCK WRITE"); /* to make compiler happy, use params */ __COUTV__((void*)address); __COUTV__((void*)writeValue); __COUTV__(numberOfBytes); }
107 
108 
109  void runSequenceOfCommands (const std::string& treeLinkName);
110 
111  static void sendAsyncExceptionToGateway (FEVInterface* fe, const std::string& errMsg, bool isPauseException, bool isStopException);
112 
115  virtual void configure (void)
116  {
117  __COUT__ << "\t Configure" << std::endl;
119  "LinkToConfigureSequence"); /*Run Configure Sequence Commands*/
120  }
121  virtual void start (std::string /*runNumber*/)
122  {
123  __COUT__ << "\t Start" << std::endl;
124  runSequenceOfCommands("LinkToStartSequence"); /*Run Start Sequence Commands*/
125  }
126  virtual void stop (void)
127  {
128  __COUT__ << "\t Stop" << std::endl;
129  runSequenceOfCommands("LinkToStopSequence"); /*Run Stop Sequence Commands*/
130  }
131  virtual void halt (void) { stop(); }
132  virtual void pause (void) { stop(); }
133  virtual void resume (void) { start(""); }
134  virtual bool running (void) { /*while(WorkLoop::continueWorkLoop_){;}*/ return false; }
140  virtual void configureSlowControls (void);
141  void addSlowControlsChannels (ConfigurationTree slowControlsGroupLink, std::map<std::string /* ROC UID*/, FESlowControlsChannel>* mapOfSlowControlsChannels);
142 
143  virtual void resetSlowControlsChannelIterator (void);
145  virtual unsigned int getSlowControlsChannelCount (void);
146  bool slowControlsRunning (void);
147  void startSlowControlsWorkLoop (void) { slowControlsWorkLoop_.startWorkLoop(); }
148  void stopSlowControlsWorkLoop (void) { slowControlsWorkLoop_.stopWorkLoop(); }
149 
150  static const std::string UNKNOWN_TYPE;
151 
152  protected:
154  std::map<std::string, FESlowControlsChannel> mapOfSlowControlsChannels_;
155  std::map<std::string,
156  FESlowControlsChannel>::iterator slowControlsChannelsIterator_;
157  FESlowControlsWorkLoop slowControlsWorkLoop_;
158  std::atomic<bool> slowControlsWorkLoopShouldRun_{true};
164  public:
166  static const std::string DEFAULT; //for default arg values in FE macro definitions
167 
168  using frontEndMacroArg_t = std::pair<const std::string /* arg name */, std::string /* arg return value */>;
169  using frontEndMacroArgs_t = std::vector<frontEndMacroArg_t>&;
170  using frontEndMacroConstArgs_t = const std::vector<frontEndMacroArg_t>&;
171  struct frontEndMacroStruct_t;
172  using frontEndMacroFunction_t = void (ots::FEVInterface::*)(__ARGS__);
174  {
176  const std::string& feMacroName,
177  const frontEndMacroFunction_t& feMacroFunction,
178  const std::vector<std::string>& namesOfInputArgs,
179  const std::vector<std::string>& namesOfOutputArgs,
180  const std::string& requiredUserPermissions = "1" /*Level definition: 0:no-access,1:=user,255:=admin*/,
181  const std::string& allowedCallingFrontEnds = "*" /*StringMacros:: wild card set match string (i.e. string-to-set, then wild-card-set match)*/,
182  const std::string& feMacroTooltip = "")
183  : feMacroName_ (feMacroName)
184  , macroFunction_ (feMacroFunction)
185  , namesOfInputArguments_ (namesOfInputArgs)
186  , namesOfOutputArguments_ (namesOfOutputArgs)
187  , requiredUserPermissions_ (requiredUserPermissions)
188  , allowedCallingFrontEnds_ (allowedCallingFrontEnds)
189  , feMacroTooltip_ (feMacroTooltip)
190  {
191  }
192 
193  const std::string feMacroName_;
195  const std::vector<std::string> namesOfInputArguments_, namesOfOutputArguments_;
196  const std::string requiredUserPermissions_;
197  const std::string allowedCallingFrontEnds_;
198  const std::string feMacroTooltip_;
199  }; //end frontEndMacroStruct_t
200  const std::map<std::string, frontEndMacroStruct_t>& getMapOfFEMacroFunctions(void)
201  {
202  return mapOfFEMacroFunctions_;
203  }
204  void runSelfFrontEndMacro (
205  const std::string& feMacroName,
206  const std::vector<FEVInterface::frontEndMacroArg_t>& inputArgs,
207  std::vector<FEVInterface::frontEndMacroArg_t>& outputArgs);
214  {
215  macroStruct_t(const std::string& macroString);
216 
217  enum
218  {
219  OP_TYPE_READ,
220  OP_TYPE_WRITE,
221  OP_TYPE_DELAY,
222  };
223 
224  struct readOp_t
225  {
226  uint64_t address_;
227  bool addressIsVar_;
228  std::string addressVarName_;
229  bool dataIsVar_;
230  std::string dataVarName_;
231  }; // end macroStruct_t::writeOp_t declaration
232 
233  struct writeOp_t
234  {
235  uint64_t address_;
236  bool addressIsVar_;
237  std::string addressVarName_;
238  uint64_t data_;
239  bool dataIsVar_;
240  std::string dataVarName_;
241  }; // end macroStruct_t::writeOp_t declaration
242 
243  struct delayOp_t
244  {
245  uint64_t delay_;
246  bool delayIsVar_;
247  std::string delayVarName_;
248  }; // end macroStruct_t::writeOp_t declaration
249 
250  std::string macroName_;
251  std::vector<std::pair<unsigned int /*op type*/,
252  unsigned int /*index in specific type vector*/> >
253  operations_;
254  std::vector<macroStruct_t::readOp_t> readOps_;
255  std::vector<macroStruct_t::writeOp_t> writeOps_;
256  std::vector<macroStruct_t::delayOp_t> delayOps_;
257  std::set<std::string> namesOfInputArguments_, namesOfOutputArguments_;
258  bool lsbf_;
259  }; // end macroStruct_t declaration
260  protected:
262  std::map<std::string /*name*/, uint64_t /*value*/>& variableMap);
263 
264  public:
271  template<class T>
272  void sendToFrontEnd (const std::string& targetInterfaceID, const T& value) const;
273  void runFrontEndMacro (const std::string& targetInterfaceID,const std::string& feMacroName, const std::vector<FEVInterface::frontEndMacroArg_t>& inputArgs, std::vector<FEVInterface::frontEndMacroArg_t>& outputArgs) const;
274 
275  void PauseResumeSlowControls (__ARGS__);
276 
281  template<class T>
282  void receiveFromFrontEnd (const std::string& requester, T& retValue, unsigned int timeoutInSeconds = 1) const;
284  void receiveFromFrontEnd (const std::string& requester, std::string& retValue, unsigned int timeoutInSeconds = 1) const;
287  template<class T>
288  T receiveFromFrontEnd (const std::string& requester = "*", unsigned int timeoutInSeconds = 1) const;
290  std::string receiveFromFrontEnd (const std::string& requester = "*", unsigned int timeoutInSeconds = 1) const;
291 
295  protected:
296  bool workLoopThread (toolbox::task::WorkLoop* workLoop);
297 
298  std::string interfaceUID_, interfaceType_;
299  std::string mfSubject_;
300 
301  unsigned int universalAddressSize_ = 0;
302  unsigned int universalDataSize_ = 0;
303 
304 
307  std::map<std::string, frontEndMacroStruct_t> mapOfFEMacroFunctions_;
309  const std::string& feMacroName,
310  frontEndMacroFunction_t feMacroFunction,
311  const std::vector<std::string>& namesOfInputArgs,
312  const std::vector<std::string>& namesOfOutputArgs,
313  uint8_t requiredUserPermissions = 1 /*Level definition: 0:no-access,1:=user,255:=admin*/,
314  const std::string& allowedCallingFEs = "*" /*StringMacros:: wild card set match string (i.e. string-to-set, then wild-card-set match)*/,
315  const std::string& feMacroTooltip = "");
317  const std::string& feMacroName,
318  frontEndMacroFunction_t feMacroFunction,
319  const std::vector<std::string>& namesOfInputArgs,
320  const std::vector<std::string>& namesOfOutputArgs,
321  const std::string& requiredUserPermissions = WebUsers::DEFAULT_USER_GROUP + ":1" /*Level definition: 0:no-access,1:=user,255:=admin*/,
322  const std::string& allowedCallingFEs = "*" /*StringMacros:: wild card set match string (i.e. string-to-set, then wild-card-set match)*/,
323  const std::string& feMacroTooltip = "");
324 
325  public:
326  static const std::string& getFEMacroConstArgument (frontEndMacroConstArgs_t args, const std::string& argName);
327  static std::string& getFEMacroArgument (frontEndMacroArgs_t args, const std::string& argName);
328  protected:
329  template<class T>
330  std::string& setFEMacroArgumentValue (frontEndMacroArgs_t args, const std::string& argName, const T& value) const;
331  public:
332  template<class T>
333  static std::string& emplaceFEMacroArgumentValue (frontEndMacroArgs_t args, const std::string& argName, const T& value);
334 
335 
336 }; // end FEVInterface class
337 
338 template<class T>
339 T getFEMacroConstArgumentValue (FEVInterface::frontEndMacroConstArgs_t args, const std::string& argName, const T& defaultValue = T());
340 
342 template<>
343 std::string getFEMacroConstArgumentValue<std::string> (FEVInterface::frontEndMacroConstArgs_t args, const std::string& argName, const std::string& defaultValue);
344 
345 template<class T>
346 T getFEMacroArgumentValue (FEVInterface::frontEndMacroArgs_t args, const std::string& argName);
347 
349 template<>
350 std::string getFEMacroArgumentValue<std::string> (FEVInterface::frontEndMacroArgs_t argsIn, const std::string& argName);
351 
353 #include "otsdaq/FECore/FEVInterface.icc"
354 
355 // clang-format on
356 
357 } // namespace ots
358 
359 #endif
void runMacro(FEVInterface::macroStruct_t &macro, std::map< std::string, uint64_t > &variableMap)
runMacro
virtual void resetSlowControlsChannelIterator(void)
virtual in case channels are handled in multiple maps, for example
void(ots::FEVInterface::*)(const frontEndMacroStruct_t &feMacroStruct, FEVInterface::frontEndMacroConstArgs_t argsIn, FEVInterface::frontEndMacroArgs_t argsOut) frontEndMacroFunction_t
void function (vector-of-inputs, vector-of-outputs)
Definition: FEVInterface.h:172
virtual void configureSlowControls(void)
end State Machine handlers
static void sendAsyncExceptionToGateway(FEVInterface *fe, const std::string &errMsg, bool isPauseException, bool isStopException)
void runSequenceOfCommands(const std::string &treeLinkName)
virtual void configure(void)
Definition: FEVInterface.h:115
std::map< std::string, frontEndMacroStruct_t > mapOfFEMacroFunctions_
Map of FE Macro functions members.
Definition: FEVInterface.h:307
static const std::string & getFEMacroConstArgument(frontEndMacroConstArgs_t args, const std::string &argName)
< for specialized access to FE Macro in/out arguments
bool universalBlockReadImplementationConfirmed
is confirmed by slow controls handling (for example) that universalBlockRead is implemented by the FE...
Definition: FEVInterface.h:105
void addSlowControlsChannels(ConfigurationTree slowControlsGroupLink, std::map< std::string, FESlowControlsChannel > *mapOfSlowControlsChannels)
static const std::string DEFAULT
end Slow Controls
Definition: FEVInterface.h:166
std::string mfSubject_
for GEN_COUT decorations which would be safe in destructors, e.g. mirror interfaceUID_
Definition: FEVInterface.h:299
virtual FESlowControlsChannel * getNextSlowControlsChannel(void)
virtual in case channels are handled in multiple maps, for example
void runFrontEndMacro(const std::string &targetInterfaceID, const std::string &feMacroName, const std::vector< FEVInterface::frontEndMacroArg_t > &inputArgs, std::vector< FEVInterface::frontEndMacroArg_t > &outputArgs) const
virtual void universalRead(char *address, char *returnValue)=0
throw std::runtime_error exception on error/timeout
void runSelfFrontEndMacro(const std::string &feMacroName, const std::vector< FEVInterface::frontEndMacroArg_t > &inputArgs, std::vector< FEVInterface::frontEndMacroArg_t > &outputArgs)
T receiveFromFrontEnd(const std::string &requester="*", unsigned int timeoutInSeconds=1) const
static std::string & getFEMacroArgument(frontEndMacroArgs_t args, const std::string &argName)
virtual bool running(void)
Definition: FEVInterface.h:134
bool slowControlsRunning(void)
slow controls workloop calls this
virtual unsigned int getSlowControlsChannelCount(void)
virtual in case channels are handled in multiple maps, for example
void receiveFromFrontEnd(const std::string &requester, T &retValue, unsigned int timeoutInSeconds=1) const
bool workLoopThread(toolbox::task::WorkLoop *workLoop)
end FE Communication helpers //////
void sendToFrontEnd(const std::string &targetInterfaceID, const T &value) const
end FE Macros
void registerFEMacroFunction(const std::string &feMacroName, frontEndMacroFunction_t feMacroFunction, const std::vector< std::string > &namesOfInputArgs, const std::vector< std::string > &namesOfOutputArgs, uint8_t requiredUserPermissions=1, const std::string &allowedCallingFEs="*", const std::string &feMacroTooltip="")
std::map< std::string, FESlowControlsChannel > mapOfSlowControlsChannels_
Slow Controls members.
Definition: FEVInterface.h:154
defines used also by OtsConfigurationWizardSupervisor
< members fully define a front-end macro function
Definition: FEVInterface.h:174
const frontEndMacroFunction_t macroFunction_
Note: must be called using this instance.
Definition: FEVInterface.h:194
macroStruct_t(const std::string &macroString)
macroStruct_t constructor
bool lsbf_
least significant byte first
Definition: FEVInterface.h:258