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