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