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;
49 __COUT_INFO__ <<
"ARTDAQ Supervisor is disabled, so skipping fcl handling."
55 mkdir((ARTDAQTableBase::ARTDAQ_FCL_PATH).c_str(), 0755);
57 __COUTS__(3) <<
"*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << __E__;
58 __COUTS__(3) << configManager->__SELF_NODE__ << __E__;
64 std::map<std::string ,
69 std::string lastBuilderFcl[2],
72 for(
auto& builder : builders)
74 const std::string& builderUID = builder.first;
75 __COUTV__(builderUID);
77 std::string returnFcl, processName;
78 bool needToFlatten =
true;
79 bool captureAsLastFcl =
81 (&builder != &builders.back());
83 ARTDAQAppType::EventBuilder,
84 DEFAULT_MAX_FRAGMENT_SIZE,
85 DEFAULT_ROUTING_TIMEOUT_MS,
86 DEFAULT_ROUTING_RETRY_COUNT,
87 captureAsLastFcl ? &returnFcl :
nullptr);
95 returnFcl.find(
"# otsdaq-ARTDAQ builder UID:");
96 if(cmi != std::string::npos)
97 cmi = returnFcl.find(
'\n', cmi);
98 if(cmi != std::string::npos)
100 size_t pnj = std::string::npos;
101 auto pni = returnFcl.find(
"\tprocess_name: ", cmi);
102 if(pni != std::string::npos)
104 pni += std::string(
"\tprocess_name: ").size();
105 pnj = returnFcl.find(
'\n', pni);
107 if(pnj != std::string::npos)
109 processName = returnFcl.substr(pni, pnj - pni);
110 __COUT__ <<
"Found process name = " << processName << __E__;
112 bool sameFirst =
false;
114 std::string newPiece = returnFcl.substr(cmi, pni - cmi);
115 if(flattenedLastFclParts[0].size() && lastBuilderFcl[0].size() &&
116 lastBuilderFcl[0] == newPiece)
118 __COUT__ <<
"Same first fcl" << __E__;
123 __COUTVS__(20, lastBuilderFcl[0]);
124 __COUTVS__(20, newPiece);
125 for(
size_t i = 0, j = 0;
126 i < lastBuilderFcl[0].size() && j < newPiece.size();
129 if(lastBuilderFcl[0][i] != newPiece[j])
133 __COUTVS__(20, lastBuilderFcl[0].substr(i, 30));
134 __COUTVS__(20, newPiece.substr(j, 30));
140 lastBuilderFcl[0] = newPiece;
143 newPiece = returnFcl.substr(pnj);
144 if(lastBuilderFcl[0].size() && lastBuilderFcl[1] == newPiece)
146 __COUT__ <<
"Same second fcl" << __E__;
149 std::chrono::steady_clock::time_point startClock =
150 std::chrono::steady_clock::now();
151 __COUT__ <<
"Found fcl match! Reuse for " << builderUID << __E__;
154 needToFlatten =
false;
157 std::string outFile =
158 getFlatFHICLFilename(ARTDAQAppType::EventBuilder, builderUID);
159 __COUTVS__(3, outFile);
160 std::ofstream ofs{outFile};
163 __SS__ <<
"Failed to open fhicl output file '" << outFile
167 ofs << flattenedLastFclParts[0] <<
"process_name: \""
168 << processName <<
"\"" << flattenedLastFclParts[1];
169 __COUTT__ << builderUID <<
" Flatten Clock time = "
170 << artdaq::TimeUtils::GetElapsedTime(startClock)
176 lastBuilderFcl[1] = newPiece;
181 ARTDAQTableBase::flattenFHICL(ARTDAQAppType::EventBuilder,
183 captureAsLastFcl ? &returnFcl :
nullptr);
185 __COUT__ <<
"Skipping full flatten for " << builderUID << __E__;
188 __COUTV__(captureAsLastFcl);
191 size_t pnj = std::string::npos;
192 auto pni = returnFcl.find(
"process_name:");
193 if(pni != std::string::npos)
196 if(pni && (returnFcl[pni - 1] ==
' ' || returnFcl[pni - 1] ==
'\n' ||
197 returnFcl[pni - 1] ==
'\t'))
198 pnj = returnFcl.find(
'\n', pni);
200 if(pnj != std::string::npos)
203 <<
"Found flattened '"
204 << returnFcl.substr(pni, pnj - pni) <<
"' at pos " << pni <<
" of "
205 << returnFcl.size() << __E__;
206 flattenedLastFclParts[0] = returnFcl.substr(0, pni);
207 flattenedLastFclParts[1] = returnFcl.substr(pnj);
211 __COUT_WARN__ <<
"Failed to capture fcl for " << processName <<
"!"
216 __COUTS__(3) <<
"*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << __E__;
220 unsigned int ARTDAQEventBuilderTable::slowControlsHandlerConfig(
221 std::stringstream& out,
223 std::vector<std::pair<std::string , std::vector<std::string>>>*
230 std::string tabStr =
"";
231 std::string commentStr =
"";
234 std::vector<std::pair<std::string, ConfigurationTree>> artdaqRecords =
237 unsigned int numberOfEventBuiderMetricParameters = 0;
239 for(
auto& artdaqPair : artdaqRecords)
241 if(artdaqPair.second.getNode(colARTDAQSupervisor_.colLinkToEventBuilders_)
245 std::vector<std::pair<std::string, ConfigurationTree>> eventBuilderRecords =
246 artdaqPair.second.getNode(colARTDAQSupervisor_.colLinkToEventBuilders_)
249 for(
auto& eventBuilderPair :
252 if(!eventBuilderPair.second.status())
257 if(eventBuilderPair.second.getNode(
"daqLink").isDisconnected())
260 auto daqLink = eventBuilderPair.second.getNode(
"daqLink");
262 if(daqLink.getNode(
"daqMetricsLink").isDisconnected())
265 auto daqMetricsLinks = daqLink.getNode(
"daqMetricsLink").getChildren();
266 for(
auto& daqMetricsLink :
269 if(!daqMetricsLink.second.status())
272 if(daqMetricsLink.second.getNode(
"metricParametersLink")
278 eventBuilderPair.second.
getNode(
"MetricAlarmThresholdsLink");
280 auto metricParametersLinks =
281 daqMetricsLink.second.
getNode(
"metricParametersLink")
283 for(
auto& metricParametersLink :
284 metricParametersLinks)
286 if(!metricParametersLink.second.status())
289 std::string subsystem =
290 metricParametersLink.second.getNode(
"metricParameterValue")
291 .getValueWithDefault<std::string>(std::string(
"TDAQ_") +
292 __ENV__(
"MU2E_OWNER"));
293 if(subsystem.find(
"Mu2e:") != std::string::npos)
294 subsystem = subsystem.replace(subsystem.find(
"Mu2e:"), 5,
"");
295 while(subsystem.find(
"\"") != std::string::npos)
296 subsystem = subsystem.replace(subsystem.find(
"\""), 1,
"");
298 numberOfEventBuiderMetricParameters =
299 slowControlsHandler(out,
303 eventBuilderPair.first,
307 __COUT__ <<
"EventBuilder '" << eventBuilderPair.first
308 <<
"' number of metrics for slow controls: "
309 << numberOfEventBuiderMetricParameters << __E__;
313 catch(
const std::runtime_error& e)
315 __COUT_ERR__ <<
"Ignoring EventBuilder error: " << e.what() << __E__;
320 return numberOfEventBuiderMetricParameters;
327 return SLOWCONTROL_PV_FILE_PATH;
virtual std::string setFilePath() const override
return out file path
void init(ConfigurationManager *configManager) override
Methods.
<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)
static bool isARTDAQEnabled(const ConfigurationManager *cfgMgr)
isARTDAQEnabled
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
bool isFirstAppInContext_
for managing if PV list has changed
const std::string & getTableName(void) const
Getters.