otsdaq  v1_01_04
 All Classes Namespaces Functions
FEVInterface.h
1 #ifndef _ots_FEVInterface_h_
2 #define _ots_FEVInterface_h_
3 
4 #include "otsdaq-core/FiniteStateMachine/VStateMachine.h"
5 #include "otsdaq-core/WorkLoopManager/WorkLoop.h"
6 #include "otsdaq-core/ConfigurationInterface/Configurable.h"
7 #include "otsdaq-core/FECore/FESlowControlsWorkLoop.h"
8 
9 
10 //#include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
11 #include "otsdaq-core/FECore/FESlowControlsChannel.h"
12 
13 #include <string>
14 #include <iostream>
15 #include <vector>
16 #include <array>
17 
18 namespace ots
19 {
20 class FrontEndHardwareBase;
21 class FrontEndFirmwareBase;
22 class FEInterfaceConfigurationBase;
23 //class SlowControlsChannelInfo;
24 
25 class FEVInterface : public VStateMachine, public WorkLoop, public Configurable
26 {
27 public:
28 
29  FEVInterface (const std::string& interfaceUID, const ConfigurationTree& theXDAQContextConfigTree, const std::string& configurationPath)
30 : WorkLoop (interfaceUID)
31 , Configurable (theXDAQContextConfigTree, configurationPath)
32 , interfaceUID_ (interfaceUID)
33 , interfaceType_ (theXDAQContextConfigTree_.getBackNode(theConfigurationPath_).getNode("FEInterfacePluginName").getValue<std::string>())
34 , daqHardwareType_ ("NOT SET")
35 , firmwareType_ ("NOT SET")
36 , slowControlsWorkLoop_ (interfaceUID + "-SlowControls", this)
37 {}
38 
39  virtual ~FEVInterface (void) {;}
40 
41  virtual void initLocalGroup(int local_group_comm_){std::cout << __PRETTY_FUNCTION__ << std::endl;}
42 
43 // void setConfigurationManager(ConfigurationManager* configurationManager){theConfigurationManager_ = configurationManager;}
44  //virtual void configureFEW (void) = 0;
45 
46  void configureSlowControls(void);
47  //virtual void configureDetector(const DACStream& theDACStream) = 0;
48  //virtual void resetDetector() = 0;
49 
50  const std::string& getInterfaceUID (void) const {return interfaceUID_;}
51  const std::string& getDaqHardwareType (void) const {return daqHardwareType_;}
52  const std::string& getFirmwareType (void) const {return firmwareType_;}
53  const std::string& getInterfaceType (void) const {return interfaceType_;}
54 
55  virtual int universalRead (char* address, char* returnValue) = 0;
56  virtual void universalWrite (char* address, char* writeValue) = 0;
57  const unsigned int& getUniversalAddressSize(void) {return universalAddressSize_;}
58  const unsigned int& getUniversalDataSize (void) {return universalDataSize_;}
59 
60  // virtual int interfaceWrite(uint64_t address, const std::string& value){return 0;}
61  // virtual int interfaceRead (uint64_t address, std::string& value){return 0;}
62 
63  FrontEndHardwareBase* getHardwareP(void) const {return theFrontEndHardware_;}
64  FrontEndFirmwareBase* getFirmwareP(void) const {return theFrontEndFirmware_;}
65 
66  bool slowControlsRunning(void);
67  void startSlowControlsWorkLooop(void) {slowControlsWorkLoop_.startWorkLoop();}
68  void stopSlowControlsWorkLooop(void) {slowControlsWorkLoop_.stopWorkLoop();}
69 
70  //public types and functions for map of FE macros
71  using frontEndMacroInArg_t = std::pair<const std::string /* input arg name */ , const std::string /* arg input value */ >;
72  using frontEndMacroInArgs_t = const std::vector<frontEndMacroInArg_t> &;
73  using frontEndMacroOutArg_t = std::pair<const std::string /* output arg name */, std::string /* arg return value */>;
74  using frontEndMacroOutArgs_t = std::vector<frontEndMacroOutArg_t> &;
75  using frontEndMacroFunction_t = void (ots::FEVInterface::* )(frontEndMacroInArgs_t, frontEndMacroOutArgs_t); //void function (vector-of-inputs, vector-of-outputs)
76  struct frontEndMacroStruct_t //members fully define a front-end macro function
77  {
78  frontEndMacroStruct_t(const frontEndMacroFunction_t &feMacroFunction,
79  const std::vector<std::string> &namesOfInputArgs,
80  const std::vector<std::string> &namesOfOutputArgs,
81  const uint8_t requiredUserPermissions)
82  :macroFunction_(feMacroFunction)
83  ,namesOfInputArguments_(namesOfInputArgs)
84  ,namesOfOutputArguments_(namesOfOutputArgs)
85  ,requiredUserPermissions_(requiredUserPermissions)
86  {}
87 
88  const frontEndMacroFunction_t macroFunction_; //Note: must be called using this instance
89  const std::vector<std::string> namesOfInputArguments_, namesOfOutputArguments_;
90  const uint8_t requiredUserPermissions_;
91  };
92  const std::map<std::string, frontEndMacroStruct_t>& getMapOfFEMacroFunctions() {return mapOfFEMacroFunctions_;}
93 
94 protected:
95  bool workLoopThread(toolbox::task::WorkLoop* workLoop){continueWorkLoop_ = running(); /* in case users return false, without using continueWorkLoop_*/ return continueWorkLoop_;}
96  std::string interfaceUID_;
97  std::string interfaceType_;
98 
99 
100  std::string daqHardwareType_;
101  std::string firmwareType_;
102 
103  FrontEndHardwareBase* theFrontEndHardware_ = nullptr;
104  FrontEndFirmwareBase* theFrontEndFirmware_ = nullptr;
105 
106  unsigned int universalAddressSize_ = 0;
107  unsigned int universalDataSize_ = 0;
108 
109  //Controls members
110  std::map<std::string, FESlowControlsChannel> mapOfSlowControlsChannels_;
111  FESlowControlsWorkLoop slowControlsWorkLoop_;
112 
113 
114  //FE Macro Function members and helper functions:
115 
116  std::map<std::string, frontEndMacroStruct_t> mapOfFEMacroFunctions_; //Map of FE Macro functions members
117  std::array<std::string, 3> testarr_;
118  //void registerFEMacroFunction(const std::string &feMacroName, frontEndMacroFunction_t feMacroFunction, unsigned int numOfInputArgs, unsigned int numOfOutputArgs, uint8_t requiredUserPermissions);
119  void registerFEMacroFunction(const std::string &feMacroName, frontEndMacroFunction_t feMacroFunction, const std::vector<std::string> &namesOfInputArgs, const std::vector<std::string> &namesOfOutputArgs,uint8_t requiredUserPermissions);
120  const std::string& getFEMacroInputArgument(frontEndMacroInArgs_t &argsIn, const std::string &argName);
121  std::string& getFEMacroOutputArgument(frontEndMacroOutArgs_t &argsOut, const std::string& argName);
122 };
123 
124 }
125 
126 #endif