1 #include "otsdaq-core/ConfigurationPluginDataFormats/ARTDAQBoardReaderConfiguration.h"
2 #include "otsdaq-core/Macros/ConfigurationPluginMacros.h"
3 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
4 #include "otsdaq-core/ConfigurationPluginDataFormats/XDAQContextConfiguration.h"
14 #define ARTDAQ_FCL_PATH std::string(getenv("USER_DATA")) + "/"+ "ARTDAQConfigurations/"
15 #define ARTDAQ_FILE_PREAMBLE "boardReader"
18 #define OUT out << tabStr << commentStr
19 #define PUSHTAB tabStr += "\t"
20 #define POPTAB tabStr.resize(tabStr.size()-1)
21 #define PUSHCOMMENT commentStr += "# "
22 #define POPCOMMENT commentStr.resize(commentStr.size()-2)
26 ARTDAQBoardReaderConfiguration::ARTDAQBoardReaderConfiguration(
void)
36 ARTDAQBoardReaderConfiguration::~ARTDAQBoardReaderConfiguration(
void)
43 mkdir((ARTDAQ_FCL_PATH).c_str(), 0755);
45 __COUT__ <<
"*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << std::endl;
46 __COUT__ << configManager->__SELF_NODE__ << std::endl;
50 std::vector<const XDAQContextConfiguration::XDAQContext *> readerContexts =
51 contextConfig->getBoardReaderContexts();
57 for (
auto &readerContext : readerContexts)
61 ConfigurationTree readerConfigNode = contextConfig->getSupervisorConfigNode(configManager,
62 readerContext->contextUID_, readerContext->applications_[0].applicationUID_);
64 __COUT__ <<
"Path for this reader config is " <<
65 readerContext->contextUID_ <<
"/" <<
66 readerContext->applications_[0].applicationUID_ <<
"/" <<
67 readerConfigNode.getValueAsString() <<
70 __COUT__ <<
"Checking that this reader supervisor node is DataManager-like." << std::endl;
72 readerConfigNode.getNode(
"LinkToDataManagerConfiguration").getChildren();
75 catch (
const std::runtime_error& e)
77 __SS__ <<
"artdaq Board Readers must be instantiated as a Consumer within a DataManager configuration. Error found while checking for LinkToDataManagerConfiguration: " <<
78 e.what() << std::endl;
79 __COUT_ERR__ << ss.str();
80 __COUT__ <<
"Path for this reader config is " <<
81 readerContext->contextUID_ <<
"/" <<
82 readerContext->applications_[0].applicationUID_ <<
"/X" << std::endl;
83 __COUT_ERR__ <<
"This board reader will likely not get instantiated properly! Proceeding anyway with fcl generation." << std::endl;
97 auto childrenMap = configManager->__SELF_NODE__.getChildren();
98 std::string appUID, buffUID, consumerUID;
99 for (
auto &child : childrenMap)
102 for (
auto& readerContext : readerContexts) {
103 ConfigurationTree readerConfigNode = contextConfig->getSupervisorConfigNode(configManager,
104 readerContext->contextUID_, readerContext->applications_[0].applicationUID_);
105 auto dataManagerConfMap = readerConfigNode.getNode(
"LinkToDataManagerConfiguration").getChildren();
106 for (
auto dmc : dataManagerConfMap) {
107 auto dataBufferConfMap = dmc.second.getNode(
"LinkToDataBufferConfiguration").getChildren();
108 for (
auto dbc : dataBufferConfMap) {
109 auto processorConfUID = dbc.second.getNode(
"LinkToProcessorUID").getUIDAsString();
110 if (processorConfUID == child.second.getValue()) {
111 __COUT__ <<
"Found match for context UID: " << readerContext->contextUID_ << std::endl;
112 thisContext = readerContext;
118 if (thisContext ==
nullptr) {
119 __COUT_ERR__ <<
"Could not find matching context for this configuration!" << std::endl;
122 if (child.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<
bool>())
124 outputFHICL(configManager, child.second,
125 contextConfig->getARTDAQAppRank(thisContext->contextUID_),
126 contextConfig->getContextAddress(thisContext->contextUID_),
127 contextConfig->getARTDAQDataPort(configManager,thisContext->contextUID_),
144 std::string ARTDAQBoardReaderConfiguration::getFHICLFilename(
const ConfigurationTree &boardReaderNode)
146 __COUT__ <<
"ARTDAQ BoardReader UID: " << boardReaderNode.getValue() << std::endl;
147 std::string filename = ARTDAQ_FCL_PATH + ARTDAQ_FILE_PREAMBLE +
"-";
148 std::string uid = boardReaderNode.getValue();
149 for (
unsigned int i = 0; i < uid.size(); ++i)
150 if ((uid[i] >=
'a' && uid[i] <=
'z') ||
151 (uid[i] >=
'A' && uid[i] <=
'Z') ||
152 (uid[i] >=
'0' && uid[i] <=
'9'))
157 __COUT__ <<
"fcl: " << filename << std::endl;
164 const ConfigurationTree &boardReaderNode,
unsigned int selfRank, std::string selfHost,
unsigned int selfPort,
260 std::string filename = getFHICLFilename(boardReaderNode);
266 std::string tabStr =
"";
267 std::string commentStr =
"";
269 out.open(filename, std::fstream::out | std::fstream::trunc);
272 __SS__ <<
"Failed to open ARTDAQ Builder fcl file: " << filename << std::endl;
273 throw std::runtime_error(ss.str());
279 if (boardReaderNode.isDisconnected())
287 catch (
const std::runtime_error)
289 __COUT__ <<
"Ignoring error, assume this a valid UID node." << std::endl;
300 OUT <<
"fragment_receiver: {\n";
305 OUT <<
"generator" <<
307 boardReaderNode.getNode(
"daqGeneratorPluginType").getValue() <<
308 (
"\t #daq generator plug-in type") <<
310 OUT <<
"fragment_type" <<
312 boardReaderNode.getNode(
"daqGeneratorFragmentType").getValue() <<
313 (
"\t #generator data fragment type") <<
317 auto parametersLink = boardReaderNode.getNode(
"daqParametersLink");
318 if (!parametersLink.isDisconnected())
321 auto parameters = parametersLink.getChildren();
322 for (
auto ¶meter : parameters)
324 if (!parameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<
bool>())
333 auto comment = parameter.second.getNode(
"CommentDescription");
334 OUT << parameter.second.getNode(
"daqParameterKey").getValue() <<
336 parameter.second.getNode(
"daqParameterValue").getValue()
338 (comment.isDefaultValue() ?
"" : (
"\t # " + comment.getValue())) <<
341 if (!parameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<
bool>())
373 OUT <<
"destinations: {\n";
376 auto destinationsGroup = boardReaderNode.getNode(
"daqDestinationsLink");
377 if (!destinationsGroup.isDisconnected())
381 auto destinations = destinationsGroup.getChildren();
382 for (
auto &destination : destinations)
384 auto destinationContextUID = destination.second.getNode(
"destinationARTDAQContextLink").getValueAsString();
386 unsigned int destinationRank = contextConfig->getARTDAQAppRank(destinationContextUID);
387 std::string host = contextConfig->getContextAddress(destinationContextUID);
388 unsigned int port = contextConfig->getARTDAQDataPort(configManager,destinationContextUID);
390 OUT << destination.second.getNode(
"destinationKey").getValue() <<
392 " transferPluginType: " <<
393 destination.second.getNode(
"transferPluginType").getValue() <<
394 " destination_rank: " <<
396 " max_fragment_size_words: " <<
397 destination.second.getNode(
"ARTDAQGlobalConfigurationLink/maxFragmentSizeWords").getValue<
unsigned int>() <<
398 " host_map: [{rank: " << destinationRank <<
" host: \"" << host <<
"\" portOffset: " << std::to_string(port) <<
"}, " <<
399 "{rank: " << selfRank <<
" host: \"" << selfHost <<
"\" portOffset: " << std::to_string(selfPort) <<
"}]" <<
403 catch (
const std::runtime_error& e)
405 __SS__ <<
"Are the DAQ destinations valid? Error occurred looking for Board Reader DAQ sources for UID '" <<
406 boardReaderNode.getValue() <<
"': " << e.what() << std::endl;
407 __COUT_ERR__ << ss.str() << std::endl;
408 throw std::runtime_error(ss.str());
418 OUT <<
"metrics: {\n";
421 auto metricsGroup = boardReaderNode.getNode(
"daqMetricsLink");
422 if (!metricsGroup.isDisconnected())
424 auto metrics = metricsGroup.getChildren();
426 for (
auto &metric : metrics)
428 if (!metric.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<
bool>())
431 OUT << metric.second.getNode(
"metricKey").getValue() <<
435 OUT <<
"metricPluginType: " <<
436 metric.second.getNode(
"metricPluginType").getValue()
439 metric.second.getNode(
"metricLevel").getValue()
442 auto metricParametersGroup = metric.second.getNode(
"metricParametersLink");
443 if (!metricParametersGroup.isDisconnected())
445 auto metricParameters = metricParametersGroup.getChildren();
446 for (
auto &metricParameter : metricParameters)
448 if (!metricParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<
bool>())
451 OUT << metricParameter.second.getNode(
"metricParameterKey").getValue() <<
453 metricParameter.second.getNode(
"metricParameterValue").getValue()
456 if (!metricParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<
bool>())
464 if (!metric.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<
bool>())