1 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
2 #include "otsdaq-core/Macros/TablePluginMacros.h"
3 #include "otsdaq-core/TablePlugins/ARTDAQAggregatorTable.h"
4 #include "otsdaq-core/TablePlugins/XDAQContextTable.h"
13 #define ARTDAQ_FCL_PATH std::string(__ENV__("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) {}
39 bool isFirstAppInContext = configManager->isOwnerFirstAppInContext();
42 if(!isFirstAppInContext)
46 mkdir((ARTDAQ_FCL_PATH).c_str(), 0755);
48 __COUT__ <<
"*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << std::endl;
49 __COUT__ << configManager->__SELF_NODE__ << std::endl;
53 std::vector<const XDAQContextTable::XDAQContext*> aggContexts =
54 contextConfig->getAggregatorContexts();
58 for(
auto& aggContext : aggContexts)
62 aggContext->contextUID_,
63 aggContext->applications_[0].applicationUID_);
65 __COUT__ <<
"Path for this aggregator config is " << aggContext->contextUID_
66 <<
"/" << aggContext->applications_[0].applicationUID_ <<
"/"
67 << aggConfigNode.getValueAsString() << std::endl;
72 contextConfig->getARTDAQAppRank(aggContext->contextUID_),
73 contextConfig->getContextAddress(aggContext->contextUID_),
74 contextConfig->getARTDAQDataPort(configManager, aggContext->contextUID_),
80 std::string ARTDAQAggregatorTable::getFHICLFilename(
83 __COUT__ <<
"ARTDAQ Aggregator UID: " << aggregatorNode.getValue() << std::endl;
84 std::string filename = ARTDAQ_FCL_PATH + ARTDAQ_FILE_PREAMBLE +
"-";
85 std::string uid = aggregatorNode.getValue();
86 for(
unsigned int i = 0; i < uid.size(); ++i)
87 if((uid[i] >=
'a' && uid[i] <=
'z') || (uid[i] >=
'A' && uid[i] <=
'Z') ||
88 (uid[i] >=
'0' && uid[i] <=
'9'))
93 __COUT__ <<
"fcl: " << filename << std::endl;
101 unsigned int selfRank,
102 std::string selfHost,
103 unsigned int selfPort,
251 std::string filename = getFHICLFilename(aggregatorNode);
253 __COUT__ <<
"selfRank = " << selfRank << std::endl;
259 std::string tabStr =
"";
260 std::string commentStr =
"";
262 out.open(filename, std::fstream::out | std::fstream::trunc);
265 __SS__ <<
"Failed to open ARTDAQ Aggregator fcl file: " << filename << std::endl;
271 OUT <<
"###########################################################" << __E__;
273 OUT <<
"# artdaq aggregator fcl configuration file produced by otsdaq." << __E__;
274 OUT <<
"# Creation timestamp: " << StringMacros::getTimestampString() << __E__;
275 OUT <<
"# Original filename: " << filename << __E__;
276 OUT <<
"# otsdaq-ARTDAQ Aggregator UID: " << aggregatorNode.getValue() << __E__;
278 OUT <<
"###########################################################" << __E__;
283 auto services = aggregatorNode.getNode(
"servicesLink");
284 if(!services.isDisconnected())
286 OUT <<
"services: {\n";
290 OUT <<
"scheduler: {\n";
293 OUT <<
"fileMode: " << services.getNode(
"schedulerFileMode").getValue() <<
"\n";
294 OUT <<
"errorOnFailureToPut: "
295 << (services.getNode(
"schedulerErrorOnFailtureToPut").getValue<
bool>()
304 OUT <<
"NetMonTransportServiceInterface: {\n";
307 OUT <<
"service_provider: " <<
309 services.getNode(
"NetMonTrasportServiceInterfaceServiceProvider").getValue()
321 auto daq = aggregatorNode.getNode(
"daqLink");
322 if(!daq.isDisconnected())
328 OUT <<
"aggregator: {\n";
331 auto parametersLink = daq.getNode(
"daqAggregatorParametersLink");
332 if(!parametersLink.isDisconnected())
334 auto parameters = parametersLink.getChildren();
335 for(
auto& parameter : parameters)
337 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
342 parameter.second.getNode(TableViewColumnInfo::COL_NAME_COMMENT);
343 OUT << parameter.second.getNode(
"daqParameterKey").getValue() <<
": "
344 << parameter.second.getNode(
"daqParameterValue").getValue()
345 << (comment.isDefaultValue() ?
"" : (
"\t # " + comment.getValue()))
348 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
355 OUT <<
"sources: {\n";
358 auto sourcesGroup = daq.getNode(
"daqAggregatorSourcesLink");
359 if(!sourcesGroup.isDisconnected())
363 auto sources = sourcesGroup.getChildren();
364 for(
auto& source : sources)
366 std::string sourceContextUID =
367 source.second.getNode(
"sourceARTDAQContextLink")
370 unsigned int sourceRank = -1;
373 sourceRank = contextConfig->getARTDAQAppRank(sourceContextUID);
375 catch(
const std::runtime_error& e)
377 __MCOUT_WARN__(
"Are the DAQ sources valid? "
378 <<
"Perhaps a Context has been turned off? "
379 <<
"Skipping source due to an error looking for "
380 <<
"Aggregator DAQ source context '"
381 << sourceContextUID <<
"' for UID '"
382 << aggregatorNode.getValue() <<
"': " << e.what()
387 std::string host = contextConfig->getContextAddress(sourceContextUID);
389 contextConfig->getARTDAQDataPort(configManager, sourceContextUID);
392 OUT << source.second.getNode(
"sourceKey").getValue() <<
": {\n";
395 OUT <<
"transferPluginType: "
396 << source.second.getNode(
"transferPluginType").getValue()
399 OUT <<
"source_rank: " << sourceRank << __E__;
405 .getNode(
"ARTDAQGlobalTableLink/maxFragmentSizeBytes")
406 .getValue<
unsigned long long>();
407 OUT <<
"max_fragment_size_bytes: " << mfsb << __E__;
408 OUT <<
"max_fragment_size_words: " << (mfsb / 8) << __E__;
412 __SS__ <<
"The field ARTDAQGlobalTableLink/maxFragmentSizeBytes "
413 "could not be accessed. Make sure the link is valid."
418 OUT <<
"host_map: [\n";
422 OUT <<
"rank: " << sourceRank << __E__;
423 OUT <<
"host: \"" << host <<
"\"" << __E__;
424 OUT <<
"portOffset: " << std::to_string(port) << __E__;
429 OUT <<
"rank: " << selfRank << __E__;
430 OUT <<
"host: \"" << selfHost <<
"\"" << __E__;
431 OUT <<
"portOffset: " << std::to_string(selfPort) << __E__;
441 catch(
const std::runtime_error& e)
443 __SS__ <<
"Are the DAQ sources valid? Error occurred looking for "
444 "Aggregator DAQ sources for UID '"
445 << aggregatorNode.getValue() <<
"': " << e.what() << std::endl;
446 __COUT_ERR__ << ss.str() << std::endl;
456 OUT <<
"metrics: {\n";
459 auto metricsGroup = daq.getNode(
"daqMetricsLink");
460 if(!metricsGroup.isDisconnected())
462 auto metrics = metricsGroup.getChildren();
464 for(
auto& metric : metrics)
466 if(!metric.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
470 OUT << metric.second.getNode(
"metricKey").getValue() <<
": {\n";
473 OUT <<
"metricPluginType: "
474 << metric.second.getNode(
"metricPluginType").getValue() <<
"\n";
475 OUT <<
"level: " << metric.second.getNode(
"metricLevel").getValue()
478 auto metricParametersGroup =
479 metric.second.getNode(
"metricParametersLink");
480 if(!metricParametersGroup.isDisconnected())
482 auto metricParameters = metricParametersGroup.getChildren();
483 for(
auto& metricParameter : metricParameters)
485 if(!metricParameter.second
486 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
490 auto comment = metricParameter.second.getNode(
491 TableViewColumnInfo::COL_NAME_COMMENT);
492 OUT << metricParameter.second.getNode(
"metricParameterKey")
495 << metricParameter.second.getNode(
"metricParameterValue")
497 << (comment.isDefaultValue() ?
""
498 : (
"\t # " + comment.getValue()))
501 if(!metricParameter.second
502 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
510 if(!metric.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
518 OUT <<
"destinations: {\n";
522 auto destinationsGroup = daq.getNode(
"daqAggregatorDestinationsLink");
523 if(!destinationsGroup.isDisconnected())
527 auto destinations = destinationsGroup.getChildren();
528 for(
auto& destination : destinations)
530 auto destinationContextUID =
531 destination.second.getNode(
"destinationARTDAQContextLink")
534 unsigned int destinationRank = -1;
538 contextConfig->getARTDAQAppRank(destinationContextUID);
540 catch(
const std::runtime_error& e)
543 "Are the DAQ destinations valid? "
544 <<
"Perhaps a Context has been turned off? "
545 <<
"Skipping destination due to an error looking for "
546 <<
"Aggregator DAQ source context '" << destinationContextUID
547 <<
"' for UID '" << aggregatorNode.getValue()
548 <<
"': " << e.what() << __E__);
552 contextConfig->getContextAddress(destinationContextUID);
553 unsigned int port = contextConfig->getARTDAQDataPort(
554 configManager, destinationContextUID);
557 OUT << destination.second.getNode(
"destinationKey").getValue()
561 OUT <<
"transferPluginType: "
562 << destination.second.getNode(
"transferPluginType").getValue()
565 OUT <<
"source_rank: " << destinationRank << __E__;
571 .getNode(
"ARTDAQGlobalTableLink/maxFragmentSizeBytes")
572 .getValue<
unsigned long long>();
573 OUT <<
"max_fragment_size_bytes: " << mfsb << __E__;
574 OUT <<
"max_fragment_size_words: " << (mfsb / 8) << __E__;
578 __SS__ <<
"The field ARTDAQGlobalTableLink/maxFragmentSizeBytes "
579 "could not be accessed. Make sure the link is valid."
584 OUT <<
"host_map: [\n";
588 OUT <<
"rank: " << destinationRank << __E__;
589 OUT <<
"host: \"" << host <<
"\"" << __E__;
590 OUT <<
"portOffset: " << std::to_string(port) << __E__;
595 OUT <<
"rank: " << selfRank << __E__;
596 OUT <<
"host: \"" << selfHost <<
"\"" << __E__;
597 OUT <<
"portOffset: " << std::to_string(selfPort) << __E__;
607 catch(
const std::runtime_error& e)
609 __SS__ <<
"Are the DAQ destinations valid? Error occurred looking for "
610 "Aggregator DAQ destinations for UID '"
611 << aggregatorNode.getValue() <<
"': " << e.what() << std::endl;
612 __COUT_ERR__ << ss.str() << std::endl;
625 auto source = aggregatorNode.getNode(
"sourceLink");
626 if(!source.isDisconnected())
628 OUT <<
"source: {\n";
631 OUT <<
"module_type: " << source.getNode(
"sourceModuleType").getValue() <<
"\n";
638 auto outputs = aggregatorNode.getNode(
"outputsLink");
639 if(!outputs.isDisconnected())
641 OUT <<
"outputs: {\n";
645 auto outputPlugins = outputs.getChildren();
646 for(
auto& outputPlugin : outputPlugins)
648 if(!outputPlugin.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
652 OUT << outputPlugin.second.getNode(
"outputKey").getValue() <<
": {\n";
654 OUT <<
"module_type: "
655 << outputPlugin.second.getNode(
"outputModuleType").getValue() <<
"\n";
656 auto pluginParameterLink =
657 outputPlugin.second.getNode(
"outputModuleParameterLink");
658 if(!pluginParameterLink.isDisconnected())
660 auto pluginParameters = pluginParameterLink.getChildren();
661 for(
auto& pluginParameter : pluginParameters)
663 if(!pluginParameter.second
664 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
668 auto comment = pluginParameter.second.getNode(
669 TableViewColumnInfo::COL_NAME_COMMENT);
670 OUT << pluginParameter.second.getNode(
"outputParameterKey").getValue()
672 << pluginParameter.second.getNode(
"outputParameterValue")
674 << (comment.isDefaultValue() ?
""
675 : (
"\t # " + comment.getValue()))
678 if(!pluginParameter.second
679 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
687 if(!outputPlugin.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
698 auto physics = aggregatorNode.getNode(
"physicsLink");
699 if(!physics.isDisconnected())
702 OUT <<
"physics: {\n";
706 auto analyzers = physics.getNode(
"analyzersLink");
707 if(!analyzers.isDisconnected())
710 OUT <<
"analyzers: {\n";
713 auto modules = analyzers.getChildren();
714 for(
auto& module : modules)
716 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
720 OUT << module.second.getNode(
"analyzerKey").getValue() <<
": {\n";
722 OUT <<
"module_type: "
723 << module.second.getNode(
"analyzerModuleType").getValue() <<
"\n";
724 auto moduleParameterLink =
725 module.second.getNode(
"analyzerModuleParameterLink");
726 if(!moduleParameterLink.isDisconnected())
728 auto moduleParameters = moduleParameterLink.getChildren();
729 for(
auto& moduleParameter : moduleParameters)
731 if(!moduleParameter.second
732 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
736 auto comment = moduleParameter.second.getNode(
737 TableViewColumnInfo::COL_NAME_COMMENT);
738 OUT << moduleParameter.second.getNode(
"analyzerParameterKey")
741 << moduleParameter.second.getNode(
"analyzerParameterValue")
743 << (comment.isDefaultValue() ?
""
744 : (
"\t # " + comment.getValue()))
747 if(!moduleParameter.second
748 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
756 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
764 auto producers = physics.getNode(
"producersLink");
765 if(!producers.isDisconnected())
768 OUT <<
"producers: {\n";
771 auto modules = producers.getChildren();
772 for(
auto& module : modules)
774 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
778 OUT << module.second.getNode(
"producerKey").getValue() <<
": {\n";
780 OUT <<
"module_type: "
781 << module.second.getNode(
"producerModuleType").getValue() <<
"\n";
782 auto moduleParameterLink =
783 module.second.getNode(
"producerModuleParameterLink");
784 if(!moduleParameterLink.isDisconnected())
786 auto moduleParameters = moduleParameterLink.getChildren();
787 for(
auto& moduleParameter : moduleParameters)
789 if(!moduleParameter.second
790 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
794 auto comment = moduleParameter.second.getNode(
795 TableViewColumnInfo::COL_NAME_COMMENT);
796 OUT << moduleParameter.second.getNode(
"producerParameterKey")
799 << moduleParameter.second.getNode(
"producerParameterValue")
801 << (comment.isDefaultValue() ?
""
802 : (
"\t # " + comment.getValue()))
805 if(!moduleParameter.second
806 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
814 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
822 auto filters = physics.getNode(
"filtersLink");
823 if(!filters.isDisconnected())
826 OUT <<
"filters: {\n";
829 auto modules = filters.getChildren();
830 for(
auto& module : modules)
832 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
836 OUT << module.second.getNode(
"filterKey").getValue() <<
": {\n";
838 OUT <<
"module_type: "
839 << module.second.getNode(
"filterModuleType").getValue() <<
"\n";
840 auto moduleParameterLink =
841 module.second.getNode(
"filterModuleParameterLink");
842 if(!moduleParameterLink.isDisconnected())
844 auto moduleParameters = moduleParameterLink.getChildren();
845 for(
auto& moduleParameter : moduleParameters)
847 if(!moduleParameter.second
848 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
852 auto comment = moduleParameter.second.getNode(
853 TableViewColumnInfo::COL_NAME_COMMENT);
854 OUT << moduleParameter.second.getNode(
"filterParameterKey")
857 << moduleParameter.second.getNode(
"filterParameterValue")
859 << (comment.isDefaultValue() ?
""
860 : (
"\t # " + comment.getValue()))
863 if(!moduleParameter.second
864 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
872 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
880 auto otherParameterLink = physics.getNode(
"physicsOtherParametersLink");
881 if(!otherParameterLink.isDisconnected())
884 auto physicsParameters = otherParameterLink.getChildren();
885 for(
auto& parameter : physicsParameters)
887 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
892 parameter.second.getNode(TableViewColumnInfo::COL_NAME_COMMENT);
893 OUT << parameter.second.getNode(
"physicsParameterKey").getValue() <<
": "
894 << parameter.second.getNode(
"physicsParameterValue").getValue()
895 << (comment.isDefaultValue() ?
"" : (
"\t # " + comment.getValue()))
898 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
911 OUT <<
"process_name: "
912 << aggregatorNode.getNode(
913 "ARTDAQGlobalTableForProcessNameLink/processNameForAggregators")
918 __SS__ <<
"The field "
919 "ARTDAQGlobalTableForProcessNameLink/processNameForAggregators could "
921 <<
"Make sure the link is valid from aggregator '"
922 << aggregatorNode.getValue() <<
".'" << __E__;