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 __COUT__ << "*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << std::endl;
00048 __COUT__ << 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 __COUT__ << "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 __COUT__ << "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 __COUT__ << "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 try
00285 {
00286 auto destinations = destinationsGroup.getChildren();
00287 for(auto &destination:destinations)
00288 {
00289 unsigned int destinationRank =
00290 contextConfig->getARTDAQAppRank(
00291 destination.second.getNode("destinationARTDAQContextLink").getValue());
00292 OUT << destination.second.getNode("destinationKey").getValue() <<
00293 ": {" <<
00294 " transferPluginType: " <<
00295 destination.second.getNode("transferPluginType").getValue() <<
00296 " destination_rank: " <<
00297 destinationRank <<
00298 " max_fragment_size_words: " <<
00299 destination.second.getNode("ARTDAQGlobalConfigurationLink/maxFragmentSizeWords").getValue<unsigned int>() <<
00300 "}\n";
00301 }
00302 }
00303 catch(const std::runtime_error& e)
00304 {
00305 __SS__ << "Are the Net Monitor Transport Service destinations valid? Error occurred looking for Event Builder transport service destinations for UID '" <<
00306 builderNode.getValue() << "': " << e.what() << std::endl;
00307 __COUT_ERR__ << ss.str() << std::endl;
00308 throw std::runtime_error(ss.str());
00309 }
00310 }
00311 POPTAB;
00312 OUT << "}\n\n";
00313
00314 POPTAB;
00315 OUT << "}\n\n";
00316
00317 POPTAB;
00318 OUT << "}\n\n";
00319
00320 }
00321
00322
00323
00324 auto daq = builderNode.getNode("daqLink");
00325 if(!daq.isDisconnected())
00326 {
00328 OUT << "daq: {\n";
00329
00330
00331 PUSHTAB;
00332 OUT << "event_builder: {\n";
00333
00334 PUSHTAB;
00335 auto parametersLink = daq.getNode("daqEventBuilderParametersLink");
00336 if(!parametersLink.isDisconnected())
00337 {
00338
00339 auto parameters = parametersLink.getChildren();
00340 for(auto ¶meter:parameters)
00341 {
00342 if(!parameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00343 PUSHCOMMENT;
00344
00345 OUT << parameter.second.getNode("daqParameterKey").getValue() <<
00346 ": " <<
00347 parameter.second.getNode("daqParameterValue").getValue()
00348 << "\n";
00349
00350 if(!parameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00351 POPCOMMENT;
00352 }
00353 }
00354 OUT << "\n";
00355
00356
00357 OUT << "sources: {\n";
00358
00359 PUSHTAB;
00360 auto sourcesGroup = daq.getNode("daqEventBuilderSourcesLink");
00361 if(!sourcesGroup.isDisconnected())
00362 {
00363 try
00364 {
00365 auto sources = sourcesGroup.getChildren();
00366 for(auto &source:sources)
00367 {
00368 unsigned int sourceRank =
00369 contextConfig->getARTDAQAppRank(
00370 source.second.getNode("sourceARTDAQContextLink").getValue());
00371
00372 OUT << source.second.getNode("sourceKey").getValue() <<
00373 ": {" <<
00374 " transferPluginType: " <<
00375 source.second.getNode("transferPluginType").getValue() <<
00376 " source_rank: " <<
00377 sourceRank <<
00378 " max_fragment_size_words: " <<
00379 source.second.getNode("ARTDAQGlobalConfigurationLink/maxFragmentSizeWords").getValue<unsigned int>() <<
00380 "}\n";
00381 }
00382 }
00383 catch(const std::runtime_error& e)
00384 {
00385 __SS__ << "Are the DAQ sources valid? Error occurred looking for Event Builder DAQ sources for UID '" <<
00386 builderNode.getValue() << "': " << e.what() << std::endl;
00387 __COUT_ERR__ << ss.str() << std::endl;
00388 throw std::runtime_error(ss.str());
00389 }
00390 }
00391 POPTAB;
00392 OUT << "}\n\n";
00393
00394 POPTAB;
00395 OUT << "}\n\n";
00396
00397
00398 OUT << "metrics: {\n";
00399
00400 PUSHTAB;
00401 auto metricsGroup = daq.getNode("daqMetricsLink");
00402 if(!metricsGroup.isDisconnected())
00403 {
00404 auto metrics = metricsGroup.getChildren();
00405
00406 for(auto &metric:metrics)
00407 {
00408 if(!metric.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00409 PUSHCOMMENT;
00410
00411 OUT << metric.second.getNode("metricKey").getValue() <<
00412 ": {\n";
00413 PUSHTAB;
00414
00415 OUT << "metricPluginType: " <<
00416 metric.second.getNode("metricPluginType").getValue()
00417 << "\n";
00418 OUT << "level: " <<
00419 metric.second.getNode("metricLevel").getValue()
00420 << "\n";
00421
00422 auto metricParametersGroup = metric.second.getNode("metricParametersLink");
00423 if(!metricParametersGroup.isDisconnected())
00424 {
00425 auto metricParameters = metricParametersGroup.getChildren();
00426 for(auto &metricParameter:metricParameters)
00427 {
00428 if(!metricParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00429 PUSHCOMMENT;
00430
00431 OUT << metricParameter.second.getNode("metricParameterKey").getValue() <<
00432 ": " <<
00433 metricParameter.second.getNode("metricParameterValue").getValue()
00434 << "\n";
00435
00436 if(!metricParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00437 POPCOMMENT;
00438
00439 }
00440 }
00441 POPTAB;
00442 OUT << "}\n\n";
00443
00444 if(!metric.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00445 POPCOMMENT;
00446 }
00447 }
00448 POPTAB;
00449 OUT << "}\n\n";
00450
00451 POPTAB;
00452 OUT << "}\n\n";
00453 }
00454
00455
00456
00457 auto outputs = builderNode.getNode("outputsLink");
00458 if(!outputs.isDisconnected())
00459 {
00460 OUT << "outputs: {\n";
00461
00462 PUSHTAB;
00463
00464 auto outputPlugins = outputs.getChildren();
00465 for(auto &outputPlugin:outputPlugins)
00466 {
00467 if(!outputPlugin.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00468 PUSHCOMMENT;
00469
00470 OUT << outputPlugin.second.getNode("outputKey").getValue() <<
00471 ": {\n";
00472 PUSHTAB;
00473 OUT << "module_type: " <<
00474 outputPlugin.second.getNode("outputModuleType").getValue() <<
00475 "\n";
00476 auto pluginParameterLink = outputPlugin.second.getNode("outputModuleParameterLink");
00477 if(!pluginParameterLink.isDisconnected())
00478 {
00479 auto pluginParameters = pluginParameterLink.getChildren();
00480 for(auto &pluginParameter:pluginParameters)
00481 {
00482 if(!pluginParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00483 PUSHCOMMENT;
00484
00485 OUT << pluginParameter.second.getNode("outputParameterKey").getValue() <<
00486 ": " <<
00487 pluginParameter.second.getNode("outputParameterValue").getValue()
00488 << "\n";
00489
00490 if(!pluginParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00491 POPCOMMENT;
00492 }
00493 }
00494 POPTAB;
00495 OUT << "}\n\n";
00496
00497 if(!outputPlugin.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00498 POPCOMMENT;
00499 }
00500
00501 POPTAB;
00502 OUT << "}\n\n";
00503 }
00504
00505
00506
00507
00508 auto physics = builderNode.getNode("physicsLink");
00509 if(!physics.isDisconnected())
00510 {
00512 OUT << "physics: {\n";
00513
00514 PUSHTAB;
00515
00516 auto analyzers = physics.getNode("analyzersLink");
00517 if(!analyzers.isDisconnected())
00518 {
00520 OUT << "analyzers: {\n";
00521
00522 PUSHTAB;
00523 auto modules = analyzers.getChildren();
00524 for(auto &module:modules)
00525 {
00526 if(!module.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00527 PUSHCOMMENT;
00528
00529 OUT << module.second.getNode("analyzerKey").getValue() <<
00530 ": {\n";
00531 PUSHTAB;
00532 OUT << "module_type: " <<
00533 module.second.getNode("analyzerModuleType").getValue() <<
00534 "\n";
00535 auto moduleParameterLink = module.second.getNode("analyzerModuleParameterLink");
00536 if(!moduleParameterLink.isDisconnected())
00537 {
00538 auto moduleParameters = moduleParameterLink.getChildren();
00539 for(auto &moduleParameter:moduleParameters)
00540 {
00541 if(!moduleParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00542 PUSHCOMMENT;
00543
00544 OUT << moduleParameter.second.getNode("analyzerParameterKey").getValue() <<
00545 ": " <<
00546 moduleParameter.second.getNode("analyzerParameterValue").getValue()
00547 << "\n";
00548
00549 if(!moduleParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00550 POPCOMMENT;
00551 }
00552 }
00553 POPTAB;
00554 OUT << "}\n\n";
00555
00556 if(!module.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00557 POPCOMMENT;
00558 }
00559 POPTAB;
00560 OUT << "}\n\n";
00561 }
00562
00563 auto producers = physics.getNode("producersLink");
00564 if(!producers.isDisconnected())
00565 {
00567 OUT << "producers: {\n";
00568
00569 PUSHTAB;
00570 auto modules = producers.getChildren();
00571 for(auto &module:modules)
00572 {
00573 if(!module.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00574 PUSHCOMMENT;
00575
00576 OUT << module.second.getNode("producerKey").getValue() <<
00577 ": {\n";
00578 PUSHTAB;
00579 OUT << "module_type: " <<
00580 module.second.getNode("producerModuleType").getValue() <<
00581 "\n";
00582 auto moduleParameterLink = module.second.getNode("producerModuleParameterLink");
00583 if(!moduleParameterLink.isDisconnected())
00584 {
00585 auto moduleParameters = moduleParameterLink.getChildren();
00586 for(auto &moduleParameter:moduleParameters)
00587 {
00588 if(!moduleParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00589 PUSHCOMMENT;
00590
00591 OUT << moduleParameter.second.getNode("producerParameterKey").getValue() <<
00592 ":" <<
00593 moduleParameter.second.getNode("producerParameterValue").getValue()
00594 << "\n";
00595
00596 if(!moduleParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00597 POPCOMMENT;
00598 }
00599 }
00600 POPTAB;
00601 OUT << "}\n\n";
00602
00603 if(!module.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00604 POPCOMMENT;
00605 }
00606 POPTAB;
00607 OUT << "}\n\n";
00608 }
00609
00610
00611 auto filters = physics.getNode("filtersLink");
00612 if(!filters.isDisconnected())
00613 {
00615 OUT << "filters: {\n";
00616
00617 PUSHTAB;
00618 auto modules = filters.getChildren();
00619 for(auto &module:modules)
00620 {
00621 if(!module.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00622 PUSHCOMMENT;
00623
00624 OUT << module.second.getNode("filterKey").getValue() <<
00625 ": {\n";
00626 PUSHTAB;
00627 OUT << "module_type: " <<
00628 module.second.getNode("filterModuleType").getValue() <<
00629 "\n";
00630 auto moduleParameterLink = module.second.getNode("filterModuleParameterLink");
00631 if(!moduleParameterLink.isDisconnected())
00632 {
00633 auto moduleParameters = moduleParameterLink.getChildren();
00634 for(auto &moduleParameter:moduleParameters)
00635 {
00636 if(!moduleParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00637 PUSHCOMMENT;
00638
00639 OUT << moduleParameter.second.getNode("filterParameterKey").getValue()
00640 << ": " <<
00641 moduleParameter.second.getNode("filterParameterValue").getValue()
00642 << "\n";
00643
00644 if(!moduleParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00645 POPCOMMENT;
00646 }
00647 }
00648 POPTAB;
00649 OUT << "}\n\n";
00650
00651 if(!module.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00652 POPCOMMENT;
00653 }
00654 POPTAB;
00655 OUT << "}\n\n";
00656 }
00657
00658
00659 auto otherParameterLink = physics.getNode("physicsOtherParametersLink");
00660 if(!otherParameterLink.isDisconnected())
00661 {
00663 auto physicsParameters = otherParameterLink.getChildren();
00664 for(auto ¶meter:physicsParameters)
00665 {
00666 if(!parameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00667 PUSHCOMMENT;
00668
00669 OUT << parameter.second.getNode("physicsParameterKey").getValue() <<
00670 ": " <<
00671 parameter.second.getNode("physicsParameterValue").getValue()
00672 << "\n";
00673
00674 if(!parameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00675 POPCOMMENT;
00676 }
00677 }
00678 POPTAB;
00679 OUT << "}\n\n";
00680 }
00681
00682
00683
00684
00685 auto source = builderNode.getNode("sourceLink");
00686 if(!source.isDisconnected())
00687 {
00688 OUT << "source: {\n";
00689
00690 PUSHTAB;
00691 OUT << "module_type: " << source.getNode("sourceModuleType").getValue() <<
00692 "\n";
00693 OUT << "waiting_time: " << source.getNode("sourceWaitingTime").getValue() <<
00694 "\n";
00695 OUT << "resume_after_timeout: " <<
00696 (source.getNode("sourceResumeAfterTimeout").getValue<bool>()?"true":"false") <<
00697 "\n";
00698 POPTAB;
00699 OUT << "}\n\n";
00700 }
00701
00702
00703
00704 OUT << "process_name: " <<
00705 builderNode.getNode("ARTDAQGlobalConfigurationForProcessNameLink/processNameForBuilders")
00706 << "\n";
00707
00708
00709
00710
00711 out.close();
00712 }
00713
00714
00715 DEFINE_OTS_CONFIGURATION(ARTDAQBuilderConfiguration)