1 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
2 #include "otsdaq-core/Macros/TablePluginMacros.h"
3 #include "otsdaq-core/TablePlugins/ARTDAQBuilderTable.h"
4 #include "otsdaq-core/TablePlugins/XDAQContextTable.h"
13 #define ARTDAQ_FCL_PATH std::string(__ENV__("USER_DATA")) + "/" + "ARTDAQConfigurations/"
14 #define ARTDAQ_FILE_PREAMBLE "builder"
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 ARTDAQBuilderTable::ARTDAQBuilderTable(
void) :
TableBase(
"ARTDAQBuilderTable")
32 ARTDAQBuilderTable::~ARTDAQBuilderTable(
void) {}
39 bool isFirstAppInContext = configManager->isOwnerFirstAppInContext();
42 if(!isFirstAppInContext)
46 mkdir((ARTDAQ_FCL_PATH).c_str(), 0755);
48 __COUT__ <<
"*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << __E__;
49 __COUT__ << configManager->__SELF_NODE__ << __E__;
54 std::vector<const XDAQContextTable::XDAQContext*> builderContexts =
55 contextConfig->getEventBuilderContexts();
59 for(
auto& builderContext : builderContexts)
63 builderContext->contextUID_,
64 builderContext->applications_[0].applicationUID_);
67 builderContext->contextUID_,
68 builderContext->applications_[0].applicationUID_);
70 __COUT__ <<
"Path for this aggregator config is " << builderContext->contextUID_
71 <<
"/" << builderContext->applications_[0].applicationUID_ <<
"/"
72 << builderConfigNode.getValueAsString() << __E__;
77 contextConfig->getARTDAQAppRank(builderContext->contextUID_),
78 contextConfig->getContextAddress(builderContext->contextUID_),
79 contextConfig->getARTDAQDataPort(configManager, builderContext->contextUID_),
85 std::string ARTDAQBuilderTable::getFHICLFilename(
const ConfigurationTree& builderNode)
87 __COUT__ <<
"ARTDAQ Builder UID: " << builderNode.getValue() << __E__;
88 std::string filename = ARTDAQ_FCL_PATH + ARTDAQ_FILE_PREAMBLE +
"-";
89 std::string uid = builderNode.getValue();
90 for(
unsigned int i = 0; i < uid.size(); ++i)
91 if((uid[i] >=
'a' && uid[i] <=
'z') || (uid[i] >=
'A' && uid[i] <=
'Z') ||
92 (uid[i] >=
'0' && uid[i] <=
'9'))
97 __COUT__ <<
"fcl: " << filename << __E__;
105 unsigned int selfRank,
106 std::string selfHost,
107 unsigned int selfPort,
230 std::string filename = getFHICLFilename(builderNode);
236 std::string tabStr =
"";
237 std::string commentStr =
"";
239 out.open(filename, std::fstream::out | std::fstream::trunc);
242 __SS__ <<
"Failed to open ARTDAQ Builder fcl file: " << filename << __E__;
248 OUT <<
"###########################################################" << __E__;
250 OUT <<
"# artdaq builder fcl configuration file produced by otsdaq." << __E__;
251 OUT <<
"# Creation timestamp: " << StringMacros::getTimestampString() << __E__;
252 OUT <<
"# Original filename: " << filename << __E__;
253 OUT <<
"# otsdaq-ARTDAQ Builder UID: " << builderNode.getValue() << __E__;
255 OUT <<
"###########################################################" << __E__;
259 if(builderNode.isDisconnected())
269 auto services = builderNode.getNode(
"servicesLink");
270 if(!services.isDisconnected())
272 OUT <<
"services: {\n";
276 OUT <<
"scheduler: {\n";
279 OUT <<
"fileMode: " << services.getNode(
"schedulerFileMode").getValue() <<
"\n";
280 OUT <<
"errorOnFailureToPut: "
281 << (services.getNode(
"schedulerErrorOnFailtureToPut").getValue<
bool>()
290 OUT <<
"NetMonTransportServiceInterface: {\n";
293 OUT <<
"service_provider: " <<
295 services.getNode(
"NetMonTrasportServiceInterfaceServiceProvider").getValue()
297 OUT <<
"destinations: {\n";
300 auto destinationsGroup =
301 services.getNode(
"NetMonTrasportServiceInterfaceDestinationsLink");
302 if(!destinationsGroup.isDisconnected())
306 auto destinations = destinationsGroup.getChildren();
307 for(
auto& destination : destinations)
309 auto destinationContextUID =
310 destination.second.getNode(
"destinationARTDAQContextLink")
313 unsigned int destinationRank = -1;
317 contextConfig->getARTDAQAppRank(destinationContextUID);
319 catch(
const std::runtime_error& e)
322 "Are the Transport Service destinations valid? "
323 <<
"Perhaps a Context has been turned off? "
324 <<
"Skipping destination due to an error looking for Event "
325 <<
"Builder DAQ source context '" << destinationContextUID
326 <<
"' for UID '" << builderNode.getValue()
327 <<
"': " << e.what() << __E__);
332 contextConfig->getContextAddress(destinationContextUID);
333 unsigned int port = contextConfig->getARTDAQDataPort(
334 configManager, destinationContextUID);
337 OUT << destination.second.getNode(
"destinationKey").getValue()
341 OUT <<
"transferPluginType: "
342 << destination.second.getNode(
"transferPluginType").getValue()
345 OUT <<
"destination_rank: " << destinationRank << __E__;
351 .getNode(
"ARTDAQGlobalTableLink/maxFragmentSizeBytes")
352 .getValue<
unsigned long long>();
353 OUT <<
"max_fragment_size_bytes: " << mfsb << __E__;
354 OUT <<
"max_fragment_size_words: " << (mfsb / 8) << __E__;
358 __SS__ <<
"The field ARTDAQGlobalTableLink/maxFragmentSizeBytes "
359 "could not be accessed. Make sure the link is valid."
364 OUT <<
"host_map: [\n";
368 OUT <<
"rank: " << destinationRank << __E__;
369 OUT <<
"host: \"" << host <<
"\"" << __E__;
370 OUT <<
"portOffset: " << std::to_string(port) << __E__;
375 OUT <<
"rank: " << selfRank << __E__;
376 OUT <<
"host: \"" << selfHost <<
"\"" << __E__;
377 OUT <<
"portOffset: " << std::to_string(selfPort) << __E__;
387 catch(
const std::runtime_error& e)
389 __SS__ <<
"Are the Net Monitor Transport Service destinations valid? "
390 "Error occurred looking for Event Builder transport service "
391 "destinations for UID '"
392 << builderNode.getValue() <<
"': " << e.what() << __E__;
402 auto otherParameterLink = services.getNode(
"ServicesParametersLink");
403 if(!otherParameterLink.isDisconnected())
406 auto servicesParameters = otherParameterLink.getChildren();
409 for(
auto& parameter : servicesParameters)
411 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
415 OUT << parameter.second.getNode(
"daqParameterKey").getValue() <<
": "
416 << parameter.second.getNode(
"daqParameterValue").getValue() <<
"\n";
418 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
432 auto daq = builderNode.getNode(
"daqLink");
433 if(!daq.isDisconnected())
440 OUT <<
"event_builder: {\n";
444 auto mfsb = daq.getNode(
"daqEventBuilderMaxFragmentSizeBytes")
445 .getValue<
unsigned long long>();
446 OUT <<
"max_fragment_size_bytes: " << mfsb << __E__;
447 OUT <<
"max_fragment_size_words: " << (mfsb / 8) << __E__;
448 OUT <<
"buffer_count: "
449 << daq.getNode(
"daqEventBuilderBufferCount").getValue<
unsigned long long>()
452 auto parametersLink = daq.getNode(
"daqEventBuilderParametersLink");
453 if(!parametersLink.isDisconnected())
455 auto parameters = parametersLink.getChildren();
456 for(
auto& parameter : parameters)
458 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
462 OUT << parameter.second.getNode(
"daqParameterKey").getValue() <<
": "
463 << parameter.second.getNode(
"daqParameterValue").getValue() <<
"\n";
465 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
472 OUT <<
"sources: {\n";
475 auto sourcesGroup = daq.getNode(
"daqEventBuilderSourcesLink");
476 if(!sourcesGroup.isDisconnected())
480 auto sources = sourcesGroup.getChildren();
481 for(
auto& source : sources)
483 auto sourceContextUID =
484 source.second.getNode(
"sourceARTDAQContextLink")
487 unsigned int sourceRank = -1;
490 sourceRank = contextConfig->getARTDAQAppRank(sourceContextUID);
492 catch(
const std::runtime_error& e)
495 "Are the DAQ sources valid? "
496 <<
"Perhaps a Context has been turned off? "
497 <<
"Skipping source due to an error looking for Event "
498 <<
"Builder DAQ source context '" << sourceContextUID
499 <<
"' for UID '" << builderNode.getValue()
500 <<
"': " << e.what() << __E__);
504 std::string host = contextConfig->getContextAddress(sourceContextUID);
506 contextConfig->getARTDAQDataPort(configManager, sourceContextUID);
509 OUT << source.second.getNode(
"sourceKey").getValue() <<
": {\n";
512 OUT <<
"transferPluginType: "
513 << source.second.getNode(
"transferPluginType").getValue()
516 OUT <<
"source_rank: " << sourceRank << __E__;
522 .getNode(
"ARTDAQGlobalTableLink/maxFragmentSizeBytes")
523 .getValue<
unsigned long long>();
524 OUT <<
"max_fragment_size_bytes: " << mfsb << __E__;
525 OUT <<
"max_fragment_size_words: " << (mfsb / 8) << __E__;
529 __SS__ <<
"The field ARTDAQGlobalTableLink/maxFragmentSizeBytes "
530 "could not be accessed. Make sure the link is valid."
535 OUT <<
"host_map: [\n";
539 OUT <<
"rank: " << sourceRank << __E__;
540 OUT <<
"host: \"" << host <<
"\"" << __E__;
541 OUT <<
"portOffset: " << std::to_string(port) << __E__;
546 OUT <<
"rank: " << selfRank << __E__;
547 OUT <<
"host: \"" << selfHost <<
"\"" << __E__;
548 OUT <<
"portOffset: " << std::to_string(selfPort) << __E__;
558 catch(
const std::runtime_error& e)
560 __SS__ <<
"Are the DAQ sources valid? Error occurred looking for Event "
561 "Builder DAQ sources for UID '"
562 << builderNode.getValue() <<
"': " << e.what() << __E__;
572 OUT <<
"metrics: {\n";
575 auto metricsGroup = daq.getNode(
"daqMetricsLink");
576 if(!metricsGroup.isDisconnected())
578 auto metrics = metricsGroup.getChildren();
580 for(
auto& metric : metrics)
582 if(!metric.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
586 OUT << metric.second.getNode(
"metricKey").getValue() <<
": {\n";
589 OUT <<
"metricPluginType: "
590 << metric.second.getNode(
"metricPluginType").getValue() <<
"\n";
591 OUT <<
"level: " << metric.second.getNode(
"metricLevel").getValue()
594 auto metricParametersGroup =
595 metric.second.getNode(
"metricParametersLink");
596 if(!metricParametersGroup.isDisconnected())
598 auto metricParameters = metricParametersGroup.getChildren();
599 for(
auto& metricParameter : metricParameters)
601 if(!metricParameter.second
602 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
606 OUT << metricParameter.second.getNode(
"metricParameterKey")
609 << metricParameter.second.getNode(
"metricParameterValue")
613 if(!metricParameter.second
614 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
622 if(!metric.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
636 auto outputs = builderNode.getNode(
"outputsLink");
637 if(!outputs.isDisconnected())
639 OUT <<
"outputs: {\n";
643 auto outputPlugins = outputs.getChildren();
644 for(
auto& outputPlugin : outputPlugins)
646 if(!outputPlugin.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
650 std::string moduleType =
651 outputPlugin.second.getNode(
"outputModuleType").getValue();
653 OUT << outputPlugin.second.getNode(
"outputKey").getValue() <<
": {\n";
656 OUT <<
"module_type: " << moduleType <<
"\n";
658 auto pluginParameterLink =
659 outputPlugin.second.getNode(
"outputModuleParameterLink");
660 if(!pluginParameterLink.isDisconnected())
662 auto pluginParameters = pluginParameterLink.getChildren();
663 for(
auto& pluginParameter : pluginParameters)
665 if(!pluginParameter.second
666 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
670 OUT << pluginParameter.second.getNode(
"outputParameterKey").getValue()
672 << pluginParameter.second.getNode(
"outputParameterValue")
676 if(!pluginParameter.second
677 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
684 auto destinationsGroup =
685 outputPlugin.second.getNode(
"outputModuleDestinationLink");
686 if(!destinationsGroup.isDisconnected())
690 if(moduleType.find(
"BinaryNetOuput") == std::string::npos)
692 __SS__ <<
"Illegal output module type '" << moduleType
693 <<
"' to include destinations. Only modules of type "
695 <<
"are allowed to have destinations." << __E__;
699 OUT <<
"destinations: {\n";
702 auto destinations = destinationsGroup.getChildren();
703 for(
auto& destination : destinations)
706 auto destinationContextUID =
707 destination.second.getNode(
"destinationARTDAQContextLink")
710 unsigned int destinationRank = -1;
713 destinationRank = contextConfig->getARTDAQAppRank(
714 destinationContextUID);
716 catch(
const std::runtime_error& e)
719 "Are the DAQ destinations valid? "
720 <<
"Perhaps a Context has been turned off? "
721 <<
"Skipping destination due to an error looking for "
723 <<
"Builder DAQ source context '"
724 << destinationContextUID <<
"' for UID '"
725 << builderNode.getValue() <<
"': " << e.what()
731 contextConfig->getContextAddress(destinationContextUID);
732 unsigned int port = contextConfig->getARTDAQDataPort(
733 configManager, destinationContextUID);
736 OUT << destination.second.getNode(
"destinationKey").getValue()
740 OUT <<
"transferPluginType: "
741 << destination.second.getNode(
"transferPluginType")
745 OUT <<
"destination_rank: " << destinationRank << __E__;
752 "ARTDAQGlobalTableLink/maxFragmentSizeBytes")
753 .getValue<
unsigned long long>();
754 OUT <<
"max_fragment_size_bytes: " << mfsb << __E__;
755 OUT <<
"max_fragment_size_words: " << (mfsb / 8) << __E__;
761 "ARTDAQGlobalTableLink/maxFragmentSizeBytes could "
762 "not be accessed. Make sure the link is valid."
767 OUT <<
"host_map: [\n";
771 OUT <<
"rank: " << destinationRank << __E__;
772 OUT <<
"host: \"" << host <<
"\"" << __E__;
773 OUT <<
"portOffset: " << std::to_string(port) << __E__;
778 OUT <<
"rank: " << selfRank << __E__;
779 OUT <<
"host: \"" << selfHost <<
"\"" << __E__;
780 OUT <<
"portOffset: " << std::to_string(selfPort) << __E__;
789 catch(
const std::runtime_error& e)
791 __SS__ <<
"Error encountered populating parameters for "
792 "output module destination '"
794 <<
"'... Please verify fields. Here was the error: "
795 << e.what() << __E__;
802 catch(
const std::runtime_error& e)
804 __SS__ <<
"Are the Output module destinations valid? "
805 "Error occurred looking for Event Builder output module "
806 "destinations for UID '"
807 << outputPlugin.second.getValue() <<
"': " << e.what()
816 if(!outputPlugin.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
827 auto physics = builderNode.getNode(
"physicsLink");
828 if(!physics.isDisconnected())
831 OUT <<
"physics: {\n";
835 auto analyzers = physics.getNode(
"analyzersLink");
836 if(!analyzers.isDisconnected())
839 OUT <<
"analyzers: {\n";
842 auto modules = analyzers.getChildren();
843 for(
auto& module : modules)
845 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
849 OUT << module.second.getNode(
"analyzerKey").getValue() <<
": {\n";
851 OUT <<
"module_type: "
852 << module.second.getNode(
"analyzerModuleType").getValue() <<
"\n";
853 auto moduleParameterLink =
854 module.second.getNode(
"analyzerModuleParameterLink");
855 if(!moduleParameterLink.isDisconnected())
857 auto moduleParameters = moduleParameterLink.getChildren();
858 for(
auto& moduleParameter : moduleParameters)
860 if(!moduleParameter.second
861 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
865 OUT << moduleParameter.second.getNode(
"analyzerParameterKey")
868 << moduleParameter.second.getNode(
"analyzerParameterValue")
872 if(!moduleParameter.second
873 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
881 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
889 auto producers = physics.getNode(
"producersLink");
890 if(!producers.isDisconnected())
893 OUT <<
"producers: {\n";
896 auto modules = producers.getChildren();
897 for(
auto& module : modules)
899 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
903 OUT << module.second.getNode(
"producerKey").getValue() <<
": {\n";
905 OUT <<
"module_type: "
906 << module.second.getNode(
"producerModuleType").getValue() <<
"\n";
907 auto moduleParameterLink =
908 module.second.getNode(
"producerModuleParameterLink");
909 if(!moduleParameterLink.isDisconnected())
911 auto moduleParameters = moduleParameterLink.getChildren();
912 for(
auto& moduleParameter : moduleParameters)
914 if(!moduleParameter.second
915 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
919 OUT << moduleParameter.second.getNode(
"producerParameterKey")
922 << moduleParameter.second.getNode(
"producerParameterValue")
926 if(!moduleParameter.second
927 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
935 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
943 auto filters = physics.getNode(
"filtersLink");
944 if(!filters.isDisconnected())
947 OUT <<
"filters: {\n";
950 auto modules = filters.getChildren();
951 for(
auto& module : modules)
953 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
957 OUT << module.second.getNode(
"filterKey").getValue() <<
": {\n";
959 OUT <<
"module_type: "
960 << module.second.getNode(
"filterModuleType").getValue() <<
"\n";
961 auto moduleParameterLink =
962 module.second.getNode(
"filterModuleParameterLink");
963 if(!moduleParameterLink.isDisconnected())
965 auto moduleParameters = moduleParameterLink.getChildren();
966 for(
auto& moduleParameter : moduleParameters)
968 if(!moduleParameter.second
969 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
973 OUT << moduleParameter.second.getNode(
"filterParameterKey")
976 << moduleParameter.second.getNode(
"filterParameterValue")
980 if(!moduleParameter.second
981 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
989 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
997 auto otherParameterLink = physics.getNode(
"physicsOtherParametersLink");
998 if(!otherParameterLink.isDisconnected())
1001 auto physicsParameters = otherParameterLink.getChildren();
1002 for(
auto& parameter : physicsParameters)
1004 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
1008 OUT << parameter.second.getNode(
"physicsParameterKey").getValue() <<
": "
1009 << parameter.second.getNode(
"physicsParameterValue").getValue()
1012 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
1023 auto source = builderNode.getNode(
"sourceLink");
1024 if(!source.isDisconnected())
1026 OUT <<
"source: {\n";
1029 OUT <<
"module_type: " << source.getNode(
"sourceModuleType").getValue() <<
"\n";
1030 OUT <<
"waiting_time: " << source.getNode(
"sourceWaitingTime").getValue() <<
"\n";
1031 OUT <<
"resume_after_timeout: "
1032 << (source.getNode(
"sourceResumeAfterTimeout").getValue<
bool>() ?
"true"
1041 OUT <<
"process_name: "
1042 << builderNode.getNode(
1043 "ARTDAQGlobalTableForProcessNameLink/processNameForBuilders")
1046 auto otherParameterLink = builderNode.getNode(
"addOnParametersLink");
1047 if(!otherParameterLink.isDisconnected())
1050 auto otherParameters = otherParameterLink.getChildren();
1053 for(
auto& parameter : otherParameters)
1055 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
1059 OUT << parameter.second.getNode(
"daqParameterKey").getValue() <<
": "
1060 << parameter.second.getNode(
"daqParameterValue").getValue() <<
"\n";
1062 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)