1 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
2 #include "otsdaq/Macros/TablePluginMacros.h"
3 #include "otsdaq/TablePlugins/ARTDAQBoardReaderTable.h"
4 #include "otsdaq/TablePlugins/XDAQContextTable.h"
13 #define ARTDAQ_FCL_PATH std::string(__ENV__("USER_DATA")) + "/" + "ARTDAQConfigurations/"
14 #define ARTDAQ_FILE_PREAMBLE "boardReader"
17 #define OUT out << tabStr << commentStr
18 #define PUSHTAB tabStr += "\t"
19 #define POPTAB tabStr.resize(tabStr.size() - 1)
20 #define PUSHCOMMENT commentStr += "# "
21 #define POPCOMMENT commentStr.resize(commentStr.size() - 2)
24 ARTDAQBoardReaderTable::ARTDAQBoardReaderTable(
void)
33 ARTDAQBoardReaderTable::~ARTDAQBoardReaderTable(
void) {}
40 bool isFirstAppInContext = configManager->isOwnerFirstAppInContext();
43 if(!isFirstAppInContext)
47 mkdir((ARTDAQ_FCL_PATH).c_str(), 0755);
49 __COUT__ <<
"*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << __E__;
50 __COUT__ << configManager->__SELF_NODE__ << __E__;
55 std::vector<const XDAQContextTable::XDAQContext*> readerContexts =
56 contextConfig->getBoardReaderContexts();
61 for(
auto& readerContext : readerContexts)
67 readerContext->contextUID_,
68 readerContext->applications_[0].applicationUID_);
70 __COUT__ <<
"Path for this reader config is " << readerContext->contextUID_
71 <<
"/" << readerContext->applications_[0].applicationUID_ <<
"/"
72 << readerConfigNode.getValueAsString() << __E__;
74 __COUT__ <<
"Checking that this reader supervisor node is DataManager-like."
77 readerConfigNode.getNode(
"LinkToDataBufferTable").getChildren();
79 catch(
const std::runtime_error& e)
81 __SS__ <<
"artdaq Board Readers must be instantiated as a Consumer within a "
83 <<
"Error found while checking for LinkToDataBufferTable: " << e.what()
85 __COUT_ERR__ << ss.str();
86 __COUT__ <<
"Path for this reader config is " << readerContext->contextUID_
87 <<
"/" << readerContext->applications_[0].applicationUID_ <<
"/X"
89 __COUT_ERR__ <<
"This board reader will likely not get instantiated "
90 "properly! Proceeding anyway with fcl generation."
106 auto childrenMap = configManager->__SELF_NODE__.getChildren();
107 std::string appUID, buffUID, consumerUID;
108 for(
auto& child : childrenMap)
111 for(
auto& readerContext : readerContexts)
115 readerContext->contextUID_,
116 readerContext->applications_[0].applicationUID_);
117 auto dataManagerConfMap =
118 readerConfigNode.getNode(
"LinkToDataBufferTable").getChildren();
119 for(
auto dmc : dataManagerConfMap)
121 auto dataBufferConfMap =
122 dmc.second.getNode(
"LinkToDataProcessorTable").getChildren();
123 for(
auto dbc : dataBufferConfMap)
125 auto processorConfUID =
126 dbc.second.getNode(
"LinkToProcessorUID").getUIDAsString();
127 if(processorConfUID == child.second.getValue())
129 __COUT__ <<
"Found match for context UID: "
130 << readerContext->contextUID_ << __E__;
131 thisContext = readerContext;
137 if(thisContext ==
nullptr)
139 __COUT_ERR__ <<
"Could not find matching context for this table!" << __E__;
143 if(child.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
151 contextConfig->getContextAddress(thisContext->contextUID_),
193 unsigned int selfRank,
194 const std::string& selfHost,
195 unsigned int selfPort,
197 size_t maxFragmentSizeBytes)
324 std::string filename = ARTDAQTableBase::getFHICLFilename(ARTDAQ_FILE_PREAMBLE,
325 boardReaderNode.getValue());
331 std::string tabStr =
"";
332 std::string commentStr =
"";
334 out.open(filename, std::fstream::out | std::fstream::trunc);
337 __SS__ <<
"Failed to open ARTDAQ Builder fcl file: " << filename << __E__;
343 OUT <<
"###########################################################" << __E__;
345 OUT <<
"# artdaq reader fcl configuration file produced by otsdaq." << __E__;
346 OUT <<
"# Creation timestamp: " << StringMacros::getTimestampString() << __E__;
347 OUT <<
"# Original filename: " << filename << __E__;
348 OUT <<
"# otsdaq-ARTDAQ Reader UID: " << boardReaderNode.getValue() << __E__;
350 OUT <<
"###########################################################" << __E__;
356 if(boardReaderNode.isDisconnected())
364 catch(
const std::runtime_error&)
366 __COUT__ <<
"Ignoring error, assume this a valid UID node." << __E__;
377 OUT <<
"fragment_receiver: {\n";
380 OUT <<
"max_fragment_size_bytes: " << maxFragmentSizeBytes <<
"\n";
384 <<
": " << boardReaderNode.getNode(
"daqGeneratorPluginType").getValue()
385 << (
"\t #daq generator plug-in type") <<
"\n";
386 OUT <<
"fragment_type"
387 <<
": " << boardReaderNode.getNode(
"daqGeneratorFragmentType").getValue()
388 << (
"\t #generator data fragment type") <<
"\n\n";
391 auto parametersLink = boardReaderNode.getNode(
"daqParametersLink");
392 if(!parametersLink.isDisconnected())
394 auto parameters = parametersLink.getChildren();
395 for(
auto& parameter : parameters)
397 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
409 parameter.second.getNode(TableViewColumnInfo::COL_NAME_COMMENT);
410 OUT << parameter.second.getNode(
"daqParameterKey").getValue() <<
": "
411 << parameter.second.getNode(
"daqParameterValue").getValue()
412 << (comment.isDefaultValue() ?
"" : (
"\t # " + comment.getValue()))
415 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
450 OUT <<
"destinations: {\n";
457 OUT <<
"metrics: {\n";
460 auto metricsGroup = boardReaderNode.getNode(
"daqMetricsLink");
461 if(!metricsGroup.isDisconnected())
463 auto metrics = metricsGroup.getChildren();
465 for(
auto& metric : metrics)
467 if(!metric.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
471 OUT << metric.second.getNode(
"metricKey").getValue() <<
": {\n";
474 OUT <<
"metricPluginType: "
475 << metric.second.getNode(
"metricPluginType").getValue() <<
"\n";
476 OUT <<
"level: " << metric.second.getNode(
"metricLevel").getValue() <<
"\n";
478 auto metricParametersGroup = metric.second.getNode(
"metricParametersLink");
479 if(!metricParametersGroup.isDisconnected())
481 auto metricParameters = metricParametersGroup.getChildren();
482 for(
auto& metricParameter : metricParameters)
484 if(!metricParameter.second
485 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
489 OUT << metricParameter.second.getNode(
"metricParameterKey").getValue()
491 << metricParameter.second.getNode(
"metricParameterValue")
495 if(!metricParameter.second
496 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
504 if(!metric.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)