1 #include "otsdaq/Macros/TablePluginMacros.h"
2 #include "otsdaq/TablePlugins/ARTDAQEventBuilderTable.h"
10 #define SLOWCONTROL_PV_FILE_PATH \
12 getenv("OTSDAQ_EPICS_DATA")? \
13 (std::string(getenv("OTSDAQ_EPICS_DATA")) + "/" + __ENV__("MU2E_OWNER") + "_otsdaq_artdaqEventBuilder-ai.dbg"): \
14 (EPICS_CONFIG_PATH + "/_otsdaq_artdaqEventBuilder-ai.dbg") )
19 ARTDAQEventBuilderTable::ARTDAQEventBuilderTable(
void)
27 __COUT__ <<
"ARTDAQEventBuilderTable Constructed." << __E__;
31 ARTDAQEventBuilderTable::~ARTDAQEventBuilderTable(
void) {}
36 lastConfigManager_ = configManager;
37 if(!ARTDAQTableBase::doGenFiles(configManager))
39 __COUTS__(3) <<
"ARTDAQTableBase indicates file generation can be skipped."
44 __COUTS__(3) <<
"*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << __E__;
45 __COUTS__(3) << configManager->__SELF_NODE__ << __E__;
51 void ARTDAQEventBuilderTable::genFlatFHiCL(
void)
57 std::map<std::string ,
62 std::string lastBuilderFcl[2],
65 for(
auto& builder : builders)
67 const std::string& builderUID = builder.first;
68 __COUTV__(builderUID);
70 std::string returnFcl, processName;
71 bool needToFlatten =
true;
72 bool captureAsLastFcl =
74 (&builder != &builders.back());
76 ARTDAQAppType::EventBuilder,
77 DEFAULT_MAX_FRAGMENT_SIZE,
78 DEFAULT_ROUTING_TIMEOUT_MS,
79 DEFAULT_ROUTING_RETRY_COUNT,
80 captureAsLastFcl ? &returnFcl :
nullptr);
88 returnFcl.find(
"# otsdaq-ARTDAQ builder UID:");
89 if(cmi != std::string::npos)
90 cmi = returnFcl.find(
'\n', cmi);
91 if(cmi != std::string::npos)
93 size_t pnj = std::string::npos;
94 auto pni = returnFcl.find(
"\tprocess_name: ", cmi);
95 if(pni != std::string::npos)
97 pni += std::string(
"\tprocess_name: ").size();
98 pnj = returnFcl.find(
'\n', pni);
100 if(pnj != std::string::npos)
102 processName = returnFcl.substr(pni, pnj - pni);
103 __COUT__ <<
"Found process name = " << processName << __E__;
105 bool sameFirst =
false;
107 std::string newPiece = returnFcl.substr(cmi, pni - cmi);
108 if(flattenedLastFclParts[0].size() && lastBuilderFcl[0].size() &&
109 lastBuilderFcl[0] == newPiece)
111 __COUT__ <<
"Same first fcl" << __E__;
116 __COUTVS__(20, lastBuilderFcl[0]);
117 __COUTVS__(20, newPiece);
118 for(
size_t i = 0, j = 0;
119 i < lastBuilderFcl[0].size() && j < newPiece.size();
122 if(lastBuilderFcl[0][i] != newPiece[j])
126 __COUTVS__(20, lastBuilderFcl[0].substr(i, 30));
127 __COUTVS__(20, newPiece.substr(j, 30));
133 lastBuilderFcl[0] = newPiece;
136 newPiece = returnFcl.substr(pnj);
137 if(lastBuilderFcl[0].size() && lastBuilderFcl[1] == newPiece)
139 __COUT__ <<
"Same second fcl" << __E__;
142 std::chrono::steady_clock::time_point startClock =
143 std::chrono::steady_clock::now();
144 __COUT__ <<
"Found fcl match! Reuse for " << builderUID << __E__;
147 needToFlatten =
false;
150 std::string outFile =
151 getFlatFHICLFilename(ARTDAQAppType::EventBuilder, builderUID);
152 __COUTVS__(3, outFile);
153 std::ofstream ofs{outFile};
156 __SS__ <<
"Failed to open fhicl output file '" << outFile
160 std::ostringstream out;
161 out << flattenedLastFclParts[0] <<
"process_name: \""
162 << processName <<
"\"" << flattenedLastFclParts[1];
165 fclMap_[ARTDAQAppType::EventBuilder][builder.first] = out.str();
167 __COUTT__ << builderUID <<
" Flatten Clock time = "
168 << artdaq::TimeUtils::GetElapsedTime(startClock)
174 lastBuilderFcl[1] = newPiece;
178 std::string& returnFclRef = returnFcl;
181 ARTDAQTableBase::flattenFHICL(
182 ARTDAQAppType::EventBuilder,
184 &(fclMap_[ARTDAQAppType::EventBuilder]
188 returnFclRef = fclMap_[ARTDAQAppType::EventBuilder][builder.first];
191 __COUT__ <<
"Skipping full flatten for " << builderUID << __E__;
194 __COUTV__(captureAsLastFcl);
197 size_t pnj = std::string::npos;
198 auto pni = returnFclRef.find(
"process_name:");
199 if(pni != std::string::npos)
203 (returnFclRef[pni - 1] ==
' ' || returnFclRef[pni - 1] ==
'\n' ||
204 returnFclRef[pni - 1] ==
'\t'))
205 pnj = returnFclRef.find(
'\n', pni);
207 if(pnj != std::string::npos)
210 <<
"Found flattened '"
211 << returnFclRef.substr(pni, pnj - pni) <<
"' at pos " << pni <<
" of "
212 << returnFclRef.size() << __E__;
213 flattenedLastFclParts[0] = returnFclRef.substr(0, pni);
214 flattenedLastFclParts[1] = returnFclRef.substr(pnj);
218 __COUT_WARN__ <<
"Failed to capture fcl for " << processName <<
"!"
223 __COUTS__(3) <<
"*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << __E__;
227 unsigned int ARTDAQEventBuilderTable::slowControlsHandlerConfig(
228 std::stringstream& out,
230 std::vector<std::pair<std::string , std::vector<std::string>>>*
237 std::string tabStr =
"";
238 std::string commentStr =
"";
241 std::vector<std::pair<std::string, ConfigurationTree>> artdaqRecords =
244 unsigned int numberOfEventBuiderMetricParameters = 0;
246 for(
auto& artdaqPair : artdaqRecords)
248 if(artdaqPair.second.getNode(colARTDAQSupervisor_.colLinkToEventBuilders_)
252 std::vector<std::pair<std::string, ConfigurationTree>> eventBuilderRecords =
253 artdaqPair.second.getNode(colARTDAQSupervisor_.colLinkToEventBuilders_)
256 for(
auto& eventBuilderPair :
259 if(!eventBuilderPair.second.status())
264 if(eventBuilderPair.second.getNode(
"daqLink").isDisconnected())
267 auto daqLink = eventBuilderPair.second.getNode(
"daqLink");
269 if(daqLink.getNode(
"daqMetricsLink").isDisconnected())
272 auto daqMetricsLinks = daqLink.getNode(
"daqMetricsLink").getChildren();
273 for(
auto& daqMetricsLink :
276 if(!daqMetricsLink.second.status())
279 if(daqMetricsLink.second.getNode(
"metricParametersLink")
285 eventBuilderPair.second.
getNode(
"MetricAlarmThresholdsLink");
287 auto metricParametersLinks =
288 daqMetricsLink.second.
getNode(
"metricParametersLink")
290 for(
auto& metricParametersLink :
291 metricParametersLinks)
293 if(!metricParametersLink.second.status())
296 std::string subsystem =
297 metricParametersLink.second.getNode(
"metricParameterValue")
298 .getValueWithDefault<std::string>(std::string(
"TDAQ_") +
299 __ENV__(
"MU2E_OWNER"));
300 if(subsystem.find(
"Mu2e:") != std::string::npos)
301 subsystem = subsystem.replace(subsystem.find(
"Mu2e:"), 5,
"");
302 while(subsystem.find(
"\"") != std::string::npos)
303 subsystem = subsystem.replace(subsystem.find(
"\""), 1,
"");
305 numberOfEventBuiderMetricParameters =
306 slowControlsHandler(out,
310 eventBuilderPair.first,
314 __COUT__ <<
"EventBuilder '" << eventBuilderPair.first
315 <<
"' number of metrics for slow controls: "
316 << numberOfEventBuiderMetricParameters << __E__;
320 catch(
const std::runtime_error& e)
322 __COUT_ERR__ <<
"Ignoring EventBuilder error: " << e.what() << __E__;
327 return numberOfEventBuiderMetricParameters;
334 return SLOWCONTROL_PV_FILE_PATH;
void init(ConfigurationManager *configManager) override
Methods.
virtual std::string setFilePath(void) const override
return out file path
<virtual so future plugins can inherit from multiple table base classes
static void outputDataReceiverFHICL(const ConfigurationTree &receiverNode, ARTDAQAppType appType, size_t maxFragmentSizeBytes=DEFAULT_MAX_FRAGMENT_SIZE, size_t routingTimeoutMs=DEFAULT_ROUTING_TIMEOUT_MS, size_t routingRetryCount=DEFAULT_ROUTING_RETRY_COUNT, std::string *returnFcl=nullptr)
ConfigurationTree getNode(const std::string &nodeString, bool doNotThrowOnBrokenUIDLinks=false) const
"root/parent/parent/"
ConfigurationTree getNode(const std::string &nodeName, bool doNotThrowOnBrokenUIDLinks=false) const
navigating between nodes
std::vector< std::pair< std::string, ConfigurationTree > > getChildren(std::map< std::string, std::string > filterMap=std::map< std::string, std::string >(), bool byPriority=false, bool onlyStatusTrue=false) const
<virtual so future plugins can inherit from multiple table base classes
const std::string & getTableName(void) const
Getters.
defines used also by OtsConfigurationWizardSupervisor