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 __COUT__ << "*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << std::endl;
00046 __COUT__ << 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 __COUT__ << "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 __COUT__ << "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 __COUT__ << "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 __COUT__ << "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(ViewColumnInfo::COL_NAME_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(ViewColumnInfo::COL_NAME_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 try
00348 {
00349 auto sources = sourcesGroup.getChildren();
00350 for(auto &source:sources)
00351 {
00352 unsigned int sourceRank =
00353 contextConfig->getARTDAQAppRank(
00354 source.second.getNode("sourceARTDAQContextLink").getValue());
00355
00356 OUT << source.second.getNode("sourceKey").getValue() <<
00357 ": {" <<
00358 " transferPluginType: " <<
00359 source.second.getNode("transferPluginType").getValue() <<
00360 " source_rank: " <<
00361 sourceRank <<
00362 " max_fragment_size_words: " <<
00363 source.second.getNode("ARTDAQGlobalConfigurationLink/maxFragmentSizeWords").getValue<unsigned int>() <<
00364 "}\n";
00365 }
00366 }
00367 catch(const std::runtime_error& e)
00368 {
00369 __SS__ << "Are the DAQ sources valid? Error occurred looking for Aggregator DAQ sources for UID '" <<
00370 aggregatorNode.getValue() << "': " << e.what() << std::endl;
00371 __COUT_ERR__ << ss.str() << std::endl;
00372 throw std::runtime_error(ss.str());
00373 }
00374 }
00375 POPTAB;
00376 OUT << "}\n\n";
00377
00378 POPTAB;
00379 OUT << "}\n\n";
00380
00381
00382 OUT << "metrics: {\n";
00383
00384 PUSHTAB;
00385 auto metricsGroup = daq.getNode("daqMetricsLink");
00386 if(!metricsGroup.isDisconnected())
00387 {
00388 auto metrics = metricsGroup.getChildren();
00389
00390 for(auto &metric:metrics)
00391 {
00392 if(!metric.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00393 PUSHCOMMENT;
00394
00395 OUT << metric.second.getNode("metricKey").getValue() <<
00396 ": {\n";
00397 PUSHTAB;
00398
00399 OUT << "metricPluginType: " <<
00400 metric.second.getNode("metricPluginType").getValue()
00401 << "\n";
00402 OUT << "level: " <<
00403 metric.second.getNode("metricLevel").getValue()
00404 << "\n";
00405
00406 auto metricParametersGroup = metric.second.getNode("metricParametersLink");
00407 if(!metricParametersGroup.isDisconnected())
00408 {
00409 auto metricParameters = metricParametersGroup.getChildren();
00410 for(auto &metricParameter:metricParameters)
00411 {
00412 if(!metricParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00413 PUSHCOMMENT;
00414
00415 auto comment = metricParameter.second.getNode("CommentDescription");
00416 OUT << metricParameter.second.getNode("metricParameterKey").getValue() <<
00417 ": " <<
00418 metricParameter.second.getNode("metricParameterValue").getValue()
00419 <<
00420 (comment.isDefaultValue()?"":("\t # " + comment.getValue())) <<
00421 "\n";
00422
00423 if(!metricParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00424 POPCOMMENT;
00425
00426 }
00427 }
00428 POPTAB;
00429 OUT << "}\n\n";
00430
00431 if(!metric.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00432 POPCOMMENT;
00433 }
00434 }
00435 POPTAB;
00436 OUT << "}\n\n";
00437
00438
00439 auto destinationsGroup = daq.getNode("daqAggregatorDestinationsLink");
00440 if(!destinationsGroup.isDisconnected())
00441 {
00442 try
00443 {
00444 auto destinations = destinationsGroup.getChildren();
00445 for(auto &destination:destinations)
00446 {
00447 unsigned int destinationRank = contextConfig->getARTDAQAppRank(
00448 destination.second.getNode("destinationARTDAQContextLink").getValueAsString());
00449
00450 OUT << destination.second.getNode("destinationKey").getValue() <<
00451 ": {" <<
00452 " transferPluginType: " <<
00453 destination.second.getNode("transferPluginType").getValue() <<
00454 " source_rank: " <<
00455 selfRank <<
00456 " destination_rank: " <<
00457 destinationRank <<
00458 " max_fragment_size_words: " <<
00459 destination.second.getNode("ARTDAQGlobalConfigurationLink/maxFragmentSizeWords").getValue<unsigned int>() <<
00460 "}\n";
00461 }
00462 }
00463 catch(const std::runtime_error& e)
00464 {
00465 __SS__ << "Are the DAQ destinations valid? Error occurred looking for Aggregator DAQ destinations for UID '" <<
00466 aggregatorNode.getValue() << "': " << e.what() << std::endl;
00467 __COUT_ERR__ << ss.str() << std::endl;
00468 throw std::runtime_error(ss.str());
00469 }
00470 }
00471
00472 POPTAB;
00473 OUT << "}\n\n";
00474 }
00475
00476
00477
00478
00479 auto source = aggregatorNode.getNode("sourceLink");
00480 if(!source.isDisconnected())
00481 {
00482 OUT << "source: {\n";
00483
00484 PUSHTAB;
00485 OUT << "module_type: " << source.getNode("sourceModuleType").getValue() <<
00486 "\n";
00487 POPTAB;
00488 OUT << "}\n\n";
00489 }
00490
00491
00492
00493 auto outputs = aggregatorNode.getNode("outputsLink");
00494 if(!outputs.isDisconnected())
00495 {
00496 OUT << "outputs: {\n";
00497
00498 PUSHTAB;
00499
00500 auto outputPlugins = outputs.getChildren();
00501 for(auto &outputPlugin:outputPlugins)
00502 {
00503 if(!outputPlugin.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00504 PUSHCOMMENT;
00505
00506 OUT << outputPlugin.second.getNode("outputKey").getValue() <<
00507 ": {\n";
00508 PUSHTAB;
00509 OUT << "module_type: " <<
00510 outputPlugin.second.getNode("outputModuleType").getValue() <<
00511 "\n";
00512 auto pluginParameterLink = outputPlugin.second.getNode("outputModuleParameterLink");
00513 if(!pluginParameterLink.isDisconnected())
00514 {
00515 auto pluginParameters = pluginParameterLink.getChildren();
00516 for(auto &pluginParameter:pluginParameters)
00517 {
00518 if(!pluginParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00519 PUSHCOMMENT;
00520
00521 auto comment = pluginParameter.second.getNode("CommentDescription");
00522 OUT << pluginParameter.second.getNode("outputParameterKey").getValue() <<
00523 ": " <<
00524 pluginParameter.second.getNode("outputParameterValue").getValue()
00525 <<
00526 (comment.isDefaultValue()?"":("\t # " + comment.getValue())) <<
00527 "\n";
00528
00529 if(!pluginParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00530 POPCOMMENT;
00531 }
00532 }
00533 POPTAB;
00534 OUT << "}\n\n";
00535
00536 if(!outputPlugin.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00537 POPCOMMENT;
00538 }
00539
00540 POPTAB;
00541 OUT << "}\n\n";
00542 }
00543
00544
00545
00546
00547 auto physics = aggregatorNode.getNode("physicsLink");
00548 if(!physics.isDisconnected())
00549 {
00551 OUT << "physics: {\n";
00552
00553 PUSHTAB;
00554
00555 auto analyzers = physics.getNode("analyzersLink");
00556 if(!analyzers.isDisconnected())
00557 {
00559 OUT << "analyzers: {\n";
00560
00561 PUSHTAB;
00562 auto modules = analyzers.getChildren();
00563 for(auto &module:modules)
00564 {
00565 if(!module.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00566 PUSHCOMMENT;
00567
00568 OUT << module.second.getNode("analyzerKey").getValue() <<
00569 ": {\n";
00570 PUSHTAB;
00571 OUT << "module_type: " <<
00572 module.second.getNode("analyzerModuleType").getValue() <<
00573 "\n";
00574 auto moduleParameterLink = module.second.getNode("analyzerModuleParameterLink");
00575 if(!moduleParameterLink.isDisconnected())
00576 {
00577 auto moduleParameters = moduleParameterLink.getChildren();
00578 for(auto &moduleParameter:moduleParameters)
00579 {
00580 if(!moduleParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00581 PUSHCOMMENT;
00582
00583 auto comment = moduleParameter.second.getNode("CommentDescription");
00584 OUT << moduleParameter.second.getNode("analyzerParameterKey").getValue() <<
00585 ": " <<
00586 moduleParameter.second.getNode("analyzerParameterValue").getValue()
00587 <<
00588 (comment.isDefaultValue()?"":("\t # " + comment.getValue())) <<
00589 "\n";
00590
00591 if(!moduleParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00592 POPCOMMENT;
00593 }
00594 }
00595 POPTAB;
00596 OUT << "}\n\n";
00597
00598 if(!module.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00599 POPCOMMENT;
00600 }
00601 POPTAB;
00602 OUT << "}\n\n";
00603 }
00604
00605 auto producers = physics.getNode("producersLink");
00606 if(!producers.isDisconnected())
00607 {
00609 OUT << "producers: {\n";
00610
00611 PUSHTAB;
00612 auto modules = producers.getChildren();
00613 for(auto &module:modules)
00614 {
00615 if(!module.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00616 PUSHCOMMENT;
00617
00618 OUT << module.second.getNode("producerKey").getValue() <<
00619 ": {\n";
00620 PUSHTAB;
00621 OUT << "module_type: " <<
00622 module.second.getNode("producerModuleType").getValue() <<
00623 "\n";
00624 auto moduleParameterLink = module.second.getNode("producerModuleParameterLink");
00625 if(!moduleParameterLink.isDisconnected())
00626 {
00627 auto moduleParameters = moduleParameterLink.getChildren();
00628 for(auto &moduleParameter:moduleParameters)
00629 {
00630 if(!moduleParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00631 PUSHCOMMENT;
00632
00633 auto comment = moduleParameter.second.getNode("CommentDescription");
00634 OUT << moduleParameter.second.getNode("producerParameterKey").getValue() <<
00635 ":" <<
00636 moduleParameter.second.getNode("producerParameterValue").getValue()
00637 <<
00638 (comment.isDefaultValue()?"":("\t # " + comment.getValue())) <<
00639 "\n";
00640
00641 if(!moduleParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00642 POPCOMMENT;
00643 }
00644 }
00645 POPTAB;
00646 OUT << "}\n\n";
00647
00648 if(!module.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00649 POPCOMMENT;
00650 }
00651 POPTAB;
00652 OUT << "}\n\n";
00653 }
00654
00655
00656 auto filters = physics.getNode("filtersLink");
00657 if(!filters.isDisconnected())
00658 {
00660 OUT << "filters: {\n";
00661
00662 PUSHTAB;
00663 auto modules = filters.getChildren();
00664 for(auto &module:modules)
00665 {
00666 if(!module.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00667 PUSHCOMMENT;
00668
00669 OUT << module.second.getNode("filterKey").getValue() <<
00670 ": {\n";
00671 PUSHTAB;
00672 OUT << "module_type: " <<
00673 module.second.getNode("filterModuleType").getValue() <<
00674 "\n";
00675 auto moduleParameterLink = module.second.getNode("filterModuleParameterLink");
00676 if(!moduleParameterLink.isDisconnected())
00677 {
00678 auto moduleParameters = moduleParameterLink.getChildren();
00679 for(auto &moduleParameter:moduleParameters)
00680 {
00681 if(!moduleParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00682 PUSHCOMMENT;
00683
00684 auto comment = moduleParameter.second.getNode("CommentDescription");
00685 OUT << moduleParameter.second.getNode("filterParameterKey").getValue()
00686 << ": " <<
00687 moduleParameter.second.getNode("filterParameterValue").getValue()
00688 <<
00689 (comment.isDefaultValue()?"":("\t # " + comment.getValue())) <<
00690 "\n";
00691
00692 if(!moduleParameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00693 POPCOMMENT;
00694 }
00695 }
00696 POPTAB;
00697 OUT << "}\n\n";
00698
00699 if(!module.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00700 POPCOMMENT;
00701 }
00702 POPTAB;
00703 OUT << "}\n\n";
00704 }
00705
00706
00707 auto otherParameterLink = physics.getNode("physicsOtherParametersLink");
00708 if(!otherParameterLink.isDisconnected())
00709 {
00711 auto physicsParameters = otherParameterLink.getChildren();
00712 for(auto ¶meter:physicsParameters)
00713 {
00714 if(!parameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00715 PUSHCOMMENT;
00716
00717 auto comment = parameter.second.getNode("CommentDescription");
00718 OUT << parameter.second.getNode("physicsParameterKey").getValue() <<
00719 ": " <<
00720 parameter.second.getNode("physicsParameterValue").getValue()
00721 <<
00722 (comment.isDefaultValue()?"":("\t # " + comment.getValue())) <<
00723 "\n";
00724
00725 if(!parameter.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<bool>())
00726 POPCOMMENT;
00727 }
00728 }
00729 POPTAB;
00730 OUT << "}\n\n";
00731 }
00732
00733
00734
00735
00736 OUT << "process_name: " <<
00737 aggregatorNode.getNode("ARTDAQGlobalConfigurationForProcessNameLink/processNameForAggregators")
00738 << "\n";
00739
00740
00741
00742
00743 out.close();
00744 }
00745
00746 DEFINE_OTS_CONFIGURATION(ARTDAQAggregatorConfiguration)