otsdaq  v2_05_02_indev
ARTDAQTableBase.h
1 #ifndef _ots_ARTDAQTableBase_h_
2 #define _ots_ARTDAQTableBase_h_
3 
4 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
5 #include "otsdaq/ConfigurationInterface/ConfigurationManagerRW.h"
6 #include "otsdaq/TableCore/TableBase.h"
7 
8 // helpers
9 #define OUT out << tabStr << commentStr
10 #define PUSHTAB tabStr += "\t"
11 #define POPTAB tabStr.resize(tabStr.size() - 1)
12 #define PUSHCOMMENT commentStr += "# "
13 #define POPCOMMENT commentStr.resize(commentStr.size() - 2)
14 
15 namespace ots
16 {
17 // clang-format off
18 class ARTDAQTableBase : virtual public TableBase //virtual so future plugins can inherit from multiple table base classes
19 {
20  public:
22  ARTDAQTableBase(std::string tableName, std::string* accumulatedExceptions = 0);
23 
24  virtual ~ARTDAQTableBase(void);
25 
26  static const std::string ARTDAQ_FCL_PATH;
27  static const std::string ARTDAQ_SUPERVISOR_CLASS, ARTDAQ_SUPERVISOR_TABLE;
28  static const std::string ARTDAQ_READER_TABLE, ARTDAQ_BUILDER_TABLE, ARTDAQ_LOGGER_TABLE, ARTDAQ_DISPATCHER_TABLE, ARTDAQ_MONITOR_TABLE, ARTDAQ_ROUTER_TABLE;
29  static const std::string ARTDAQ_SUBSYSTEM_TABLE;
30  static const std::string ARTDAQ_TYPE_TABLE_HOSTNAME, ARTDAQ_TYPE_TABLE_SUBSYSTEM_LINK, ARTDAQ_TYPE_TABLE_SUBSYSTEM_LINK_UID;
31 
32  enum class ARTDAQAppType
33  {
34  BoardReader,
35  EventBuilder,
36  DataLogger,
37  Dispatcher,
38  Monitor,
39  RoutingMaster
40  };
41 
42  enum
43  {
44  DEFAULT_MAX_FRAGMENT_SIZE = 1048576,
45  DEFAULT_ROUTING_TIMEOUT_MS = 1000,
46  DEFAULT_ROUTING_RETRY_COUNT = 5,
47  };
48 
49  static const int NULL_SUBSYSTEM_DESTINATION;
50  static const std::string NULL_SUBSYSTEM_DESTINATION_LABEL;
51 
52  struct ProcessInfo
53  {
54  std::string label;
55  std::string hostname;
56  int subsystem;
57  bool status;
58 
59  ProcessInfo(std::string l, std::string h, int s, ARTDAQAppType /*t*/, bool onOff)
60  : label(l), hostname(h), subsystem(s), status(onOff) {}
61  };
62 
64  {
65  int id;
66  std::string label;
67 
68  std::set<int> sources; // by subsystem id
69  int destination; // destination subsystem id, 0 := no destination
70 
71  bool hasRoutingMaster;
72  std::string routingMasterHost;
73 
74  SubsystemInfo() : sources(), destination(0), hasRoutingMaster(false), routingMasterHost("") {}
75  };
76 
77  struct ARTDAQInfo
78  {
79  std::map<int /*subsystem ID*/, ARTDAQTableBase::SubsystemInfo> subsystems;
80  std::map<ARTDAQAppType, std::list<ProcessInfo>> processes;
81  };
82 
83  static const std::string& getTypeString (ARTDAQAppType type);
84  static std::string getFHICLFilename (ARTDAQAppType type, const std::string& name);
85  static std::string getFlatFHICLFilename (ARTDAQAppType type, const std::string& name);
86  static void flattenFHICL (ARTDAQAppType type, const std::string& name);
87 
88  static void insertParameters (std::ostream& out,
89  std::string& tabStr,
90  std::string& commentStr,
91  ConfigurationTree parameterLink,
92  const std::string& parameterPreamble,
93  bool onlyInsertAtTableParameters = false,
94  bool includeAtTableParameters = false);
95  static std::string insertModuleType (std::ostream& out, std::string& tabStr, std::string& commentStr, ConfigurationTree moduleTypeNode);
96  static void insertMetricsBlock (std::ostream& out, std::string& tabStr, std::string& commentStr, ConfigurationTree daqNode);
97 
98  static void outputBoardReaderFHICL (const ConfigurationTree& boardReaderNode,
99  size_t maxFragmentSizeBytes = DEFAULT_MAX_FRAGMENT_SIZE,
100  size_t routingTimeoutMs = DEFAULT_ROUTING_TIMEOUT_MS,
101  size_t routingRetryCount = DEFAULT_ROUTING_RETRY_COUNT);
102 
103  static void outputDataReceiverFHICL (const ConfigurationTree& receiverNode,
104  ARTDAQAppType appType,
105  size_t maxFragmentSizeBytes = DEFAULT_MAX_FRAGMENT_SIZE,
106  size_t routingTimeoutMs = DEFAULT_ROUTING_TIMEOUT_MS,
107  size_t routingRetryCount = DEFAULT_ROUTING_RETRY_COUNT);
108 
109  static void outputRoutingMasterFHICL (const ConfigurationTree& routingMasterNode,
110  size_t routingTimeoutMs = DEFAULT_ROUTING_TIMEOUT_MS,
111  size_t routingRetryCount = DEFAULT_ROUTING_RETRY_COUNT);
112 
113  static const ARTDAQInfo& extractARTDAQInfo (ConfigurationTree artdaqSupervisorNode,
114  bool getStatusFalseNodes = false,
115  bool doWriteFHiCL = false,
116  size_t maxFragmentSizeBytes = DEFAULT_MAX_FRAGMENT_SIZE,
117  size_t routingTimeoutMs = DEFAULT_ROUTING_TIMEOUT_MS,
118  size_t routingRetryCount = DEFAULT_ROUTING_RETRY_COUNT,
119  ProgressBar* progressBar = 0);
120 
121  static const ARTDAQInfo& getARTDAQSystem (ConfigurationManagerRW* cfgMgr,
122  std::map<std::string /*type*/,
123  std::map<std::string /*record*/,
124  std::vector<std::string /*property*/>>>& nodeTypeToObjectMap,
125  std::map<std::string /*subsystemName*/,
126  std::string /*destinationSubsystemName*/>& subsystemObjectMap,
127  std::vector<std::string /*property*/>& artdaqSupervisoInfo);
128 
130  const std::map<std::string /*type*/,
131  std::map<std::string /*record*/,
132  std::vector<std::string /*property*/>>>& nodeTypeToObjectMap,
133  const std::map<std::string /*subsystemName*/,
134  std::string /*destinationSubsystemName*/>& subsystemObjectMap);
135 
136  private:
137  static int getSubsytemId (ConfigurationTree subsystemNode);
138  static void extractRoutingMastersInfo (ConfigurationTree artdaqSupervisorNode, bool getStatusFalseNodes, bool doWriteFHiCL, size_t routingTimeoutMs, size_t routingRetryCount);
139  static void extractBoardReadersInfo (ConfigurationTree artdaqSupervisorNode, bool getStatusFalseNodes, bool doWriteFHiCL, size_t maxFragmentSizeBytes, size_t routingTimeoutMs, size_t routingRetryCount);
140  static void extractEventBuildersInfo (ConfigurationTree artdaqSupervisorNode, bool getStatusFalseNodes, bool doWriteFHiCL, size_t maxFragmentSizeBytes);
141  static void extractDataLoggersInfo (ConfigurationTree artdaqSupervisorNode, bool getStatusFalseNodes, bool doWriteFHiCL, size_t maxFragmentSizeBytes);
142  static void extractDispatchersInfo (ConfigurationTree artdaqSupervisorNode, bool getStatusFalseNodes, bool doWriteFHiCL, size_t maxFragmentSizeBytes);
143 
144  static ARTDAQInfo info_;
145 
146  public:
147  static struct ProcessTypes
148  {
149  std::string const READER = "reader";
150  std::string const BUILDER = "builder";
151  std::string const LOGGER = "logger";
152  std::string const DISPATCHER = "dispatcher";
153  std::string const MONITOR = "monitor";
154  std::string const ROUTER = "router";
155 
156  ProcessTypes()
157  : mapToType_({
158  std::make_pair(READER, ARTDAQTableBase::ARTDAQAppType::BoardReader),
159  std::make_pair(BUILDER, ARTDAQTableBase::ARTDAQAppType::EventBuilder),
160  std::make_pair(LOGGER, ARTDAQTableBase::ARTDAQAppType::DataLogger),
161  std::make_pair(DISPATCHER, ARTDAQTableBase::ARTDAQAppType::Dispatcher),
162  std::make_pair(MONITOR, ARTDAQTableBase::ARTDAQAppType::Monitor),
163  std::make_pair(ROUTER, ARTDAQTableBase::ARTDAQAppType::RoutingMaster)})
164  , mapToTable_({
165  std::make_pair(READER, ARTDAQTableBase::ARTDAQ_READER_TABLE),
166  std::make_pair(BUILDER, ARTDAQTableBase::ARTDAQ_BUILDER_TABLE),
167  std::make_pair(LOGGER, ARTDAQTableBase::ARTDAQ_LOGGER_TABLE),
168  std::make_pair(DISPATCHER, ARTDAQTableBase::ARTDAQ_DISPATCHER_TABLE),
169  std::make_pair(MONITOR, ARTDAQTableBase::ARTDAQ_MONITOR_TABLE),
170  std::make_pair(ROUTER, ARTDAQTableBase::ARTDAQ_ROUTER_TABLE)})
171  , mapToGroupIDAppend_({
172  std::make_pair(READER, "BoardReaders"),
173  std::make_pair(BUILDER, "EventBuilders"),
174  std::make_pair(LOGGER, "DataLoggers"),
175  std::make_pair(DISPATCHER, "Dispatchers"),
176  std::make_pair(MONITOR, "Monitors"),
177  std::make_pair(ROUTER, "RoutingMasters")})
178  , mapToLinkGroupIDColumn_({
179  std::make_pair(READER, ARTDAQTableBase::colARTDAQSupervisor_.colLinkToBoardReadersGroupID_),
180  std::make_pair(BUILDER, ARTDAQTableBase::colARTDAQSupervisor_.colLinkToEventBuildersGroupID_),
181  std::make_pair(LOGGER, ARTDAQTableBase::colARTDAQSupervisor_.colLinkToDataLoggersGroupID_),
182  std::make_pair(DISPATCHER, ARTDAQTableBase::colARTDAQSupervisor_.colLinkToDispatchersGroupID_),
183  std::make_pair(ROUTER, ARTDAQTableBase::colARTDAQSupervisor_.colLinkToRoutingMastersGroupID_)})
184  , mapToGroupIDColumn_({
185  std::make_pair(READER, "BoardReaderGroupID"),
186  std::make_pair(BUILDER, "EventBuilderGroupID"),
187  std::make_pair(LOGGER, "DataLoggerGroupID"),
188  std::make_pair(DISPATCHER, "DispatcherGroupID"),
189  std::make_pair(MONITOR, "MonitorGroupID"),
190  std::make_pair(ROUTER, "RoutingMasterGroupID")})
191  {}
192 
193  const std::map<std::string /*processType*/, ARTDAQTableBase::ARTDAQAppType> mapToType_;
194  const std::map<std::string /*processType*/, std::string /*typeTable*/> mapToTable_, mapToGroupIDAppend_, mapToLinkGroupIDColumn_, mapToGroupIDColumn_;
195  } processTypes_;
196 
197  // ARTDAQ Supervisor Column names
198  static struct ColARTDAQSupervisor
199  {
200  std::string const colDAQInterfaceDebugLevel_ = "DAQInterfaceDebugLevel";
201  std::string const colDAQSetupScript_ = "DAQSetupScript";
202 
203  std::string const colLinkToBoardReaders_ = "BoardReadersLink";
204  std::string const colLinkToBoardReadersGroupID_ = "BoardReadersLinkGroupID";
205  std::string const colLinkToEventBuilders_ = "EventBuildersLink";
206  std::string const colLinkToEventBuildersGroupID_ = "EventBuildersLinkGroupID";
207  std::string const colLinkToDataLoggers_ = "DataLoggersLink";
208  std::string const colLinkToDataLoggersGroupID_ = "DataLoggersLinkGroupID";
209  std::string const colLinkToDispatchers_ = "DispatchersLink";
210  std::string const colLinkToDispatchersGroupID_ = "DispatchersLinkGroupID";
211  std::string const colLinkToRoutingMasters_ = "RoutingMastersLink";
212  std::string const colLinkToRoutingMastersGroupID_ = "RoutingMastersLinkGroupID";
213  } colARTDAQSupervisor_;
214 
215  // ARTDAQ Supervisor Column names
216  static struct ColARTDAQSubsystem
217  {
218  std::string const colLinkToDestination_ = "SubsystemDestinationLink";
219  std::string const colLinkToDestinationUID_ = "SubsystemDestinationUID";
220  } colARTDAQSubsystem_;
221 };
222 // clang-format on
223 } // namespace ots
224 
225 #endif
static void setAndActivateARTDAQSystem(ConfigurationManagerRW *cfgMgr, const std::map< std::string, std::map< std::string, std::vector< std::string >>> &nodeTypeToObjectMap, const std::map< std::string, std::string > &subsystemObjectMap)