00001 #include "otsdaq-core/ConfigurationPluginDataFormats/ARTDAQAggregatorConfiguration.h"
00002 #include "otsdaq-core/Macros/ConfigurationPluginMacros.h"
00003 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
00004 #include "otsdaq-core/ConfigurationPluginDataFormats/XDAQContextConfiguration.h"
00005
00006 #include <iostream>
00007 #include <fstream>
00008 #include <stdio.h>
00009 #include <sys/stat.h>
00010
00011 using namespace ots;
00012
00013
00014 #define ARTDAQ_FCL_PATH std::string(getenv("USER_DATA")) + "/"+ "ARTDAQConfigurations/"
00015 #define ARTDAQ_FILE_PREAMBLE "aggregator"
00016
00017
00018 #define OUT out << tabStr << commentStr
00019 #define PUSHTAB tabStr += "\t"
00020 #define POPTAB tabStr.resize(tabStr.size()-1)
00021 #define PUSHCOMMENT commentStr += "# "
00022 #define POPCOMMENT commentStr.resize(commentStr.size()-2)
00023
00024
00025
00026 ARTDAQAggregatorConfiguration::ARTDAQAggregatorConfiguration(void)
00027 : ConfigurationBase("ARTDAQAggregatorConfiguration")
00028 {
00030
00032
00033 }
00034
00035
00036 ARTDAQAggregatorConfiguration::~ARTDAQAggregatorConfiguration(void)
00037 {}
00038
00039
00040 void ARTDAQAggregatorConfiguration::init(ConfigurationManager* configManager)
00041 {
00042
00043 mkdir((ARTDAQ_FCL_PATH).c_str(), 0755);
00044
00045 __COUT__ << "*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << std::endl;
00046 __COUT__ << configManager->__SELF_NODE__ << std::endl;
00047
00048 const XDAQContextConfiguration *contextConfig = configManager->__GET_CONFIG__(XDAQContextConfiguration);
00049 std::vector<const XDAQContextConfiguration::XDAQContext *> aggContexts =
00050 contextConfig->getAggregatorContexts();
00051
00052
00053
00054 for (auto &aggContext : aggContexts)
00055 {
00056 ConfigurationTree aggConfigNode = contextConfig->getSupervisorConfigNode(configManager,
00057 aggContext->contextUID_, aggContext->applications_[0].applicationUID_);
00058
00059 __COUT__ << "Path for this aggregator config is " <<
00060 aggContext->contextUID_ << "/" <<
00061 aggContext->applications_[0].applicationUID_ << "/" <<
00062 aggConfigNode.getValueAsString() <<
00063 std::endl;
00064
00065 outputFHICL(configManager,aggConfigNode,
00066 contextConfig->getARTDAQAppRank(aggContext->contextUID_),
00067 contextConfig->getContextAddress(aggContext->contextUID_),
00068 contextConfig->getARTDAQDataPort(configManager,aggContext->contextUID_),
00069 contextConfig);
00070 }
00071 }
00072
00073
00074 std::string ARTDAQAggregatorConfiguration::getFHICLFilename(const ConfigurationTree &aggregatorNode)
00075 {
00076 __COUT__ << "ARTDAQ Aggregator UID: " << aggregatorNode.getValue() << std::endl;
00077 std::string filename = ARTDAQ_FCL_PATH + ARTDAQ_FILE_PREAMBLE + "-";
00078 std::string uid = aggregatorNode.getValue();
00079 for (unsigned int i = 0; i < uid.size(); ++i)
00080 if ((uid[i] >= 'a' && uid[i] <= 'z') ||
00081 (uid[i] >= 'A' && uid[i] <= 'Z') ||
00082 (uid[i] >= '0' && uid[i] <= '9'))
00083 filename += uid[i];
00084
00085 filename += ".fcl";
00086
00087 __COUT__ << "fcl: " << filename << std::endl;
00088
00089 return filename;
00090 }
00091
00092
00093 void ARTDAQAggregatorConfiguration::outputFHICL(ConfigurationManager *configManager,
00094 const ConfigurationTree &aggregatorNode,
00095 unsigned int selfRank, std::string selfHost, unsigned int selfPort,
00096 const XDAQContextConfiguration *contextConfig)
00097 {
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 std::string filename = getFHICLFilename(aggregatorNode);
00242
00243 __COUT__ << "selfRank = " << selfRank << std::endl;
00244
00245
00247
00248 std::fstream out;
00249
00250 std::string tabStr = "";
00251 std::string commentStr = "";
00252
00253 out.open(filename, std::fstream::out | std::fstream::trunc);
00254 if (out.fail())
00255 {
00256 __SS__ << "Failed to open ARTDAQ Aggregator fcl file: " << filename << std::endl;
00257 throw std::runtime_error(ss.str());
00258 }
00259
00260
00261 if (aggregatorNode.isDisconnected())
00262 {
00263
00264 OUT << "{}\n\n";
00265 out.close();
00266 return;
00267 }
00268
00269
00270
00271 auto services = aggregatorNode.getNode("servicesLink");
00272 if (!services.isDisconnected())
00273 {
00274 OUT << "services: {\n";
00275
00276
00277 PUSHTAB;
00278 OUT << "scheduler: {\n";
00279
00280 PUSHTAB;
00281 OUT << "fileMode: " << services.getNode("schedulerFileMode").getValue() <<
00282 "\n";
00283 OUT << "errorOnFailureToPut: " <<
00284 (services.getNode("schedulerErrorOnFailtureToPut").getValue<bool>() ? "true" : "false") <<
00285 "\n";
00286 POPTAB;
00287
00288 OUT << "}\n\n";
00289
00290
00291
00292 OUT << "NetMonTransportServiceInterface: {\n";
00293
00294 PUSHTAB;
00295 OUT << "service_provider: " <<
00296
00297 services.getNode("NetMonTrasportServiceInterfaceServiceProvider").getValue()
00298 << "\n";
00299
00300 POPTAB;
00301 OUT << "}\n\n";
00302
00303 POPTAB;
00304 OUT << "}\n\n";
00305
00306 }
00307
00308
00309
00310 auto daq = aggregatorNode.getNode("daqLink");
00311 if (!daq.isDisconnected())
00312 {
00313 OUT << "daq: {\n";
00314
00315
00316 PUSHTAB;
00317 OUT << "aggregator: {\n";
00318
00319 PUSHTAB;
00320 auto parametersLink = daq.getNode("daqAggregatorParametersLink");
00321 if (!parametersLink.isDisconnected())
00322 {
00323
00324 auto parameters = parametersLink.getChildren();
00325 for (auto ¶meter : parameters)
00326 {
00327 if (!parameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00328 PUSHCOMMENT;
00329
00330 auto comment = parameter.second.getNode("CommentDescription");
00331 OUT << parameter.second.getNode("daqParameterKey").getValue() <<
00332 ": " <<
00333 parameter.second.getNode("daqParameterValue").getValue()
00334 <<
00335 (comment.isDefaultValue() ? "" : ("\t # " + comment.getValue())) <<
00336 "\n";
00337
00338 if (!parameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00339 POPCOMMENT;
00340 }
00341 }
00342 OUT << "\n";
00343
00344 OUT << "sources: {\n";
00345
00346 PUSHTAB;
00347 auto sourcesGroup = daq.getNode("daqAggregatorSourcesLink");
00348 if (!sourcesGroup.isDisconnected())
00349 {
00350 try
00351 {
00352 auto sources = sourcesGroup.getChildren();
00353 for (auto &source : sources)
00354 {
00355 std::string sourceContextUID = source.second.getNode("sourceARTDAQContextLink").getValueAsString();
00356
00357 std::string host = contextConfig->getContextAddress(sourceContextUID);
00358 unsigned int sourceRank = contextConfig->getARTDAQAppRank(sourceContextUID);
00359 unsigned int port = contextConfig->getARTDAQDataPort(configManager, sourceContextUID);
00360
00361 OUT << source.second.getNode("sourceKey").getValue() <<
00362 ": {" <<
00363 " transferPluginType: " <<
00364 source.second.getNode("transferPluginType").getValue() <<
00365 " source_rank: " <<
00366 sourceRank <<
00367 " max_fragment_size_words: " <<
00368 source.second.getNode("ARTDAQGlobalConfigurationLink/maxFragmentSizeWords").getValue<unsigned int>() <<
00369 " host_map: [{rank: " << sourceRank << " host: \"" << host << "\" portOffset: " << std::to_string(port) << "}, " <<
00370 "{rank: " << selfRank << " host: \"" << selfHost << "\" portOffset: " << std::to_string(selfPort) << "}]" <<
00371 "}\n";
00372 }
00373 }
00374 catch (const std::runtime_error& e)
00375 {
00376 __SS__ << "Are the DAQ sources valid? Error occurred looking for Aggregator DAQ sources for UID '" <<
00377 aggregatorNode.getValue() << "': " << e.what() << std::endl;
00378 __COUT_ERR__ << ss.str() << std::endl;
00379 throw std::runtime_error(ss.str());
00380 }
00381 }
00382 POPTAB;
00383 OUT << "}\n\n";
00384
00385 POPTAB;
00386 OUT << "}\n\n";
00387
00388
00389 OUT << "metrics: {\n";
00390
00391 PUSHTAB;
00392 auto metricsGroup = daq.getNode("daqMetricsLink");
00393 if (!metricsGroup.isDisconnected())
00394 {
00395 auto metrics = metricsGroup.getChildren();
00396
00397 for (auto &metric : metrics)
00398 {
00399 if (!metric.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00400 PUSHCOMMENT;
00401
00402 OUT << metric.second.getNode("metricKey").getValue() <<
00403 ": {\n";
00404 PUSHTAB;
00405
00406 OUT << "metricPluginType: " <<
00407 metric.second.getNode("metricPluginType").getValue()
00408 << "\n";
00409 OUT << "level: " <<
00410 metric.second.getNode("metricLevel").getValue()
00411 << "\n";
00412
00413 auto metricParametersGroup = metric.second.getNode("metricParametersLink");
00414 if (!metricParametersGroup.isDisconnected())
00415 {
00416 auto metricParameters = metricParametersGroup.getChildren();
00417 for (auto &metricParameter : metricParameters)
00418 {
00419 if (!metricParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00420 PUSHCOMMENT;
00421
00422 auto comment = metricParameter.second.getNode("CommentDescription");
00423 OUT << metricParameter.second.getNode("metricParameterKey").getValue() <<
00424 ": " <<
00425 metricParameter.second.getNode("metricParameterValue").getValue()
00426 <<
00427 (comment.isDefaultValue() ? "" : ("\t # " + comment.getValue())) <<
00428 "\n";
00429
00430 if (!metricParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00431 POPCOMMENT;
00432
00433 }
00434 }
00435 POPTAB;
00436 OUT << "}\n\n";
00437
00438 if (!metric.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00439 POPCOMMENT;
00440 }
00441 }
00442 POPTAB;
00443 OUT << "}\n\n";
00444
00445 OUT << "destinations: {\n";
00446
00447 PUSHTAB;
00448
00449 auto destinationsGroup = daq.getNode("daqAggregatorDestinationsLink");
00450 if (!destinationsGroup.isDisconnected())
00451 {
00452 try
00453 {
00454 auto destinations = destinationsGroup.getChildren();
00455 for (auto &destination : destinations)
00456 {
00457 auto destinationContextUID = destination.second.getNode("destinationARTDAQContextLink").getValueAsString();
00458
00459 unsigned int destinationRank = contextConfig->getARTDAQAppRank(destinationContextUID);
00460 std::string host = contextConfig->getContextAddress(destinationContextUID);
00461 unsigned int port = contextConfig->getARTDAQDataPort(configManager,destinationContextUID);
00462
00463 OUT << destination.second.getNode("destinationKey").getValue() <<
00464 ": {" <<
00465 " transferPluginType: " <<
00466 destination.second.getNode("transferPluginType").getValue() <<
00467 " source_rank: " <<
00468 selfRank <<
00469 " destination_rank: " <<
00470 destinationRank <<
00471 " max_fragment_size_words: " <<
00472 destination.second.getNode("ARTDAQGlobalConfigurationLink/maxFragmentSizeWords").getValue<unsigned int>() <<
00473 " host_map: [{rank: " << destinationRank << " host: \"" << host << "\" portOffset: " << std::to_string(port) << "}, " <<
00474 "{rank: " << selfRank << " host: \"" << selfHost << "\" portOffset: " << std::to_string(selfPort) << "}]" <<
00475 "}\n";
00476 }
00477 }
00478 catch (const std::runtime_error& e)
00479 {
00480 __SS__ << "Are the DAQ destinations valid? Error occurred looking for Aggregator DAQ destinations for UID '" <<
00481 aggregatorNode.getValue() << "': " << e.what() << std::endl;
00482 __COUT_ERR__ << ss.str() << std::endl;
00483 throw std::runtime_error(ss.str());
00484 }
00485 }
00486 POPTAB;
00487 OUT << "}\n\n";
00488
00489 POPTAB;
00490 OUT << "}\n\n";
00491 }
00492
00493
00494
00495
00496 auto source = aggregatorNode.getNode("sourceLink");
00497 if (!source.isDisconnected())
00498 {
00499 OUT << "source: {\n";
00500
00501 PUSHTAB;
00502 OUT << "module_type: " << source.getNode("sourceModuleType").getValue() <<
00503 "\n";
00504 POPTAB;
00505 OUT << "}\n\n";
00506 }
00507
00508
00509
00510 auto outputs = aggregatorNode.getNode("outputsLink");
00511 if (!outputs.isDisconnected())
00512 {
00513 OUT << "outputs: {\n";
00514
00515 PUSHTAB;
00516
00517 auto outputPlugins = outputs.getChildren();
00518 for (auto &outputPlugin : outputPlugins)
00519 {
00520 if (!outputPlugin.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00521 PUSHCOMMENT;
00522
00523 OUT << outputPlugin.second.getNode("outputKey").getValue() <<
00524 ": {\n";
00525 PUSHTAB;
00526 OUT << "module_type: " <<
00527 outputPlugin.second.getNode("outputModuleType").getValue() <<
00528 "\n";
00529 auto pluginParameterLink = outputPlugin.second.getNode("outputModuleParameterLink");
00530 if (!pluginParameterLink.isDisconnected())
00531 {
00532 auto pluginParameters = pluginParameterLink.getChildren();
00533 for (auto &pluginParameter : pluginParameters)
00534 {
00535 if (!pluginParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00536 PUSHCOMMENT;
00537
00538 auto comment = pluginParameter.second.getNode("CommentDescription");
00539 OUT << pluginParameter.second.getNode("outputParameterKey").getValue() <<
00540 ": " <<
00541 pluginParameter.second.getNode("outputParameterValue").getValue()
00542 <<
00543 (comment.isDefaultValue() ? "" : ("\t # " + comment.getValue())) <<
00544 "\n";
00545
00546 if (!pluginParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00547 POPCOMMENT;
00548 }
00549 }
00550 POPTAB;
00551 OUT << "}\n\n";
00552
00553 if (!outputPlugin.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00554 POPCOMMENT;
00555 }
00556
00557 POPTAB;
00558 OUT << "}\n\n";
00559 }
00560
00561
00562
00563
00564 auto physics = aggregatorNode.getNode("physicsLink");
00565 if (!physics.isDisconnected())
00566 {
00568 OUT << "physics: {\n";
00569
00570 PUSHTAB;
00571
00572 auto analyzers = physics.getNode("analyzersLink");
00573 if (!analyzers.isDisconnected())
00574 {
00576 OUT << "analyzers: {\n";
00577
00578 PUSHTAB;
00579 auto modules = analyzers.getChildren();
00580 for (auto &module : modules)
00581 {
00582 if (!module.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00583 PUSHCOMMENT;
00584
00585 OUT << module.second.getNode("analyzerKey").getValue() <<
00586 ": {\n";
00587 PUSHTAB;
00588 OUT << "module_type: " <<
00589 module.second.getNode("analyzerModuleType").getValue() <<
00590 "\n";
00591 auto moduleParameterLink = module.second.getNode("analyzerModuleParameterLink");
00592 if (!moduleParameterLink.isDisconnected())
00593 {
00594 auto moduleParameters = moduleParameterLink.getChildren();
00595 for (auto &moduleParameter : moduleParameters)
00596 {
00597 if (!moduleParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00598 PUSHCOMMENT;
00599
00600 auto comment = moduleParameter.second.getNode("CommentDescription");
00601 OUT << moduleParameter.second.getNode("analyzerParameterKey").getValue() <<
00602 ": " <<
00603 moduleParameter.second.getNode("analyzerParameterValue").getValue()
00604 <<
00605 (comment.isDefaultValue() ? "" : ("\t # " + comment.getValue())) <<
00606 "\n";
00607
00608 if (!moduleParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00609 POPCOMMENT;
00610 }
00611 }
00612 POPTAB;
00613 OUT << "}\n\n";
00614
00615 if (!module.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00616 POPCOMMENT;
00617 }
00618 POPTAB;
00619 OUT << "}\n\n";
00620 }
00621
00622 auto producers = physics.getNode("producersLink");
00623 if (!producers.isDisconnected())
00624 {
00626 OUT << "producers: {\n";
00627
00628 PUSHTAB;
00629 auto modules = producers.getChildren();
00630 for (auto &module : modules)
00631 {
00632 if (!module.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00633 PUSHCOMMENT;
00634
00635 OUT << module.second.getNode("producerKey").getValue() <<
00636 ": {\n";
00637 PUSHTAB;
00638 OUT << "module_type: " <<
00639 module.second.getNode("producerModuleType").getValue() <<
00640 "\n";
00641 auto moduleParameterLink = module.second.getNode("producerModuleParameterLink");
00642 if (!moduleParameterLink.isDisconnected())
00643 {
00644 auto moduleParameters = moduleParameterLink.getChildren();
00645 for (auto &moduleParameter : moduleParameters)
00646 {
00647 if (!moduleParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00648 PUSHCOMMENT;
00649
00650 auto comment = moduleParameter.second.getNode("CommentDescription");
00651 OUT << moduleParameter.second.getNode("producerParameterKey").getValue() <<
00652 ":" <<
00653 moduleParameter.second.getNode("producerParameterValue").getValue()
00654 <<
00655 (comment.isDefaultValue() ? "" : ("\t # " + comment.getValue())) <<
00656 "\n";
00657
00658 if (!moduleParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00659 POPCOMMENT;
00660 }
00661 }
00662 POPTAB;
00663 OUT << "}\n\n";
00664
00665 if (!module.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00666 POPCOMMENT;
00667 }
00668 POPTAB;
00669 OUT << "}\n\n";
00670 }
00671
00672
00673 auto filters = physics.getNode("filtersLink");
00674 if (!filters.isDisconnected())
00675 {
00677 OUT << "filters: {\n";
00678
00679 PUSHTAB;
00680 auto modules = filters.getChildren();
00681 for (auto &module : modules)
00682 {
00683 if (!module.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00684 PUSHCOMMENT;
00685
00686 OUT << module.second.getNode("filterKey").getValue() <<
00687 ": {\n";
00688 PUSHTAB;
00689 OUT << "module_type: " <<
00690 module.second.getNode("filterModuleType").getValue() <<
00691 "\n";
00692 auto moduleParameterLink = module.second.getNode("filterModuleParameterLink");
00693 if (!moduleParameterLink.isDisconnected())
00694 {
00695 auto moduleParameters = moduleParameterLink.getChildren();
00696 for (auto &moduleParameter : moduleParameters)
00697 {
00698 if (!moduleParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00699 PUSHCOMMENT;
00700
00701 auto comment = moduleParameter.second.getNode("CommentDescription");
00702 OUT << moduleParameter.second.getNode("filterParameterKey").getValue()
00703 << ": " <<
00704 moduleParameter.second.getNode("filterParameterValue").getValue()
00705 <<
00706 (comment.isDefaultValue() ? "" : ("\t # " + comment.getValue())) <<
00707 "\n";
00708
00709 if (!moduleParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00710 POPCOMMENT;
00711 }
00712 }
00713 POPTAB;
00714 OUT << "}\n\n";
00715
00716 if (!module.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00717 POPCOMMENT;
00718 }
00719 POPTAB;
00720 OUT << "}\n\n";
00721 }
00722
00723
00724 auto otherParameterLink = physics.getNode("physicsOtherParametersLink");
00725 if (!otherParameterLink.isDisconnected())
00726 {
00728 auto physicsParameters = otherParameterLink.getChildren();
00729 for (auto ¶meter : physicsParameters)
00730 {
00731 if (!parameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00732 PUSHCOMMENT;
00733
00734 auto comment = parameter.second.getNode("CommentDescription");
00735 OUT << parameter.second.getNode("physicsParameterKey").getValue() <<
00736 ": " <<
00737 parameter.second.getNode("physicsParameterValue").getValue()
00738 <<
00739 (comment.isDefaultValue() ? "" : ("\t # " + comment.getValue())) <<
00740 "\n";
00741
00742 if (!parameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00743 POPCOMMENT;
00744 }
00745 }
00746 POPTAB;
00747 OUT << "}\n\n";
00748 }
00749
00750
00751
00752
00753 OUT << "process_name: " <<
00754 aggregatorNode.getNode("ARTDAQGlobalConfigurationForProcessNameLink/processNameForAggregators")
00755 << "\n";
00756
00757
00758
00759
00760 out.close();
00761 }
00762
00763 DEFINE_OTS_CONFIGURATION(ARTDAQAggregatorConfiguration)