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