1 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
2 #include "otsdaq-core/Macros/TablePluginMacros.h"
3 #include "otsdaq-core/TablePluginDataFormats/ARTDAQBuilderTable.h"
4 #include "otsdaq-core/TablePluginDataFormats/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) {}
38 mkdir((ARTDAQ_FCL_PATH).c_str(), 0755);
40 __COUT__ <<
"*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << __E__;
41 __COUT__ << configManager->__SELF_NODE__ << __E__;
46 std::vector<const XDAQContextTable::XDAQContext*> builderContexts =
47 contextConfig->getEventBuilderContexts();
51 for(
auto& builderContext : builderContexts)
55 builderContext->contextUID_,
56 builderContext->applications_[0].applicationUID_);
59 builderContext->contextUID_,
60 builderContext->applications_[0].applicationUID_);
62 __COUT__ <<
"Path for this aggregator config is " << builderContext->contextUID_
63 <<
"/" << builderContext->applications_[0].applicationUID_ <<
"/"
64 << builderConfigNode.getValueAsString() << __E__;
69 contextConfig->getARTDAQAppRank(builderContext->contextUID_),
70 contextConfig->getContextAddress(builderContext->contextUID_),
71 contextConfig->getARTDAQDataPort(configManager, builderContext->contextUID_),
77 std::string ARTDAQBuilderTable::getFHICLFilename(
const ConfigurationTree& builderNode)
79 __COUT__ <<
"ARTDAQ Builder UID: " << builderNode.getValue() << __E__;
80 std::string filename = ARTDAQ_FCL_PATH + ARTDAQ_FILE_PREAMBLE +
"-";
81 std::string uid = builderNode.getValue();
82 for(
unsigned int i = 0; i < uid.size(); ++i)
83 if((uid[i] >=
'a' && uid[i] <=
'z') || (uid[i] >=
'A' && uid[i] <=
'Z') ||
84 (uid[i] >=
'0' && uid[i] <=
'9'))
89 __COUT__ <<
"fcl: " << filename << __E__;
97 unsigned int selfRank,
99 unsigned int selfPort,
222 std::string filename = getFHICLFilename(builderNode);
228 std::string tabStr =
"";
229 std::string commentStr =
"";
231 out.open(filename, std::fstream::out | std::fstream::trunc);
234 __SS__ <<
"Failed to open ARTDAQ Builder fcl file: " << filename << __E__;
240 OUT <<
"###########################################################" << __E__;
242 OUT <<
"# artdaq builder fcl configuration file produced by otsdaq." << __E__;
243 OUT <<
"# Creation timestamp: " << StringMacros::getTimestampString() << __E__;
244 OUT <<
"# Original filename: " << filename << __E__;
245 OUT <<
"# otsdaq-ARTDAQ Builder UID: " << builderNode.getValue() << __E__;
247 OUT <<
"###########################################################" << __E__;
251 if(builderNode.isDisconnected())
261 auto services = builderNode.getNode(
"servicesLink");
262 if(!services.isDisconnected())
264 OUT <<
"services: {\n";
268 OUT <<
"scheduler: {\n";
271 OUT <<
"fileMode: " << services.getNode(
"schedulerFileMode").getValue() <<
"\n";
272 OUT <<
"errorOnFailureToPut: "
273 << (services.getNode(
"schedulerErrorOnFailtureToPut").getValue<
bool>()
282 OUT <<
"NetMonTransportServiceInterface: {\n";
285 OUT <<
"service_provider: " <<
287 services.getNode(
"NetMonTrasportServiceInterfaceServiceProvider").getValue()
289 OUT <<
"destinations: {\n";
292 auto destinationsGroup =
293 services.getNode(
"NetMonTrasportServiceInterfaceDestinationsLink");
294 if(!destinationsGroup.isDisconnected())
298 auto destinations = destinationsGroup.getChildren();
299 for(
auto& destination : destinations)
301 auto destinationContextUID =
302 destination.second.getNode(
"destinationARTDAQContextLink")
305 unsigned int destinationRank = -1;
309 contextConfig->getARTDAQAppRank(destinationContextUID);
311 catch(
const std::runtime_error& e)
314 "Are the Transport Service destinations valid? "
315 <<
"Perhaps a Context has been turned off? "
316 <<
"Skipping destination due to an error looking for Event "
317 <<
"Builder DAQ source context '" << destinationContextUID
318 <<
"' for UID '" << builderNode.getValue()
319 <<
"': " << e.what() << __E__);
324 contextConfig->getContextAddress(destinationContextUID);
325 unsigned int port = contextConfig->getARTDAQDataPort(
326 configManager, destinationContextUID);
329 OUT << destination.second.getNode(
"destinationKey").getValue()
333 OUT <<
"transferPluginType: "
334 << destination.second.getNode(
"transferPluginType").getValue()
337 OUT <<
"destination_rank: " << destinationRank << __E__;
343 .getNode(
"ARTDAQGlobalTableLink/maxFragmentSizeBytes")
344 .getValue<
unsigned long long>();
345 OUT <<
"max_fragment_size_bytes: " << mfsb << __E__;
346 OUT <<
"max_fragment_size_words: " << (mfsb / 8) << __E__;
350 __SS__ <<
"The field ARTDAQGlobalTableLink/maxFragmentSizeBytes "
351 "could not be accessed. Make sure the link is valid."
356 OUT <<
"host_map: [\n";
360 OUT <<
"rank: " << destinationRank << __E__;
361 OUT <<
"host: \"" << host <<
"\"" << __E__;
362 OUT <<
"portOffset: " << std::to_string(port) << __E__;
367 OUT <<
"rank: " << selfRank << __E__;
368 OUT <<
"host: \"" << selfHost <<
"\"" << __E__;
369 OUT <<
"portOffset: " << std::to_string(selfPort) << __E__;
379 catch(
const std::runtime_error& e)
381 __SS__ <<
"Are the Net Monitor Transport Service destinations valid? "
382 "Error occurred looking for Event Builder transport service "
383 "destinations for UID '"
384 << builderNode.getValue() <<
"': " << e.what() << __E__;
394 auto otherParameterLink = services.getNode(
"ServicesParametersLink");
395 if(!otherParameterLink.isDisconnected())
398 auto servicesParameters = otherParameterLink.getChildren();
401 for(
auto& parameter : servicesParameters)
403 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
407 OUT << parameter.second.getNode(
"daqParameterKey").getValue() <<
": "
408 << parameter.second.getNode(
"daqParameterValue").getValue() <<
"\n";
410 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
424 auto daq = builderNode.getNode(
"daqLink");
425 if(!daq.isDisconnected())
432 OUT <<
"event_builder: {\n";
436 auto mfsb = daq.getNode(
"daqEventBuilderMaxFragmentSizeBytes")
437 .getValue<
unsigned long long>();
438 OUT <<
"max_fragment_size_bytes: " << mfsb << __E__;
439 OUT <<
"max_fragment_size_words: " << (mfsb / 8) << __E__;
440 OUT <<
"buffer_count: "
441 << daq.getNode(
"daqEventBuilderBufferCount").getValue<
unsigned long long>()
444 auto parametersLink = daq.getNode(
"daqEventBuilderParametersLink");
445 if(!parametersLink.isDisconnected())
447 auto parameters = parametersLink.getChildren();
448 for(
auto& parameter : parameters)
450 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
454 OUT << parameter.second.getNode(
"daqParameterKey").getValue() <<
": "
455 << parameter.second.getNode(
"daqParameterValue").getValue() <<
"\n";
457 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
464 OUT <<
"sources: {\n";
467 auto sourcesGroup = daq.getNode(
"daqEventBuilderSourcesLink");
468 if(!sourcesGroup.isDisconnected())
472 auto sources = sourcesGroup.getChildren();
473 for(
auto& source : sources)
475 auto sourceContextUID =
476 source.second.getNode(
"sourceARTDAQContextLink")
479 unsigned int sourceRank = -1;
482 sourceRank = contextConfig->getARTDAQAppRank(sourceContextUID);
484 catch(
const std::runtime_error& e)
487 "Are the DAQ sources valid? "
488 <<
"Perhaps a Context has been turned off? "
489 <<
"Skipping source due to an error looking for Event "
490 <<
"Builder DAQ source context '" << sourceContextUID
491 <<
"' for UID '" << builderNode.getValue()
492 <<
"': " << e.what() << __E__);
496 std::string host = contextConfig->getContextAddress(sourceContextUID);
498 contextConfig->getARTDAQDataPort(configManager, sourceContextUID);
501 OUT << source.second.getNode(
"sourceKey").getValue() <<
": {\n";
504 OUT <<
"transferPluginType: "
505 << source.second.getNode(
"transferPluginType").getValue()
508 OUT <<
"source_rank: " << sourceRank << __E__;
514 .getNode(
"ARTDAQGlobalTableLink/maxFragmentSizeBytes")
515 .getValue<
unsigned long long>();
516 OUT <<
"max_fragment_size_bytes: " << mfsb << __E__;
517 OUT <<
"max_fragment_size_words: " << (mfsb / 8) << __E__;
521 __SS__ <<
"The field ARTDAQGlobalTableLink/maxFragmentSizeBytes "
522 "could not be accessed. Make sure the link is valid."
527 OUT <<
"host_map: [\n";
531 OUT <<
"rank: " << sourceRank << __E__;
532 OUT <<
"host: \"" << host <<
"\"" << __E__;
533 OUT <<
"portOffset: " << std::to_string(port) << __E__;
538 OUT <<
"rank: " << selfRank << __E__;
539 OUT <<
"host: \"" << selfHost <<
"\"" << __E__;
540 OUT <<
"portOffset: " << std::to_string(selfPort) << __E__;
550 catch(
const std::runtime_error& e)
552 __SS__ <<
"Are the DAQ sources valid? Error occurred looking for Event "
553 "Builder DAQ sources for UID '"
554 << builderNode.getValue() <<
"': " << e.what() << __E__;
564 OUT <<
"metrics: {\n";
567 auto metricsGroup = daq.getNode(
"daqMetricsLink");
568 if(!metricsGroup.isDisconnected())
570 auto metrics = metricsGroup.getChildren();
572 for(
auto& metric : metrics)
574 if(!metric.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
578 OUT << metric.second.getNode(
"metricKey").getValue() <<
": {\n";
581 OUT <<
"metricPluginType: "
582 << metric.second.getNode(
"metricPluginType").getValue() <<
"\n";
583 OUT <<
"level: " << metric.second.getNode(
"metricLevel").getValue()
586 auto metricParametersGroup =
587 metric.second.getNode(
"metricParametersLink");
588 if(!metricParametersGroup.isDisconnected())
590 auto metricParameters = metricParametersGroup.getChildren();
591 for(
auto& metricParameter : metricParameters)
593 if(!metricParameter.second
594 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
598 OUT << metricParameter.second.getNode(
"metricParameterKey")
601 << metricParameter.second.getNode(
"metricParameterValue")
605 if(!metricParameter.second
606 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
614 if(!metric.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
628 auto outputs = builderNode.getNode(
"outputsLink");
629 if(!outputs.isDisconnected())
631 OUT <<
"outputs: {\n";
635 auto outputPlugins = outputs.getChildren();
636 for(
auto& outputPlugin : outputPlugins)
638 if(!outputPlugin.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
642 std::string moduleType =
643 outputPlugin.second.getNode(
"outputModuleType").getValue();
645 OUT << outputPlugin.second.getNode(
"outputKey").getValue() <<
": {\n";
648 OUT <<
"module_type: " << moduleType <<
"\n";
650 auto pluginParameterLink =
651 outputPlugin.second.getNode(
"outputModuleParameterLink");
652 if(!pluginParameterLink.isDisconnected())
654 auto pluginParameters = pluginParameterLink.getChildren();
655 for(
auto& pluginParameter : pluginParameters)
657 if(!pluginParameter.second
658 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
662 OUT << pluginParameter.second.getNode(
"outputParameterKey").getValue()
664 << pluginParameter.second.getNode(
"outputParameterValue")
668 if(!pluginParameter.second
669 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
676 auto destinationsGroup =
677 outputPlugin.second.getNode(
"outputModuleDestinationLink");
678 if(!destinationsGroup.isDisconnected())
682 if(moduleType.find(
"BinaryNetOuput") == std::string::npos)
684 __SS__ <<
"Illegal output module type '" << moduleType
685 <<
"' to include destinations. Only modules of type "
687 <<
"are allowed to have destinations." << __E__;
691 OUT <<
"destinations: {\n";
694 auto destinations = destinationsGroup.getChildren();
695 for(
auto& destination : destinations)
698 auto destinationContextUID =
699 destination.second.getNode(
"destinationARTDAQContextLink")
702 unsigned int destinationRank = -1;
705 destinationRank = contextConfig->getARTDAQAppRank(
706 destinationContextUID);
708 catch(
const std::runtime_error& e)
711 "Are the DAQ destinations valid? "
712 <<
"Perhaps a Context has been turned off? "
713 <<
"Skipping destination due to an error looking for "
715 <<
"Builder DAQ source context '"
716 << destinationContextUID <<
"' for UID '"
717 << builderNode.getValue() <<
"': " << e.what()
723 contextConfig->getContextAddress(destinationContextUID);
724 unsigned int port = contextConfig->getARTDAQDataPort(
725 configManager, destinationContextUID);
728 OUT << destination.second.getNode(
"destinationKey").getValue()
732 OUT <<
"transferPluginType: "
733 << destination.second.getNode(
"transferPluginType")
737 OUT <<
"destination_rank: " << destinationRank << __E__;
744 "ARTDAQGlobalTableLink/maxFragmentSizeBytes")
745 .getValue<
unsigned long long>();
746 OUT <<
"max_fragment_size_bytes: " << mfsb << __E__;
747 OUT <<
"max_fragment_size_words: " << (mfsb / 8) << __E__;
753 "ARTDAQGlobalTableLink/maxFragmentSizeBytes could "
754 "not be accessed. Make sure the link is valid."
759 OUT <<
"host_map: [\n";
763 OUT <<
"rank: " << destinationRank << __E__;
764 OUT <<
"host: \"" << host <<
"\"" << __E__;
765 OUT <<
"portOffset: " << std::to_string(port) << __E__;
770 OUT <<
"rank: " << selfRank << __E__;
771 OUT <<
"host: \"" << selfHost <<
"\"" << __E__;
772 OUT <<
"portOffset: " << std::to_string(selfPort) << __E__;
781 catch(
const std::runtime_error& e)
783 __SS__ <<
"Error encountered populating parameters for "
784 "output module destination '"
786 <<
"'... Please verify fields. Here was the error: "
787 << e.what() << __E__;
794 catch(
const std::runtime_error& e)
796 __SS__ <<
"Are the Output module destinations valid? "
797 "Error occurred looking for Event Builder output module "
798 "destinations for UID '"
799 << outputPlugin.second.getValue() <<
"': " << e.what()
808 if(!outputPlugin.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
819 auto physics = builderNode.getNode(
"physicsLink");
820 if(!physics.isDisconnected())
823 OUT <<
"physics: {\n";
827 auto analyzers = physics.getNode(
"analyzersLink");
828 if(!analyzers.isDisconnected())
831 OUT <<
"analyzers: {\n";
834 auto modules = analyzers.getChildren();
835 for(
auto& module : modules)
837 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
841 OUT << module.second.getNode(
"analyzerKey").getValue() <<
": {\n";
843 OUT <<
"module_type: "
844 << module.second.getNode(
"analyzerModuleType").getValue() <<
"\n";
845 auto moduleParameterLink =
846 module.second.getNode(
"analyzerModuleParameterLink");
847 if(!moduleParameterLink.isDisconnected())
849 auto moduleParameters = moduleParameterLink.getChildren();
850 for(
auto& moduleParameter : moduleParameters)
852 if(!moduleParameter.second
853 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
857 OUT << moduleParameter.second.getNode(
"analyzerParameterKey")
860 << moduleParameter.second.getNode(
"analyzerParameterValue")
864 if(!moduleParameter.second
865 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
873 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
881 auto producers = physics.getNode(
"producersLink");
882 if(!producers.isDisconnected())
885 OUT <<
"producers: {\n";
888 auto modules = producers.getChildren();
889 for(
auto& module : modules)
891 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
895 OUT << module.second.getNode(
"producerKey").getValue() <<
": {\n";
897 OUT <<
"module_type: "
898 << module.second.getNode(
"producerModuleType").getValue() <<
"\n";
899 auto moduleParameterLink =
900 module.second.getNode(
"producerModuleParameterLink");
901 if(!moduleParameterLink.isDisconnected())
903 auto moduleParameters = moduleParameterLink.getChildren();
904 for(
auto& moduleParameter : moduleParameters)
906 if(!moduleParameter.second
907 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
911 OUT << moduleParameter.second.getNode(
"producerParameterKey")
914 << moduleParameter.second.getNode(
"producerParameterValue")
918 if(!moduleParameter.second
919 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
927 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
935 auto filters = physics.getNode(
"filtersLink");
936 if(!filters.isDisconnected())
939 OUT <<
"filters: {\n";
942 auto modules = filters.getChildren();
943 for(
auto& module : modules)
945 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
949 OUT << module.second.getNode(
"filterKey").getValue() <<
": {\n";
951 OUT <<
"module_type: "
952 << module.second.getNode(
"filterModuleType").getValue() <<
"\n";
953 auto moduleParameterLink =
954 module.second.getNode(
"filterModuleParameterLink");
955 if(!moduleParameterLink.isDisconnected())
957 auto moduleParameters = moduleParameterLink.getChildren();
958 for(
auto& moduleParameter : moduleParameters)
960 if(!moduleParameter.second
961 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
965 OUT << moduleParameter.second.getNode(
"filterParameterKey")
968 << moduleParameter.second.getNode(
"filterParameterValue")
972 if(!moduleParameter.second
973 .getNode(TableViewColumnInfo::COL_NAME_STATUS)
981 if(!module.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
989 auto otherParameterLink = physics.getNode(
"physicsOtherParametersLink");
990 if(!otherParameterLink.isDisconnected())
993 auto physicsParameters = otherParameterLink.getChildren();
994 for(
auto& parameter : physicsParameters)
996 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
1000 OUT << parameter.second.getNode(
"physicsParameterKey").getValue() <<
": "
1001 << parameter.second.getNode(
"physicsParameterValue").getValue()
1004 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
1015 auto source = builderNode.getNode(
"sourceLink");
1016 if(!source.isDisconnected())
1018 OUT <<
"source: {\n";
1021 OUT <<
"module_type: " << source.getNode(
"sourceModuleType").getValue() <<
"\n";
1022 OUT <<
"waiting_time: " << source.getNode(
"sourceWaitingTime").getValue() <<
"\n";
1023 OUT <<
"resume_after_timeout: "
1024 << (source.getNode(
"sourceResumeAfterTimeout").getValue<
bool>() ?
"true"
1033 OUT <<
"process_name: "
1034 << builderNode.getNode(
1035 "ARTDAQGlobalTableForProcessNameLink/processNameForBuilders")
1038 auto otherParameterLink = builderNode.getNode(
"addOnParametersLink");
1039 if(!otherParameterLink.isDisconnected())
1042 auto otherParameters = otherParameterLink.getChildren();
1045 for(
auto& parameter : otherParameters)
1047 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)
1051 OUT << parameter.second.getNode(
"daqParameterKey").getValue() <<
": "
1052 << parameter.second.getNode(
"daqParameterValue").getValue() <<
"\n";
1054 if(!parameter.second.getNode(TableViewColumnInfo::COL_NAME_STATUS)