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