1 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
2 #include "otsdaq-core/Macros/TablePluginMacros.h"
3 #include "otsdaq-core/TablePluginDataFormats/ARTDAQAggregatorTable.h"
4 #include "otsdaq-core/TablePluginDataFormats/XDAQContextTable.h"
13 #define ARTDAQ_FCL_PATH std::string(getenv("USER_DATA")) + "/" + "ARTDAQConfigurations/"
14 #define ARTDAQ_FILE_PREAMBLE "aggregator"
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 ARTDAQAggregatorTable::ARTDAQAggregatorTable(
void) :
TableBase(
"ARTDAQAggregatorTable")
32 ARTDAQAggregatorTable::~ARTDAQAggregatorTable(
void) {}
38 mkdir((ARTDAQ_FCL_PATH).c_str(), 0755);
40 __COUT__ <<
"*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << std::endl;
41 __COUT__ << configManager->__SELF_NODE__ << std::endl;
45 std::vector<const XDAQContextTable::XDAQContext*> aggContexts =
46 contextConfig->getAggregatorContexts();
50 for(
auto& aggContext : aggContexts)
54 aggContext->contextUID_,
55 aggContext->applications_[0].applicationUID_);
57 __COUT__ <<
"Path for this aggregator config is " << aggContext->contextUID_
58 <<
"/" << aggContext->applications_[0].applicationUID_ <<
"/"
59 << aggConfigNode.getValueAsString() << std::endl;
64 contextConfig->getARTDAQAppRank(aggContext->contextUID_),
65 contextConfig->getContextAddress(aggContext->contextUID_),
66 contextConfig->getARTDAQDataPort(configManager, aggContext->contextUID_),
72 std::string ARTDAQAggregatorTable::getFHICLFilename(
75 __COUT__ <<
"ARTDAQ Aggregator UID: " << aggregatorNode.getValue() << std::endl;
76 std::string filename = ARTDAQ_FCL_PATH + ARTDAQ_FILE_PREAMBLE +
"-";
77 std::string uid = aggregatorNode.getValue();
78 for(
unsigned int i = 0; i < uid.size(); ++i)
79 if((uid[i] >=
'a' && uid[i] <=
'z') || (uid[i] >=
'A' && uid[i] <=
'Z') ||
80 (uid[i] >=
'0' && uid[i] <=
'9'))
85 __COUT__ <<
"fcl: " << filename << std::endl;
93 unsigned int selfRank,
95 unsigned int selfPort,
243 std::string filename = getFHICLFilename(aggregatorNode);
245 __COUT__ <<
"selfRank = " << selfRank << std::endl;
251 std::string tabStr =
"";
252 std::string commentStr =
"";
254 out.open(filename, std::fstream::out | std::fstream::trunc);
257 __SS__ <<
"Failed to open ARTDAQ Aggregator fcl file: " << filename << std::endl;
263 OUT <<
"###########################################################" << __E__;
265 OUT <<
"# artdaq aggregator fcl configuration file produced by otsdaq." << __E__;
266 OUT <<
"# Creation timestamp: " << StringMacros::getTimestampString() << __E__;
267 OUT <<
"# Original filename: " << filename << __E__;
268 OUT <<
"# otsdaq-ARTDAQ Aggregator UID: " << aggregatorNode.getValue() << __E__;
270 OUT <<
"###########################################################" << __E__;
275 auto services = aggregatorNode.getNode(
"servicesLink");
276 if(!services.isDisconnected())
278 OUT <<
"services: {\n";
282 OUT <<
"scheduler: {\n";
285 OUT <<
"fileMode: " << services.getNode(
"schedulerFileMode").getValue() <<
"\n";
286 OUT <<
"errorOnFailureToPut: "
287 << (services.getNode(
"schedulerErrorOnFailtureToPut").getValue<
bool>()
296 OUT <<
"NetMonTransportServiceInterface: {\n";
299 OUT <<
"service_provider: " <<
301 services.getNode(
"NetMonTrasportServiceInterfaceServiceProvider").getValue()
313 auto daq = aggregatorNode.getNode(
"daqLink");
314 if(!daq.isDisconnected())
320 OUT <<
"aggregator: {\n";
323 auto parametersLink = daq.getNode(
"daqAggregatorParametersLink");
324 if(!parametersLink.isDisconnected())
326 auto parameters = parametersLink.getChildren();
327 for(
auto& parameter : parameters)
329 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
333 auto comment = parameter.second.getNode(
"CommentDescription");
334 OUT << parameter.second.getNode(
"daqParameterKey").getValue() <<
": "
335 << parameter.second.getNode(
"daqParameterValue").getValue()
336 << (comment.isDefaultValue() ?
"" : (
"\t # " + comment.getValue()))
339 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
346 OUT <<
"sources: {\n";
349 auto sourcesGroup = daq.getNode(
"daqAggregatorSourcesLink");
350 if(!sourcesGroup.isDisconnected())
354 auto sources = sourcesGroup.getChildren();
355 for(
auto& source : sources)
357 std::string sourceContextUID =
358 source.second.getNode(
"sourceARTDAQContextLink")
361 std::string host = contextConfig->getContextAddress(sourceContextUID);
362 unsigned int sourceRank =
363 contextConfig->getARTDAQAppRank(sourceContextUID);
365 contextConfig->getARTDAQDataPort(configManager, sourceContextUID);
368 OUT << source.second.getNode(
"sourceKey").getValue() <<
": {\n";
371 OUT <<
"transferPluginType: "
372 << source.second.getNode(
"transferPluginType").getValue()
375 OUT <<
"source_rank: " << sourceRank << __E__;
379 OUT <<
"max_fragment_size_bytes: "
381 .getNode(
"ARTDAQGlobalTableLink/maxFragmentSizeBytes")
382 .getValue<
unsigned long long>()
387 __SS__ <<
"The field ARTDAQGlobalTableLink/maxFragmentSizeBytes "
388 "could not be accessed. Make sure the link is valid."
393 OUT <<
"host_map: [\n";
397 OUT <<
"rank: " << sourceRank << __E__;
398 OUT <<
"host: \"" << host <<
"\"" << __E__;
399 OUT <<
"portOffset: " << std::to_string(port) << __E__;
404 OUT <<
"rank: " << selfRank << __E__;
405 OUT <<
"host: \"" << selfHost <<
"\"" << __E__;
406 OUT <<
"portOffset: " << std::to_string(selfPort) << __E__;
416 catch(
const std::runtime_error& e)
418 __SS__ <<
"Are the DAQ sources valid? Error occurred looking for "
419 "Aggregator DAQ sources for UID '"
420 << aggregatorNode.getValue() <<
"': " << e.what() << std::endl;
421 __COUT_ERR__ << ss.str() << std::endl;
431 OUT <<
"metrics: {\n";
434 auto metricsGroup = daq.getNode(
"daqMetricsLink");
435 if(!metricsGroup.isDisconnected())
437 auto metrics = metricsGroup.getChildren();
439 for(
auto& metric : metrics)
441 if(!metric.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
445 OUT << metric.second.getNode(
"metricKey").getValue() <<
": {\n";
448 OUT <<
"metricPluginType: "
449 << metric.second.getNode(
"metricPluginType").getValue() <<
"\n";
450 OUT <<
"level: " << metric.second.getNode(
"metricLevel").getValue()
453 auto metricParametersGroup =
454 metric.second.getNode(
"metricParametersLink");
455 if(!metricParametersGroup.isDisconnected())
457 auto metricParameters = metricParametersGroup.getChildren();
458 for(
auto& metricParameter : metricParameters)
460 if(!metricParameter.second
461 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
466 metricParameter.second.getNode(
"CommentDescription");
467 OUT << metricParameter.second.getNode(
"metricParameterKey")
470 << metricParameter.second.getNode(
"metricParameterValue")
472 << (comment.isDefaultValue() ?
""
473 : (
"\t # " + comment.getValue()))
476 if(!metricParameter.second
477 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
485 if(!metric.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
493 OUT <<
"destinations: {\n";
497 auto destinationsGroup = daq.getNode(
"daqAggregatorDestinationsLink");
498 if(!destinationsGroup.isDisconnected())
502 auto destinations = destinationsGroup.getChildren();
503 for(
auto& destination : destinations)
505 auto destinationContextUID =
506 destination.second.getNode(
"destinationARTDAQContextLink")
509 unsigned int destinationRank =
510 contextConfig->getARTDAQAppRank(destinationContextUID);
512 contextConfig->getContextAddress(destinationContextUID);
513 unsigned int port = contextConfig->getARTDAQDataPort(
514 configManager, destinationContextUID);
517 OUT << destination.second.getNode(
"destinationKey").getValue()
521 OUT <<
"transferPluginType: "
522 << destination.second.getNode(
"transferPluginType").getValue()
525 OUT <<
"source_rank: " << destinationRank << __E__;
529 OUT <<
"max_fragment_size_bytes: "
530 << destination.second
531 .getNode(
"ARTDAQGlobalTableLink/maxFragmentSizeBytes")
532 .getValue<
unsigned long long>()
537 __SS__ <<
"The field ARTDAQGlobalTableLink/maxFragmentSizeBytes "
538 "could not be accessed. Make sure the link is valid."
543 OUT <<
"host_map: [\n";
547 OUT <<
"rank: " << destinationRank << __E__;
548 OUT <<
"host: \"" << host <<
"\"" << __E__;
549 OUT <<
"portOffset: " << std::to_string(port) << __E__;
554 OUT <<
"rank: " << selfRank << __E__;
555 OUT <<
"host: \"" << selfHost <<
"\"" << __E__;
556 OUT <<
"portOffset: " << std::to_string(selfPort) << __E__;
566 catch(
const std::runtime_error& e)
568 __SS__ <<
"Are the DAQ destinations valid? Error occurred looking for "
569 "Aggregator DAQ destinations for UID '"
570 << aggregatorNode.getValue() <<
"': " << e.what() << std::endl;
571 __COUT_ERR__ << ss.str() << std::endl;
584 auto source = aggregatorNode.getNode(
"sourceLink");
585 if(!source.isDisconnected())
587 OUT <<
"source: {\n";
590 OUT <<
"module_type: " << source.getNode(
"sourceModuleType").getValue() <<
"\n";
597 auto outputs = aggregatorNode.getNode(
"outputsLink");
598 if(!outputs.isDisconnected())
600 OUT <<
"outputs: {\n";
604 auto outputPlugins = outputs.getChildren();
605 for(
auto& outputPlugin : outputPlugins)
607 if(!outputPlugin.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
611 OUT << outputPlugin.second.getNode(
"outputKey").getValue() <<
": {\n";
613 OUT <<
"module_type: "
614 << outputPlugin.second.getNode(
"outputModuleType").getValue() <<
"\n";
615 auto pluginParameterLink =
616 outputPlugin.second.getNode(
"outputModuleParameterLink");
617 if(!pluginParameterLink.isDisconnected())
619 auto pluginParameters = pluginParameterLink.getChildren();
620 for(
auto& pluginParameter : pluginParameters)
622 if(!pluginParameter.second
623 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
627 auto comment = pluginParameter.second.getNode(
"CommentDescription");
628 OUT << pluginParameter.second.getNode(
"outputParameterKey").getValue()
630 << pluginParameter.second.getNode(
"outputParameterValue")
632 << (comment.isDefaultValue() ?
""
633 : (
"\t # " + comment.getValue()))
636 if(!pluginParameter.second
637 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
645 if(!outputPlugin.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
656 auto physics = aggregatorNode.getNode(
"physicsLink");
657 if(!physics.isDisconnected())
660 OUT <<
"physics: {\n";
664 auto analyzers = physics.getNode(
"analyzersLink");
665 if(!analyzers.isDisconnected())
668 OUT <<
"analyzers: {\n";
671 auto modules = analyzers.getChildren();
672 for(
auto& module : modules)
674 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
678 OUT << module.second.getNode(
"analyzerKey").getValue() <<
": {\n";
680 OUT <<
"module_type: "
681 << module.second.getNode(
"analyzerModuleType").getValue() <<
"\n";
682 auto moduleParameterLink =
683 module.second.getNode(
"analyzerModuleParameterLink");
684 if(!moduleParameterLink.isDisconnected())
686 auto moduleParameters = moduleParameterLink.getChildren();
687 for(
auto& moduleParameter : moduleParameters)
689 if(!moduleParameter.second
690 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
695 moduleParameter.second.getNode(
"CommentDescription");
696 OUT << moduleParameter.second.getNode(
"analyzerParameterKey")
699 << moduleParameter.second.getNode(
"analyzerParameterValue")
701 << (comment.isDefaultValue() ?
""
702 : (
"\t # " + comment.getValue()))
705 if(!moduleParameter.second
706 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
714 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
722 auto producers = physics.getNode(
"producersLink");
723 if(!producers.isDisconnected())
726 OUT <<
"producers: {\n";
729 auto modules = producers.getChildren();
730 for(
auto& module : modules)
732 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
736 OUT << module.second.getNode(
"producerKey").getValue() <<
": {\n";
738 OUT <<
"module_type: "
739 << module.second.getNode(
"producerModuleType").getValue() <<
"\n";
740 auto moduleParameterLink =
741 module.second.getNode(
"producerModuleParameterLink");
742 if(!moduleParameterLink.isDisconnected())
744 auto moduleParameters = moduleParameterLink.getChildren();
745 for(
auto& moduleParameter : moduleParameters)
747 if(!moduleParameter.second
748 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
753 moduleParameter.second.getNode(
"CommentDescription");
754 OUT << moduleParameter.second.getNode(
"producerParameterKey")
757 << moduleParameter.second.getNode(
"producerParameterValue")
759 << (comment.isDefaultValue() ?
""
760 : (
"\t # " + comment.getValue()))
763 if(!moduleParameter.second
764 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
772 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
780 auto filters = physics.getNode(
"filtersLink");
781 if(!filters.isDisconnected())
784 OUT <<
"filters: {\n";
787 auto modules = filters.getChildren();
788 for(
auto& module : modules)
790 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
794 OUT << module.second.getNode(
"filterKey").getValue() <<
": {\n";
796 OUT <<
"module_type: "
797 << module.second.getNode(
"filterModuleType").getValue() <<
"\n";
798 auto moduleParameterLink =
799 module.second.getNode(
"filterModuleParameterLink");
800 if(!moduleParameterLink.isDisconnected())
802 auto moduleParameters = moduleParameterLink.getChildren();
803 for(
auto& moduleParameter : moduleParameters)
805 if(!moduleParameter.second
806 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
811 moduleParameter.second.getNode(
"CommentDescription");
812 OUT << moduleParameter.second.getNode(
"filterParameterKey")
815 << moduleParameter.second.getNode(
"filterParameterValue")
817 << (comment.isDefaultValue() ?
""
818 : (
"\t # " + comment.getValue()))
821 if(!moduleParameter.second
822 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
830 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
838 auto otherParameterLink = physics.getNode(
"physicsOtherParametersLink");
839 if(!otherParameterLink.isDisconnected())
842 auto physicsParameters = otherParameterLink.getChildren();
843 for(
auto& parameter : physicsParameters)
845 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
849 auto comment = parameter.second.getNode(
"CommentDescription");
850 OUT << parameter.second.getNode(
"physicsParameterKey").getValue() <<
": "
851 << parameter.second.getNode(
"physicsParameterValue").getValue()
852 << (comment.isDefaultValue() ?
"" : (
"\t # " + comment.getValue()))
855 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
868 OUT <<
"process_name: "
869 << aggregatorNode.getNode(
870 "ARTDAQGlobalTableForProcessNameLink/processNameForAggregators")
875 __SS__ <<
"The field "
876 "ARTDAQGlobalTableForProcessNameLink/processNameForAggregators could "
878 <<
"Make sure the link is valid from aggregator '"
879 << aggregatorNode.getValue() <<
".'" << __E__;