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;
63 std::vector<const XDAQContextConfiguration::XDAQContext *> readerContexts =
64 contextConfig->getBoardReaderContexts();
72 for(
auto &readerContext: readerContexts)
76 ConfigurationTree readerConfigNode = contextConfig->getSupervisorConfigNode(configManager,
77 readerContext->contextUID_, readerContext->applications_[0].applicationUID_);
79 __COUT__ <<
"Path for this reader config is " <<
80 readerContext->contextUID_ <<
"/" <<
81 readerContext->applications_[0].applicationUID_ <<
"/" <<
82 readerConfigNode.getValueAsString() <<
85 __COUT__ <<
"Checking that this reader supervisor node is DataManager-like." << std::endl;
87 readerConfigNode.getNode(
"LinkToDataManagerConfiguration").getChildren();
89 catch(
const std::runtime_error& e)
91 __SS__ <<
"artdaq Board Readers must be instantiated as a Consumer within a DataManager configuration. Error found while checking for LinkToDataManagerConfiguration: " <<
92 e.what() << std::endl;
93 __COUT_ERR__ << ss.str();
94 __COUT__ <<
"Path for this reader config is " <<
95 readerContext->contextUID_ <<
"/" <<
96 readerContext->applications_[0].applicationUID_ <<
"/X" << std::endl;
97 __COUT_ERR__ <<
"This board reader will likely not get instantiated properly! Proceeding anyway with fcl generation." << std::endl;
111 auto childrenMap = configManager->__SELF_NODE__.getChildren();
112 std::string appUID, buffUID, consumerUID;
114 for(
auto &child:childrenMap)
115 if(child.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<
bool>())
117 outputFHICL(child.second, contextConfig);
131 std::string ARTDAQBoardReaderConfiguration::getFHICLFilename(
const ConfigurationTree &boardReaderNode)
133 __COUT__ <<
"ARTDAQ BoardReader UID: " << boardReaderNode.getValue() << std::endl;
134 std::string filename = ARTDAQ_FCL_PATH + ARTDAQ_FILE_PREAMBLE +
"-";
135 std::string uid = boardReaderNode.getValue();
136 for(
unsigned int i=0;i<uid.size();++i)
137 if((uid[i] >=
'a' && uid[i] <=
'z') ||
138 (uid[i] >=
'A' && uid[i] <=
'Z') ||
139 (uid[i] >=
'0' && uid[i] <=
'9'))
144 __COUT__ <<
"fcl: " << filename << std::endl;
150 void ARTDAQBoardReaderConfiguration::outputFHICL(
const ConfigurationTree &boardReaderNode,
246 std::string filename = getFHICLFilename(boardReaderNode);
252 std::string tabStr =
"";
253 std::string commentStr =
"";
255 out.open(filename, std::fstream::out | std::fstream::trunc);
258 __SS__ <<
"Failed to open ARTDAQ Builder fcl file: " << filename << std::endl;
259 throw std::runtime_error(ss.str());
265 if(boardReaderNode.isDisconnected())
273 catch(
const std::runtime_error)
275 __COUT__ <<
"Ignoring error, assume this a valid UID node." << std::endl;
286 OUT <<
"fragment_receiver: {\n";
291 OUT <<
"generator" <<
293 boardReaderNode.getNode(
"daqGeneratorPluginType").getValue()<<
294 (
"\t #daq generator plug-in type") <<
296 OUT <<
"fragment_type" <<
298 boardReaderNode.getNode(
"daqGeneratorFragmentType").getValue() <<
299 (
"\t #generator data fragment type") <<
303 auto parametersLink = boardReaderNode.getNode(
"daqParametersLink");
304 if(!parametersLink.isDisconnected())
307 auto parameters = parametersLink.getChildren();
308 for(
auto ¶meter:parameters)
310 if(!parameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<
bool>())
319 auto comment = parameter.second.getNode(
"CommentDescription");
320 OUT << parameter.second.getNode(
"daqParameterKey").getValue() <<
322 parameter.second.getNode(
"daqParameterValue").getValue()
324 (comment.isDefaultValue()?
"":(
"\t # " + comment.getValue())) <<
327 if(!parameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<
bool>())
359 OUT <<
"destinations: {\n";
362 auto destinationsGroup = boardReaderNode.getNode(
"daqDestinationsLink");
363 if(!destinationsGroup.isDisconnected())
367 auto destinations = destinationsGroup.getChildren();
368 for(
auto &destination:destinations)
370 unsigned int destinationRank =
371 contextConfig->getARTDAQAppRank(
372 destination.second.getNode(
"destinationARTDAQContextLink").getValue());
373 OUT << destination.second.getNode(
"destinationKey").getValue() <<
375 " transferPluginType: " <<
376 destination.second.getNode(
"transferPluginType").getValue() <<
377 " destination_rank: " <<
379 " max_fragment_size_words: " <<
380 destination.second.getNode(
"ARTDAQGlobalConfigurationLink/maxFragmentSizeWords").getValue<
unsigned int>() <<
384 catch(
const std::runtime_error& e)
386 __SS__ <<
"Are the DAQ destinations valid? Error occurred looking for Board Reader DAQ sources for UID '" <<
387 boardReaderNode.getValue() <<
"': " << e.what() << std::endl;
388 __COUT_ERR__ << ss.str() << std::endl;
389 throw std::runtime_error(ss.str());
399 OUT <<
"metrics: {\n";
402 auto metricsGroup = boardReaderNode.getNode(
"daqMetricsLink");
403 if(!metricsGroup.isDisconnected())
405 auto metrics = metricsGroup.getChildren();
407 for(
auto &metric:metrics)
409 if(!metric.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<
bool>())
412 OUT << metric.second.getNode(
"metricKey").getValue() <<
416 OUT <<
"metricPluginType: " <<
417 metric.second.getNode(
"metricPluginType").getValue()
420 metric.second.getNode(
"metricLevel").getValue()
423 auto metricParametersGroup = metric.second.getNode(
"metricParametersLink");
424 if(!metricParametersGroup.isDisconnected())
426 auto metricParameters = metricParametersGroup.getChildren();
427 for(
auto &metricParameter:metricParameters)
429 if(!metricParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<
bool>())
432 OUT << metricParameter.second.getNode(
"metricParameterKey").getValue() <<
434 metricParameter.second.getNode(
"metricParameterValue").getValue()
437 if(!metricParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<
bool>())
445 if(!metric.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<
bool>())