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 __MOUT__ << "*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << std::endl;
00046 __MOUT__ << 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 auto aggConfigNode = contextConfig->getSupervisorConfigNode(configManager,
00057 aggContext->contextUID_, aggContext->applications_[0].applicationUID_);
00058
00059 __MOUT__ << "Path for this aggregator config is " <<
00060 aggContext->contextUID_ << "/" <<
00061 aggContext->applications_[0].applicationUID_ << "/" <<
00062 aggConfigNode.getValueAsString() <<
00063 std::endl;
00064
00065 outputFHICL(aggConfigNode,
00066 contextConfig->getARTDAQAppRank(aggContext->contextUID_),
00067 contextConfig);
00068 }
00069 }
00070
00071
00072 std::string ARTDAQAggregatorConfiguration::getFHICLFilename(const ConfigurationTree &aggregatorNode)
00073 {
00074 __MOUT__ << "ARTDAQ Aggregator UID: " << aggregatorNode.getValue() << std::endl;
00075 std::string filename = ARTDAQ_FCL_PATH + ARTDAQ_FILE_PREAMBLE + "-";
00076 std::string uid = aggregatorNode.getValue();
00077 for(unsigned int i=0;i<uid.size();++i)
00078 if((uid[i] >= 'a' && uid[i] <= 'z') ||
00079 (uid[i] >= 'A' && uid[i] <= 'Z') ||
00080 (uid[i] >= '0' && uid[i] <= '9'))
00081 filename += uid[i];
00082
00083 filename += ".fcl";
00084
00085 __MOUT__ << "fcl: " << filename << std::endl;
00086
00087 return filename;
00088 }
00089
00090
00091 void ARTDAQAggregatorConfiguration::outputFHICL(const ConfigurationTree &aggregatorNode,
00092 unsigned int selfRank,
00093 const XDAQContextConfiguration *contextConfig)
00094 {
00095
00096
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 std::string filename = getFHICLFilename(aggregatorNode);
00239
00240 __MOUT__ << "selfRank = " << selfRank << std::endl;
00241
00243
00244 std::fstream out;
00245
00246 std::string tabStr = "";
00247 std::string commentStr = "";
00248
00249 out.open(filename, std::fstream::out | std::fstream::trunc);
00250 if(out.fail())
00251 {
00252 __SS__ << "Failed to open ARTDAQ Builder fcl file: " << filename << std::endl;
00253 throw std::runtime_error(ss.str());
00254 }
00255
00256
00257
00258 auto services = aggregatorNode.getNode("servicesLink");
00259 if(!services.isDisconnected())
00260 {
00261 OUT << "services: {\n";
00262
00263
00264 PUSHTAB;
00265 OUT << "scheduler: {\n";
00266
00267 PUSHTAB;
00268 OUT << "fileMode: " << services.getNode("schedulerFileMode").getValue() <<
00269 "\n";
00270 OUT << "errorOnFailureToPut: " <<
00271 (services.getNode("schedulerErrorOnFailtureToPut").getValue<bool>()?"true":"false") <<
00272 "\n";
00273 POPTAB;
00274
00275 OUT << "}\n\n";
00276
00277
00278
00279 OUT << "NetMonTransportServiceInterface: {\n";
00280
00281 PUSHTAB;
00282 OUT << "service_provider: " <<
00283
00284 services.getNode("NetMonTrasportServiceInterfaceServiceProvider").getValue()
00285 << "\n";
00286
00287 POPTAB;
00288 OUT << "}\n\n";
00289
00290 POPTAB;
00291 OUT << "}\n\n";
00292
00293 }
00294
00295
00296
00297 auto daq = aggregatorNode.getNode("daqLink");
00298 if(!daq.isDisconnected())
00299 {
00300 OUT << "daq: {\n";
00301
00302
00303 PUSHTAB;
00304 OUT << "aggregator: {\n";
00305
00306 PUSHTAB;
00307 auto parametersLink = daq.getNode("daqAggregatorParametersLink");
00308 if(!parametersLink.isDisconnected())
00309 {
00310
00311 auto parameters = parametersLink.getChildren();
00312 for(auto ¶meter:parameters)
00313 {
00314 if(!parameter.second.getNode("Enabled").getValue<bool>())
00315 PUSHCOMMENT;
00316
00317 auto comment = parameter.second.getNode("CommentDescription");
00318 OUT << parameter.second.getNode("daqParameterKey").getValue() <<
00319 ": " <<
00320 parameter.second.getNode("daqParameterValue").getValue()
00321 <<
00322 (comment.isDefaultValue()?"":("\t # " + comment.getValue())) <<
00323 "\n";
00324
00325 if(!parameter.second.getNode("Enabled").getValue<bool>())
00326 POPCOMMENT;
00327 }
00328 }
00329 OUT << "\n";
00330
00331 OUT << "sources: {\n";
00332
00333 PUSHTAB;
00334 auto sourcesGroup = daq.getNode("daqAggregatorSourcesLink");
00335 if(!sourcesGroup.isDisconnected())
00336 {
00337 auto sources = sourcesGroup.getChildren();
00338 for(auto &source:sources)
00339 {
00340 unsigned int sourceRank =
00341 contextConfig->getARTDAQAppRank(
00342 source.second.getNode("sourceARTDAQContextLink").getValue());
00343
00344 OUT << source.second.getNode("sourceKey").getValue() <<
00345 ": {" <<
00346 " transferPluginType: " <<
00347 source.second.getNode("transferPluginType").getValue() <<
00348 " source_rank: " <<
00349 sourceRank <<
00350 " max_fragment_size_words: " <<
00351 source.second.getNode("ARTDAQGlobalConfigurationLink/maxFragmentSizeWords").getValue<unsigned int>() <<
00352 "}\n";
00353 }
00354 }
00355 POPTAB;
00356 OUT << "}\n\n";
00357
00358 POPTAB;
00359 OUT << "}\n\n";
00360
00361
00362 OUT << "metrics: {\n";
00363
00364 PUSHTAB;
00365 auto metricsGroup = daq.getNode("daqMetricsLink");
00366 if(!metricsGroup.isDisconnected())
00367 {
00368 auto metrics = metricsGroup.getChildren();
00369
00370 for(auto &metric:metrics)
00371 {
00372 if(!metric.second.getNode("Status").getValue<bool>())
00373 PUSHCOMMENT;
00374
00375 OUT << metric.second.getNode("metricKey").getValue() <<
00376 ": {\n";
00377 PUSHTAB;
00378
00379 OUT << "metricPluginType: " <<
00380 metric.second.getNode("metricPluginType").getValue()
00381 << "\n";
00382 OUT << "level: " <<
00383 metric.second.getNode("metricLevel").getValue()
00384 << "\n";
00385
00386 auto metricParametersGroup = metric.second.getNode("metricParametersLink");
00387 if(!metricParametersGroup.isDisconnected())
00388 {
00389 auto metricParameters = metricParametersGroup.getChildren();
00390 for(auto &metricParameter:metricParameters)
00391 {
00392 if(!metricParameter.second.getNode("Enabled").getValue<bool>())
00393 PUSHCOMMENT;
00394
00395 auto comment = metricParameter.second.getNode("CommentDescription");
00396 OUT << metricParameter.second.getNode("metricParameterKey").getValue() <<
00397 ": " <<
00398 metricParameter.second.getNode("metricParameterValue").getValue()
00399 <<
00400 (comment.isDefaultValue()?"":("\t # " + comment.getValue())) <<
00401 "\n";
00402
00403 if(!metricParameter.second.getNode("Enabled").getValue<bool>())
00404 POPCOMMENT;
00405
00406 }
00407 }
00408 POPTAB;
00409 OUT << "}\n\n";
00410
00411 if(!metric.second.getNode("Status").getValue<bool>())
00412 POPCOMMENT;
00413 }
00414 }
00415 POPTAB;
00416 OUT << "}\n\n";
00417
00418
00419 auto destinationsGroup = daq.getNode("daqAggregatorDestinationsLink");
00420 if(!destinationsGroup.isDisconnected())
00421 {
00422 auto destinations = destinationsGroup.getChildren();
00423 for(auto &destination:destinations)
00424 {
00425 unsigned int destinationRank = contextConfig->getARTDAQAppRank(
00426 destination.second.getNode("destinationARTDAQContextLink").getValueAsString());
00427
00428 OUT << destination.second.getNode("destinationKey").getValue() <<
00429 ": {" <<
00430 " transferPluginType: " <<
00431 destination.second.getNode("transferPluginType").getValue() <<
00432 " source_rank: " <<
00433 selfRank <<
00434 " destination_rank: " <<
00435 destinationRank <<
00436 " max_fragment_size_words: " <<
00437 destination.second.getNode("ARTDAQGlobalConfigurationLink/maxFragmentSizeWords").getValue<unsigned int>() <<
00438 "}\n";
00439 }
00440 }
00441
00442 POPTAB;
00443 OUT << "}\n\n";
00444 }
00445
00446
00447
00448
00449 auto source = aggregatorNode.getNode("sourceLink");
00450 if(!source.isDisconnected())
00451 {
00452 OUT << "source: {\n";
00453
00454 PUSHTAB;
00455 OUT << "module_type: " << source.getNode("sourceModuleType").getValue() <<
00456 "\n";
00457 POPTAB;
00458 OUT << "}\n\n";
00459 }
00460
00461
00462
00463 auto outputs = aggregatorNode.getNode("outputsLink");
00464 if(!outputs.isDisconnected())
00465 {
00466 OUT << "outputs: {\n";
00467
00468 PUSHTAB;
00469
00470 auto outputPlugins = outputs.getChildren();
00471 for(auto &outputPlugin:outputPlugins)
00472 {
00473 if(!outputPlugin.second.getNode("Status").getValue<bool>())
00474 PUSHCOMMENT;
00475
00476 OUT << outputPlugin.second.getNode("outputKey").getValue() <<
00477 ": {\n";
00478 PUSHTAB;
00479 OUT << "module_type: " <<
00480 outputPlugin.second.getNode("outputModuleType").getValue() <<
00481 "\n";
00482 auto pluginParameterLink = outputPlugin.second.getNode("outputModuleParameterLink");
00483 if(!pluginParameterLink.isDisconnected())
00484 {
00485 auto pluginParameters = pluginParameterLink.getChildren();
00486 for(auto &pluginParameter:pluginParameters)
00487 {
00488 if(!pluginParameter.second.getNode("Enabled").getValue<bool>())
00489 PUSHCOMMENT;
00490
00491 auto comment = pluginParameter.second.getNode("CommentDescription");
00492 OUT << pluginParameter.second.getNode("outputParameterKey").getValue() <<
00493 ": " <<
00494 pluginParameter.second.getNode("outputParameterValue").getValue()
00495 <<
00496 (comment.isDefaultValue()?"":("\t # " + comment.getValue())) <<
00497 "\n";
00498
00499 if(!pluginParameter.second.getNode("Enabled").getValue<bool>())
00500 POPCOMMENT;
00501 }
00502 }
00503 POPTAB;
00504 OUT << "}\n\n";
00505
00506 if(!outputPlugin.second.getNode("Status").getValue<bool>())
00507 POPCOMMENT;
00508 }
00509
00510 POPTAB;
00511 OUT << "}\n\n";
00512 }
00513
00514
00515
00516
00517 auto physics = aggregatorNode.getNode("physicsLink");
00518 if(!physics.isDisconnected())
00519 {
00521 OUT << "physics: {\n";
00522
00523 PUSHTAB;
00524
00525 auto analyzers = physics.getNode("analyzersLink");
00526 if(!analyzers.isDisconnected())
00527 {
00529 OUT << "analyzers: {\n";
00530
00531 PUSHTAB;
00532 auto modules = analyzers.getChildren();
00533 for(auto &module:modules)
00534 {
00535 if(!module.second.getNode("Status").getValue<bool>())
00536 PUSHCOMMENT;
00537
00538 OUT << module.second.getNode("analyzerKey").getValue() <<
00539 ": {\n";
00540 PUSHTAB;
00541 OUT << "module_type: " <<
00542 module.second.getNode("analyzerModuleType").getValue() <<
00543 "\n";
00544 auto moduleParameterLink = module.second.getNode("analyzerModuleParameterLink");
00545 if(!moduleParameterLink.isDisconnected())
00546 {
00547 auto moduleParameters = moduleParameterLink.getChildren();
00548 for(auto &moduleParameter:moduleParameters)
00549 {
00550 if(!moduleParameter.second.getNode("Enabled").getValue<bool>())
00551 PUSHCOMMENT;
00552
00553 auto comment = moduleParameter.second.getNode("CommentDescription");
00554 OUT << moduleParameter.second.getNode("analyzerParameterKey").getValue() <<
00555 ": " <<
00556 moduleParameter.second.getNode("analyzerParameterValue").getValue()
00557 <<
00558 (comment.isDefaultValue()?"":("\t # " + comment.getValue())) <<
00559 "\n";
00560
00561 if(!moduleParameter.second.getNode("Enabled").getValue<bool>())
00562 POPCOMMENT;
00563 }
00564 }
00565 POPTAB;
00566 OUT << "}\n\n";
00567
00568 if(!module.second.getNode("Status").getValue<bool>())
00569 POPCOMMENT;
00570 }
00571 POPTAB;
00572 OUT << "}\n\n";
00573 }
00574
00575 auto producers = physics.getNode("producersLink");
00576 if(!producers.isDisconnected())
00577 {
00579 OUT << "producers: {\n";
00580
00581 PUSHTAB;
00582 auto modules = producers.getChildren();
00583 for(auto &module:modules)
00584 {
00585 if(!module.second.getNode("Status").getValue<bool>())
00586 PUSHCOMMENT;
00587
00588 OUT << module.second.getNode("producerKey").getValue() <<
00589 ": {\n";
00590 PUSHTAB;
00591 OUT << "module_type: " <<
00592 module.second.getNode("producerModuleType").getValue() <<
00593 "\n";
00594 auto moduleParameterLink = module.second.getNode("producerModuleParameterLink");
00595 if(!moduleParameterLink.isDisconnected())
00596 {
00597 auto moduleParameters = moduleParameterLink.getChildren();
00598 for(auto &moduleParameter:moduleParameters)
00599 {
00600 if(!moduleParameter.second.getNode("Enabled").getValue<bool>())
00601 PUSHCOMMENT;
00602
00603 auto comment = moduleParameter.second.getNode("CommentDescription");
00604 OUT << moduleParameter.second.getNode("producerParameterKey").getValue() <<
00605 ":" <<
00606 moduleParameter.second.getNode("producerParameterValue").getValue()
00607 <<
00608 (comment.isDefaultValue()?"":("\t # " + comment.getValue())) <<
00609 "\n";
00610
00611 if(!moduleParameter.second.getNode("Enabled").getValue<bool>())
00612 POPCOMMENT;
00613 }
00614 }
00615 POPTAB;
00616 OUT << "}\n\n";
00617
00618 if(!module.second.getNode("Status").getValue<bool>())
00619 POPCOMMENT;
00620 }
00621 POPTAB;
00622 OUT << "}\n\n";
00623 }
00624
00625
00626 auto filters = physics.getNode("filtersLink");
00627 if(!filters.isDisconnected())
00628 {
00630 OUT << "filters: {\n";
00631
00632 PUSHTAB;
00633 auto modules = filters.getChildren();
00634 for(auto &module:modules)
00635 {
00636 if(!module.second.getNode("Status").getValue<bool>())
00637 PUSHCOMMENT;
00638
00639 OUT << module.second.getNode("filterKey").getValue() <<
00640 ": {\n";
00641 PUSHTAB;
00642 OUT << "module_type: " <<
00643 module.second.getNode("filterModuleType").getValue() <<
00644 "\n";
00645 auto moduleParameterLink = module.second.getNode("filterModuleParameterLink");
00646 if(!moduleParameterLink.isDisconnected())
00647 {
00648 auto moduleParameters = moduleParameterLink.getChildren();
00649 for(auto &moduleParameter:moduleParameters)
00650 {
00651 if(!moduleParameter.second.getNode("Enabled").getValue<bool>())
00652 PUSHCOMMENT;
00653
00654 auto comment = moduleParameter.second.getNode("CommentDescription");
00655 OUT << moduleParameter.second.getNode("filterParameterKey").getValue()
00656 << ": " <<
00657 moduleParameter.second.getNode("filterParameterValue").getValue()
00658 <<
00659 (comment.isDefaultValue()?"":("\t # " + comment.getValue())) <<
00660 "\n";
00661
00662 if(!moduleParameter.second.getNode("Enabled").getValue<bool>())
00663 POPCOMMENT;
00664 }
00665 }
00666 POPTAB;
00667 OUT << "}\n\n";
00668
00669 if(!module.second.getNode("Status").getValue<bool>())
00670 POPCOMMENT;
00671 }
00672 POPTAB;
00673 OUT << "}\n\n";
00674 }
00675
00676
00677 auto otherParameterLink = physics.getNode("physicsOtherParametersLink");
00678 if(!otherParameterLink.isDisconnected())
00679 {
00681 auto physicsParameters = otherParameterLink.getChildren();
00682 for(auto ¶meter:physicsParameters)
00683 {
00684 if(!parameter.second.getNode("Enabled").getValue<bool>())
00685 PUSHCOMMENT;
00686
00687 auto comment = parameter.second.getNode("CommentDescription");
00688 OUT << parameter.second.getNode("physicsParameterKey").getValue() <<
00689 ": " <<
00690 parameter.second.getNode("physicsParameterValue").getValue()
00691 <<
00692 (comment.isDefaultValue()?"":("\t # " + comment.getValue())) <<
00693 "\n";
00694
00695 if(!parameter.second.getNode("Enabled").getValue<bool>())
00696 POPCOMMENT;
00697 }
00698 }
00699 POPTAB;
00700 OUT << "}\n\n";
00701 }
00702
00703
00704
00705
00706 OUT << "process_name: " <<
00707 aggregatorNode.getNode("ARTDAQGlobalConfigurationForProcessNameLink/processNameForAggregators")
00708 << "\n";
00709
00710
00711
00712
00713 out.close();
00714 }
00715
00716 DEFINE_OTS_CONFIGURATION(ARTDAQAggregatorConfiguration)