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(__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) {}
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 unsigned int sourceRank = -1;
364 sourceRank = contextConfig->getARTDAQAppRank(sourceContextUID);
366 catch(
const std::runtime_error& e)
368 __MCOUT_WARN__(
"Are the DAQ sources valid? "
369 <<
"Perhaps a Context has been turned off? "
370 <<
"Skipping source due to an error looking for "
371 <<
"Aggregator DAQ source context '"
372 << sourceContextUID <<
"' for UID '"
373 << aggregatorNode.getValue() <<
"': " << e.what()
378 std::string host = contextConfig->getContextAddress(sourceContextUID);
380 contextConfig->getARTDAQDataPort(configManager, sourceContextUID);
383 OUT << source.second.getNode(
"sourceKey").getValue() <<
": {\n";
386 OUT <<
"transferPluginType: "
387 << source.second.getNode(
"transferPluginType").getValue()
390 OUT <<
"source_rank: " << sourceRank << __E__;
396 .getNode(
"ARTDAQGlobalTableLink/maxFragmentSizeBytes")
397 .getValue<
unsigned long long>();
398 OUT <<
"max_fragment_size_bytes: " << mfsb << __E__;
399 OUT <<
"max_fragment_size_words: " << (mfsb / 8) << __E__;
403 __SS__ <<
"The field ARTDAQGlobalTableLink/maxFragmentSizeBytes "
404 "could not be accessed. Make sure the link is valid."
409 OUT <<
"host_map: [\n";
413 OUT <<
"rank: " << sourceRank << __E__;
414 OUT <<
"host: \"" << host <<
"\"" << __E__;
415 OUT <<
"portOffset: " << std::to_string(port) << __E__;
420 OUT <<
"rank: " << selfRank << __E__;
421 OUT <<
"host: \"" << selfHost <<
"\"" << __E__;
422 OUT <<
"portOffset: " << std::to_string(selfPort) << __E__;
432 catch(
const std::runtime_error& e)
434 __SS__ <<
"Are the DAQ sources valid? Error occurred looking for "
435 "Aggregator DAQ sources for UID '"
436 << aggregatorNode.getValue() <<
"': " << e.what() << std::endl;
437 __COUT_ERR__ << ss.str() << std::endl;
447 OUT <<
"metrics: {\n";
450 auto metricsGroup = daq.getNode(
"daqMetricsLink");
451 if(!metricsGroup.isDisconnected())
453 auto metrics = metricsGroup.getChildren();
455 for(
auto& metric : metrics)
457 if(!metric.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
461 OUT << metric.second.getNode(
"metricKey").getValue() <<
": {\n";
464 OUT <<
"metricPluginType: "
465 << metric.second.getNode(
"metricPluginType").getValue() <<
"\n";
466 OUT <<
"level: " << metric.second.getNode(
"metricLevel").getValue()
469 auto metricParametersGroup =
470 metric.second.getNode(
"metricParametersLink");
471 if(!metricParametersGroup.isDisconnected())
473 auto metricParameters = metricParametersGroup.getChildren();
474 for(
auto& metricParameter : metricParameters)
476 if(!metricParameter.second
477 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
482 metricParameter.second.getNode(
"CommentDescription");
483 OUT << metricParameter.second.getNode(
"metricParameterKey")
486 << metricParameter.second.getNode(
"metricParameterValue")
488 << (comment.isDefaultValue() ?
""
489 : (
"\t # " + comment.getValue()))
492 if(!metricParameter.second
493 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
501 if(!metric.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
509 OUT <<
"destinations: {\n";
513 auto destinationsGroup = daq.getNode(
"daqAggregatorDestinationsLink");
514 if(!destinationsGroup.isDisconnected())
518 auto destinations = destinationsGroup.getChildren();
519 for(
auto& destination : destinations)
521 auto destinationContextUID =
522 destination.second.getNode(
"destinationARTDAQContextLink")
525 unsigned int destinationRank = -1;
529 contextConfig->getARTDAQAppRank(destinationContextUID);
531 catch(
const std::runtime_error& e)
534 "Are the DAQ destinations valid? "
535 <<
"Perhaps a Context has been turned off? "
536 <<
"Skipping destination due to an error looking for "
537 <<
"Aggregator DAQ source context '" << destinationContextUID
538 <<
"' for UID '" << aggregatorNode.getValue()
539 <<
"': " << e.what() << __E__);
543 contextConfig->getContextAddress(destinationContextUID);
544 unsigned int port = contextConfig->getARTDAQDataPort(
545 configManager, destinationContextUID);
548 OUT << destination.second.getNode(
"destinationKey").getValue()
552 OUT <<
"transferPluginType: "
553 << destination.second.getNode(
"transferPluginType").getValue()
556 OUT <<
"source_rank: " << destinationRank << __E__;
562 .getNode(
"ARTDAQGlobalTableLink/maxFragmentSizeBytes")
563 .getValue<
unsigned long long>();
564 OUT <<
"max_fragment_size_bytes: " << mfsb << __E__;
565 OUT <<
"max_fragment_size_words: " << (mfsb / 8) << __E__;
569 __SS__ <<
"The field ARTDAQGlobalTableLink/maxFragmentSizeBytes "
570 "could not be accessed. Make sure the link is valid."
575 OUT <<
"host_map: [\n";
579 OUT <<
"rank: " << destinationRank << __E__;
580 OUT <<
"host: \"" << host <<
"\"" << __E__;
581 OUT <<
"portOffset: " << std::to_string(port) << __E__;
586 OUT <<
"rank: " << selfRank << __E__;
587 OUT <<
"host: \"" << selfHost <<
"\"" << __E__;
588 OUT <<
"portOffset: " << std::to_string(selfPort) << __E__;
598 catch(
const std::runtime_error& e)
600 __SS__ <<
"Are the DAQ destinations valid? Error occurred looking for "
601 "Aggregator DAQ destinations for UID '"
602 << aggregatorNode.getValue() <<
"': " << e.what() << std::endl;
603 __COUT_ERR__ << ss.str() << std::endl;
616 auto source = aggregatorNode.getNode(
"sourceLink");
617 if(!source.isDisconnected())
619 OUT <<
"source: {\n";
622 OUT <<
"module_type: " << source.getNode(
"sourceModuleType").getValue() <<
"\n";
629 auto outputs = aggregatorNode.getNode(
"outputsLink");
630 if(!outputs.isDisconnected())
632 OUT <<
"outputs: {\n";
636 auto outputPlugins = outputs.getChildren();
637 for(
auto& outputPlugin : outputPlugins)
639 if(!outputPlugin.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
643 OUT << outputPlugin.second.getNode(
"outputKey").getValue() <<
": {\n";
645 OUT <<
"module_type: "
646 << outputPlugin.second.getNode(
"outputModuleType").getValue() <<
"\n";
647 auto pluginParameterLink =
648 outputPlugin.second.getNode(
"outputModuleParameterLink");
649 if(!pluginParameterLink.isDisconnected())
651 auto pluginParameters = pluginParameterLink.getChildren();
652 for(
auto& pluginParameter : pluginParameters)
654 if(!pluginParameter.second
655 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
659 auto comment = pluginParameter.second.getNode(
"CommentDescription");
660 OUT << pluginParameter.second.getNode(
"outputParameterKey").getValue()
662 << pluginParameter.second.getNode(
"outputParameterValue")
664 << (comment.isDefaultValue() ?
""
665 : (
"\t # " + comment.getValue()))
668 if(!pluginParameter.second
669 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
677 if(!outputPlugin.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
688 auto physics = aggregatorNode.getNode(
"physicsLink");
689 if(!physics.isDisconnected())
692 OUT <<
"physics: {\n";
696 auto analyzers = physics.getNode(
"analyzersLink");
697 if(!analyzers.isDisconnected())
700 OUT <<
"analyzers: {\n";
703 auto modules = analyzers.getChildren();
704 for(
auto& module : modules)
706 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
710 OUT << module.second.getNode(
"analyzerKey").getValue() <<
": {\n";
712 OUT <<
"module_type: "
713 << module.second.getNode(
"analyzerModuleType").getValue() <<
"\n";
714 auto moduleParameterLink =
715 module.second.getNode(
"analyzerModuleParameterLink");
716 if(!moduleParameterLink.isDisconnected())
718 auto moduleParameters = moduleParameterLink.getChildren();
719 for(
auto& moduleParameter : moduleParameters)
721 if(!moduleParameter.second
722 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
727 moduleParameter.second.getNode(
"CommentDescription");
728 OUT << moduleParameter.second.getNode(
"analyzerParameterKey")
731 << moduleParameter.second.getNode(
"analyzerParameterValue")
733 << (comment.isDefaultValue() ?
""
734 : (
"\t # " + comment.getValue()))
737 if(!moduleParameter.second
738 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
746 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
754 auto producers = physics.getNode(
"producersLink");
755 if(!producers.isDisconnected())
758 OUT <<
"producers: {\n";
761 auto modules = producers.getChildren();
762 for(
auto& module : modules)
764 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
768 OUT << module.second.getNode(
"producerKey").getValue() <<
": {\n";
770 OUT <<
"module_type: "
771 << module.second.getNode(
"producerModuleType").getValue() <<
"\n";
772 auto moduleParameterLink =
773 module.second.getNode(
"producerModuleParameterLink");
774 if(!moduleParameterLink.isDisconnected())
776 auto moduleParameters = moduleParameterLink.getChildren();
777 for(
auto& moduleParameter : moduleParameters)
779 if(!moduleParameter.second
780 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
785 moduleParameter.second.getNode(
"CommentDescription");
786 OUT << moduleParameter.second.getNode(
"producerParameterKey")
789 << moduleParameter.second.getNode(
"producerParameterValue")
791 << (comment.isDefaultValue() ?
""
792 : (
"\t # " + comment.getValue()))
795 if(!moduleParameter.second
796 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
804 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
812 auto filters = physics.getNode(
"filtersLink");
813 if(!filters.isDisconnected())
816 OUT <<
"filters: {\n";
819 auto modules = filters.getChildren();
820 for(
auto& module : modules)
822 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
826 OUT << module.second.getNode(
"filterKey").getValue() <<
": {\n";
828 OUT <<
"module_type: "
829 << module.second.getNode(
"filterModuleType").getValue() <<
"\n";
830 auto moduleParameterLink =
831 module.second.getNode(
"filterModuleParameterLink");
832 if(!moduleParameterLink.isDisconnected())
834 auto moduleParameters = moduleParameterLink.getChildren();
835 for(
auto& moduleParameter : moduleParameters)
837 if(!moduleParameter.second
838 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
843 moduleParameter.second.getNode(
"CommentDescription");
844 OUT << moduleParameter.second.getNode(
"filterParameterKey")
847 << moduleParameter.second.getNode(
"filterParameterValue")
849 << (comment.isDefaultValue() ?
""
850 : (
"\t # " + comment.getValue()))
853 if(!moduleParameter.second
854 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
862 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
870 auto otherParameterLink = physics.getNode(
"physicsOtherParametersLink");
871 if(!otherParameterLink.isDisconnected())
874 auto physicsParameters = otherParameterLink.getChildren();
875 for(
auto& parameter : physicsParameters)
877 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
881 auto comment = parameter.second.getNode(
"CommentDescription");
882 OUT << parameter.second.getNode(
"physicsParameterKey").getValue() <<
": "
883 << parameter.second.getNode(
"physicsParameterValue").getValue()
884 << (comment.isDefaultValue() ?
"" : (
"\t # " + comment.getValue()))
887 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
900 OUT <<
"process_name: "
901 << aggregatorNode.getNode(
902 "ARTDAQGlobalTableForProcessNameLink/processNameForAggregators")
907 __SS__ <<
"The field "
908 "ARTDAQGlobalTableForProcessNameLink/processNameForAggregators could "
910 <<
"Make sure the link is valid from aggregator '"
911 << aggregatorNode.getValue() <<
".'" << __E__;