1 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
2 #include "otsdaq-core/Macros/TablePluginMacros.h"
3 #include "otsdaq-core/TablePlugins/ARTDAQBoardReaderTable.h"
4 #include "otsdaq-core/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) :
TableBase(
"ARTDAQBoardReaderTable")
32 ARTDAQBoardReaderTable::~ARTDAQBoardReaderTable(
void) {}
39 bool isFirstAppInContext = configManager->isOwnerFirstAppInContext();
42 if(!isFirstAppInContext)
46 mkdir((ARTDAQ_FCL_PATH).c_str(), 0755);
48 __COUT__ <<
"*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << __E__;
49 __COUT__ << configManager->__SELF_NODE__ << __E__;
54 std::vector<const XDAQContextTable::XDAQContext*> readerContexts =
55 contextConfig->getBoardReaderContexts();
60 for(
auto& readerContext : readerContexts)
66 readerContext->contextUID_,
67 readerContext->applications_[0].applicationUID_);
69 __COUT__ <<
"Path for this reader config is " << readerContext->contextUID_
70 <<
"/" << readerContext->applications_[0].applicationUID_ <<
"/"
71 << readerConfigNode.getValueAsString() << __E__;
73 __COUT__ <<
"Checking that this reader supervisor node is DataManager-like."
76 readerConfigNode.getNode(
"LinkToDataBufferTable").getChildren();
78 catch(
const std::runtime_error& e)
80 __SS__ <<
"artdaq Board Readers must be instantiated as a Consumer within a "
82 <<
"Error found while checking for LinkToDataBufferTable: " << e.what()
84 __COUT_ERR__ << ss.str();
85 __COUT__ <<
"Path for this reader config is " << readerContext->contextUID_
86 <<
"/" << readerContext->applications_[0].applicationUID_ <<
"/X"
88 __COUT_ERR__ <<
"This board reader will likely not get instantiated "
89 "properly! Proceeding anyway with fcl generation."
105 auto childrenMap = configManager->__SELF_NODE__.getChildren();
106 std::string appUID, buffUID, consumerUID;
107 for(
auto& child : childrenMap)
110 for(
auto& readerContext : readerContexts)
114 readerContext->contextUID_,
115 readerContext->applications_[0].applicationUID_);
116 auto dataManagerConfMap =
117 readerConfigNode.getNode(
"LinkToDataBufferTable").getChildren();
118 for(
auto dmc : dataManagerConfMap)
120 auto dataBufferConfMap =
121 dmc.second.getNode(
"LinkToDataProcessorTable").getChildren();
122 for(
auto dbc : dataBufferConfMap)
124 auto processorConfUID =
125 dbc.second.getNode(
"LinkToProcessorUID").getUIDAsString();
126 if(processorConfUID == child.second.getValue())
128 __COUT__ <<
"Found match for context UID: "
129 << readerContext->contextUID_ << __E__;
130 thisContext = readerContext;
136 if(thisContext ==
nullptr)
138 __COUT_ERR__ <<
"Could not find matching context for this table!" << __E__;
142 if(child.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
145 outputFHICL(configManager,
147 contextConfig->getARTDAQAppRank(thisContext->contextUID_),
148 contextConfig->getContextAddress(thisContext->contextUID_),
149 contextConfig->getARTDAQDataPort(configManager,
150 thisContext->contextUID_),
167 std::string ARTDAQBoardReaderTable::getFHICLFilename(
170 __COUT__ <<
"ARTDAQ BoardReader UID: " << boardReaderNode.getValue() << __E__;
171 std::string filename = ARTDAQ_FCL_PATH + ARTDAQ_FILE_PREAMBLE +
"-";
172 std::string uid = boardReaderNode.getValue();
173 for(
unsigned int i = 0; i < uid.size(); ++i)
174 if((uid[i] >=
'a' && uid[i] <=
'z') || (uid[i] >=
'A' && uid[i] <=
'Z') ||
175 (uid[i] >=
'0' && uid[i] <=
'9'))
180 __COUT__ <<
"fcl: " << filename << __E__;
188 unsigned int selfRank,
189 std::string selfHost,
190 unsigned int selfPort,
318 std::string filename = getFHICLFilename(boardReaderNode);
324 std::string tabStr =
"";
325 std::string commentStr =
"";
327 out.open(filename, std::fstream::out | std::fstream::trunc);
330 __SS__ <<
"Failed to open ARTDAQ Builder fcl file: " << filename << __E__;
336 OUT <<
"###########################################################" << __E__;
338 OUT <<
"# artdaq reader fcl configuration file produced by otsdaq." << __E__;
339 OUT <<
"# Creation timestamp: " << StringMacros::getTimestampString() << __E__;
340 OUT <<
"# Original filename: " << filename << __E__;
341 OUT <<
"# otsdaq-ARTDAQ Reader UID: " << boardReaderNode.getValue() << __E__;
343 OUT <<
"###########################################################" << __E__;
349 if(boardReaderNode.isDisconnected())
357 catch(
const std::runtime_error&)
359 __COUT__ <<
"Ignoring error, assume this a valid UID node." << __E__;
370 OUT <<
"fragment_receiver: {\n";
376 <<
": " << boardReaderNode.getNode(
"daqGeneratorPluginType").getValue()
377 << (
"\t #daq generator plug-in type") <<
"\n";
378 OUT <<
"fragment_type"
379 <<
": " << boardReaderNode.getNode(
"daqGeneratorFragmentType").getValue()
380 << (
"\t #generator data fragment type") <<
"\n\n";
383 auto parametersLink = boardReaderNode.getNode(
"daqParametersLink");
384 if(!parametersLink.isDisconnected())
386 auto parameters = parametersLink.getChildren();
387 for(
auto& parameter : parameters)
389 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
401 parameter.second.getNode(TableViewColumnInfo::COL_NAME_COMMENT);
402 OUT << parameter.second.getNode(
"daqParameterKey").getValue() <<
": "
403 << parameter.second.getNode(
"daqParameterValue").getValue()
404 << (comment.isDefaultValue() ?
"" : (
"\t # " + comment.getValue()))
407 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
442 OUT <<
"destinations: {\n";
445 auto destinationsGroup = boardReaderNode.getNode(
"daqDestinationsLink");
446 if(!destinationsGroup.isDisconnected())
450 auto destinations = destinationsGroup.getChildren();
451 for(
auto& destination : destinations)
453 auto destinationContextUID =
454 destination.second.getNode(
"destinationARTDAQContextLink")
457 unsigned int destinationRank = -1;
461 contextConfig->getARTDAQAppRank(destinationContextUID);
463 catch(
const std::runtime_error& e)
466 "Are the DAQ destinations valid? "
467 <<
"Perhaps a Context has been turned off? "
468 <<
"Skipping destination due to an error looking for Board "
469 <<
"Reader DAQ source context '" << destinationContextUID
470 <<
"' for UID '" << boardReaderNode.getValue()
471 <<
"': " << e.what() << __E__);
476 contextConfig->getContextAddress(destinationContextUID);
477 unsigned int port = contextConfig->getARTDAQDataPort(
478 configManager, destinationContextUID);
481 OUT << destination.second.getNode(
"destinationKey").getValue() <<
": {\n";
484 OUT <<
"transferPluginType: "
485 << destination.second.getNode(
"transferPluginType").getValue()
488 OUT <<
"destination_rank: " << destinationRank << __E__;
492 auto mfsb = destination.second
493 .getNode(
"ARTDAQGlobalTableLink/maxFragmentSizeBytes")
494 .getValue<
unsigned long long>();
495 OUT <<
"max_fragment_size_bytes: " << mfsb << __E__;
496 OUT <<
"max_fragment_size_words: " << (mfsb / 8) << __E__;
500 __SS__ <<
"The field ARTDAQGlobalTableLink/maxFragmentSizeBytes "
501 "could not be accessed. Make sure the link is valid."
506 OUT <<
"host_map: [\n";
510 OUT <<
"rank: " << destinationRank << __E__;
511 OUT <<
"host: \"" << host <<
"\"" << __E__;
512 OUT <<
"portOffset: " << std::to_string(port) << __E__;
517 OUT <<
"rank: " << selfRank << __E__;
518 OUT <<
"host: \"" << selfHost <<
"\"" << __E__;
519 OUT <<
"portOffset: " << std::to_string(selfPort) << __E__;
529 catch(
const std::runtime_error& e)
531 __SS__ <<
"Are the DAQ destinations valid? Error occurred looking for Board "
532 "Reader DAQ sources for UID '"
533 << boardReaderNode.getValue() <<
"': " << e.what() << __E__;
543 OUT <<
"metrics: {\n";
546 auto metricsGroup = boardReaderNode.getNode(
"daqMetricsLink");
547 if(!metricsGroup.isDisconnected())
549 auto metrics = metricsGroup.getChildren();
551 for(
auto& metric : metrics)
553 if(!metric.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
557 OUT << metric.second.getNode(
"metricKey").getValue() <<
": {\n";
560 OUT <<
"metricPluginType: "
561 << metric.second.getNode(
"metricPluginType").getValue() <<
"\n";
562 OUT <<
"level: " << metric.second.getNode(
"metricLevel").getValue() <<
"\n";
564 auto metricParametersGroup = metric.second.getNode(
"metricParametersLink");
565 if(!metricParametersGroup.isDisconnected())
567 auto metricParameters = metricParametersGroup.getChildren();
568 for(
auto& metricParameter : metricParameters)
570 if(!metricParameter.second
571 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
575 OUT << metricParameter.second.getNode(
"metricParameterKey").getValue()
577 << metricParameter.second.getNode(
"metricParameterValue")
581 if(!metricParameter.second
582 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
590 if(!metric.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)