1 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
2 #include "otsdaq-core/Macros/TablePluginMacros.h"
3 #include "otsdaq-core/TablePluginDataFormats/ARTDAQBoardReaderTable.h"
4 #include "otsdaq-core/TablePluginDataFormats/XDAQContextTable.h"
13 #define ARTDAQ_FCL_PATH std::string(getenv("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) :
TableBase(
"ARTDAQBoardReaderTable")
32 ARTDAQBoardReaderTable::~ARTDAQBoardReaderTable(
void) {}
38 mkdir((ARTDAQ_FCL_PATH).c_str(), 0755);
40 __COUT__ <<
"*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << __E__;
41 __COUT__ << configManager->__SELF_NODE__ << __E__;
46 std::vector<const XDAQContextTable::XDAQContext*> readerContexts =
47 contextConfig->getBoardReaderContexts();
52 for(
auto& readerContext : readerContexts)
58 readerContext->contextUID_,
59 readerContext->applications_[0].applicationUID_);
61 __COUT__ <<
"Path for this reader config is " << readerContext->contextUID_
62 <<
"/" << readerContext->applications_[0].applicationUID_ <<
"/"
63 << readerConfigNode.getValueAsString() << __E__;
65 __COUT__ <<
"Checking that this reader supervisor node is DataManager-like."
68 readerConfigNode.getNode(
"LinkToDataBufferTable").getChildren();
70 catch(
const std::runtime_error& e)
72 __SS__ <<
"artdaq Board Readers must be instantiated as a Consumer within a "
74 <<
"Error found while checking for LinkToDataBufferTable: " << e.what()
76 __COUT_ERR__ << ss.str();
77 __COUT__ <<
"Path for this reader config is " << readerContext->contextUID_
78 <<
"/" << readerContext->applications_[0].applicationUID_ <<
"/X"
80 __COUT_ERR__ <<
"This board reader will likely not get instantiated "
81 "properly! Proceeding anyway with fcl generation."
97 auto childrenMap = configManager->__SELF_NODE__.getChildren();
98 std::string appUID, buffUID, consumerUID;
99 for(
auto& child : childrenMap)
102 for(
auto& readerContext : readerContexts)
106 readerContext->contextUID_,
107 readerContext->applications_[0].applicationUID_);
108 auto dataManagerConfMap =
109 readerConfigNode.getNode(
"LinkToDataBufferTable").getChildren();
110 for(
auto dmc : dataManagerConfMap)
112 auto dataBufferConfMap =
113 dmc.second.getNode(
"LinkToDataProcessorTable").getChildren();
114 for(
auto dbc : dataBufferConfMap)
116 auto processorConfUID =
117 dbc.second.getNode(
"LinkToProcessorUID").getUIDAsString();
118 if(processorConfUID == child.second.getValue())
120 __COUT__ <<
"Found match for context UID: "
121 << readerContext->contextUID_ << __E__;
122 thisContext = readerContext;
128 if(thisContext ==
nullptr)
130 __COUT_ERR__ <<
"Could not find matching context for this table!" << __E__;
134 if(child.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
137 outputFHICL(configManager,
139 contextConfig->getARTDAQAppRank(thisContext->contextUID_),
140 contextConfig->getContextAddress(thisContext->contextUID_),
141 contextConfig->getARTDAQDataPort(configManager,
142 thisContext->contextUID_),
159 std::string ARTDAQBoardReaderTable::getFHICLFilename(
162 __COUT__ <<
"ARTDAQ BoardReader UID: " << boardReaderNode.getValue() << __E__;
163 std::string filename = ARTDAQ_FCL_PATH + ARTDAQ_FILE_PREAMBLE +
"-";
164 std::string uid = boardReaderNode.getValue();
165 for(
unsigned int i = 0; i < uid.size(); ++i)
166 if((uid[i] >=
'a' && uid[i] <=
'z') || (uid[i] >=
'A' && uid[i] <=
'Z') ||
167 (uid[i] >=
'0' && uid[i] <=
'9'))
172 __COUT__ <<
"fcl: " << filename << __E__;
180 unsigned int selfRank,
181 std::string selfHost,
182 unsigned int selfPort,
310 std::string filename = getFHICLFilename(boardReaderNode);
316 std::string tabStr =
"";
317 std::string commentStr =
"";
319 out.open(filename, std::fstream::out | std::fstream::trunc);
322 __SS__ <<
"Failed to open ARTDAQ Builder fcl file: " << filename << __E__;
328 OUT <<
"###########################################################" << __E__;
330 OUT <<
"# artdaq reader fcl configuration file produced by otsdaq." << __E__;
331 OUT <<
"# Creation timestamp: " << StringMacros::getTimestampString() << __E__;
332 OUT <<
"# Original filename: " << filename << __E__;
333 OUT <<
"# otsdaq-ARTDAQ Reader UID: " << boardReaderNode.getValue() << __E__;
335 OUT <<
"###########################################################" << __E__;
341 if(boardReaderNode.isDisconnected())
349 catch(
const std::runtime_error)
351 __COUT__ <<
"Ignoring error, assume this a valid UID node." << __E__;
362 OUT <<
"fragment_receiver: {\n";
368 <<
": " << boardReaderNode.getNode(
"daqGeneratorPluginType").getValue()
369 << (
"\t #daq generator plug-in type") <<
"\n";
370 OUT <<
"fragment_type"
371 <<
": " << boardReaderNode.getNode(
"daqGeneratorFragmentType").getValue()
372 << (
"\t #generator data fragment type") <<
"\n\n";
375 auto parametersLink = boardReaderNode.getNode(
"daqParametersLink");
376 if(!parametersLink.isDisconnected())
378 auto parameters = parametersLink.getChildren();
379 for(
auto& parameter : parameters)
381 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
392 auto comment = parameter.second.getNode(
"CommentDescription");
393 OUT << parameter.second.getNode(
"daqParameterKey").getValue() <<
": "
394 << parameter.second.getNode(
"daqParameterValue").getValue()
395 << (comment.isDefaultValue() ?
"" : (
"\t # " + comment.getValue()))
398 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
432 OUT <<
"destinations: {\n";
435 auto destinationsGroup = boardReaderNode.getNode(
"daqDestinationsLink");
436 if(!destinationsGroup.isDisconnected())
440 auto destinations = destinationsGroup.getChildren();
441 for(
auto& destination : destinations)
443 auto destinationContextUID =
444 destination.second.getNode(
"destinationARTDAQContextLink")
447 unsigned int destinationRank =
448 contextConfig->getARTDAQAppRank(destinationContextUID);
450 contextConfig->getContextAddress(destinationContextUID);
451 unsigned int port = contextConfig->getARTDAQDataPort(
452 configManager, destinationContextUID);
455 OUT << destination.second.getNode(
"destinationKey").getValue() <<
": {\n";
458 OUT <<
"transferPluginType: "
459 << destination.second.getNode(
"transferPluginType").getValue()
462 OUT <<
"destination_rank: " << destinationRank << __E__;
466 OUT <<
"max_fragment_size_bytes: "
467 << destination.second
468 .getNode(
"ARTDAQGlobalTableLink/maxFragmentSizeBytes")
469 .getValue<
unsigned long long>()
474 __SS__ <<
"The field ARTDAQGlobalTableLink/maxFragmentSizeBytes "
475 "could not be accessed. Make sure the link is valid."
480 OUT <<
"host_map: [\n";
484 OUT <<
"rank: " << destinationRank << __E__;
485 OUT <<
"host: \"" << host <<
"\"" << __E__;
486 OUT <<
"portOffset: " << std::to_string(port) << __E__;
491 OUT <<
"rank: " << selfRank << __E__;
492 OUT <<
"host: \"" << selfHost <<
"\"" << __E__;
493 OUT <<
"portOffset: " << std::to_string(selfPort) << __E__;
503 catch(
const std::runtime_error& e)
505 __SS__ <<
"Are the DAQ destinations valid? Error occurred looking for Board "
506 "Reader DAQ sources for UID '"
507 << boardReaderNode.getValue() <<
"': " << e.what() << __E__;
517 OUT <<
"metrics: {\n";
520 auto metricsGroup = boardReaderNode.getNode(
"daqMetricsLink");
521 if(!metricsGroup.isDisconnected())
523 auto metrics = metricsGroup.getChildren();
525 for(
auto& metric : metrics)
527 if(!metric.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
531 OUT << metric.second.getNode(
"metricKey").getValue() <<
": {\n";
534 OUT <<
"metricPluginType: "
535 << metric.second.getNode(
"metricPluginType").getValue() <<
"\n";
536 OUT <<
"level: " << metric.second.getNode(
"metricLevel").getValue() <<
"\n";
538 auto metricParametersGroup = metric.second.getNode(
"metricParametersLink");
539 if(!metricParametersGroup.isDisconnected())
541 auto metricParameters = metricParametersGroup.getChildren();
542 for(
auto& metricParameter : metricParameters)
544 if(!metricParameter.second
545 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
549 OUT << metricParameter.second.getNode(
"metricParameterKey").getValue()
551 << metricParameter.second.getNode(
"metricParameterValue")
555 if(!metricParameter.second
556 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
564 if(!metric.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)