00001 #include "otsdaq-core/ConfigurationPluginDataFormats/ARTDAQBoardReaderConfiguration.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 "boardReader"
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 ARTDAQBoardReaderConfiguration::ARTDAQBoardReaderConfiguration(void)
00027 : ConfigurationBase("ARTDAQBoardReaderConfiguration")
00028 {
00030
00032
00033 }
00034
00035
00036 ARTDAQBoardReaderConfiguration::~ARTDAQBoardReaderConfiguration(void)
00037 {}
00038
00039
00040 void ARTDAQBoardReaderConfiguration::init(ConfigurationManager* configManager)
00041 {
00042
00043 mkdir((ARTDAQ_FCL_PATH).c_str(), 0755);
00044
00045 __MOUT__ << "*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << std::endl;
00046 __MOUT__ << configManager->__SELF_NODE__ << std::endl;
00047
00048 const XDAQContextConfiguration *contextConfig = configManager->__GET_CONFIG__(XDAQContextConfiguration);
00049
00050
00051
00052 auto childrenMap = configManager->__SELF_NODE__.getChildren();
00053
00054 std::string appUID, buffUID, consumerUID;
00055 for(auto &child:childrenMap)
00056 if(child.second.getNode("Status").getValue<bool>())
00057 {
00058
00059
00060 outputFHICL(child.second, contextConfig);
00061 }
00062 }
00063
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 std::string ARTDAQBoardReaderConfiguration::getFHICLFilename(const ConfigurationTree &boardReaderNode)
00075 {
00076 __MOUT__ << "ARTDAQ BoardReader UID: " << boardReaderNode.getValue() << std::endl;
00077 std::string filename = ARTDAQ_FCL_PATH + ARTDAQ_FILE_PREAMBLE + "-";
00078 std::string uid = boardReaderNode.getValue();
00079 for(unsigned int i=0;i<uid.size();++i)
00080 if((uid[i] >= 'a' && uid[i] <= 'z') ||
00081 (uid[i] >= 'A' && uid[i] <= 'Z') ||
00082 (uid[i] >= '0' && uid[i] <= '9'))
00083 filename += uid[i];
00084
00085 filename += ".fcl";
00086
00087 __MOUT__ << "fcl: " << filename << std::endl;
00088
00089 return filename;
00090 }
00091
00092
00093 void ARTDAQBoardReaderConfiguration::outputFHICL(const ConfigurationTree &boardReaderNode,
00094 const XDAQContextConfiguration *contextConfig)
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 std::string filename = getFHICLFilename(boardReaderNode);
00190
00192
00193 std::fstream out;
00194
00195 std::string tabStr = "";
00196 std::string commentStr = "";
00197
00198 out.open(filename, std::fstream::out | std::fstream::trunc);
00199 if(out.fail())
00200 {
00201 __SS__ << "Failed to open ARTDAQ Builder fcl file: " << filename << std::endl;
00202 throw std::runtime_error(ss.str());
00203 }
00204
00205
00206
00207
00208 OUT << "daq: {\n";
00209
00210
00211 PUSHTAB;
00212 OUT << "fragment_receiver: {\n";
00213
00214 PUSHTAB;
00215 {
00216 auto parametersLink = boardReaderNode.getNode("daqSharedParametersLink");
00217 if(!parametersLink.isDisconnected())
00218 {
00219
00220 auto parameters = parametersLink.getChildren();
00221 for(auto ¶meter:parameters)
00222 {
00223 if(!parameter.second.getNode("Enabled").getValue<bool>())
00224 PUSHCOMMENT;
00225
00226 auto comment = parameter.second.getNode("CommentDescription");
00227 OUT << parameter.second.getNode("daqParameterKey").getValue() <<
00228 ": " <<
00229 parameter.second.getNode("daqParameterValue").getValue()
00230 <<
00231 (comment.isDefaultValue()?"":("\t # " + comment.getValue())) <<
00232 "\n";
00233
00234 if(!parameter.second.getNode("Enabled").getValue<bool>())
00235 POPCOMMENT;
00236 }
00237 }
00238 OUT << "\n";
00239 }
00240 {
00241 auto parametersLink = boardReaderNode.getNode("daqUniqueParametersLink");
00242 if(!parametersLink.isDisconnected())
00243 {
00244
00245 auto parameters = parametersLink.getChildren();
00246 for(auto ¶meter:parameters)
00247 {
00248 if(!parameter.second.getNode("Enabled").getValue<bool>())
00249 PUSHCOMMENT;
00250
00251 auto comment = parameter.second.getNode("CommentDescription");
00252 OUT << parameter.second.getNode("daqParameterKey").getValue() <<
00253 ": " <<
00254 parameter.second.getNode("daqParameterValue").getValue()
00255 <<
00256 (comment.isDefaultValue()?"":("\t # " + comment.getValue())) <<
00257 "\n";
00258
00259 if(!parameter.second.getNode("Enabled").getValue<bool>())
00260 POPCOMMENT;
00261 }
00262 }
00263 OUT << "\n";
00264 }
00265
00266 OUT << "destinations: {\n";
00267
00268 PUSHTAB;
00269 auto destinationsGroup = boardReaderNode.getNode("daqDestinationsLink");
00270 if(!destinationsGroup.isDisconnected())
00271 {
00272 auto destinations = destinationsGroup.getChildren();
00273 for(auto &destination:destinations)
00274 {
00275 unsigned int destinationRank =
00276 contextConfig->getARTDAQAppRank(
00277 destination.second.getNode("destinationARTDAQContextLink").getValue());
00278 OUT << destination.second.getNode("destinationKey").getValue() <<
00279 ": {" <<
00280 " transferPluginType: " <<
00281 destination.second.getNode("transferPluginType").getValue() <<
00282 " destination_rank: " <<
00283 destinationRank <<
00284 " max_fragment_size_words: " <<
00285 destination.second.getNode("ARTDAQGlobalConfigurationLink/maxFragmentSizeWords").getValue<unsigned int>() <<
00286 "}\n";
00287 }
00288 }
00289 POPTAB;
00290 OUT << "}\n\n";
00291
00292 POPTAB;
00293 OUT << "}\n\n";
00294
00295
00296 OUT << "metrics: {\n";
00297
00298 PUSHTAB;
00299 auto metricsGroup = boardReaderNode.getNode("daqMetricsLink");
00300 if(!metricsGroup.isDisconnected())
00301 {
00302 auto metrics = metricsGroup.getChildren();
00303
00304 for(auto &metric:metrics)
00305 {
00306 if(!metric.second.getNode("Status").getValue<bool>())
00307 PUSHCOMMENT;
00308
00309 OUT << metric.second.getNode("metricKey").getValue() <<
00310 ": {\n";
00311 PUSHTAB;
00312
00313 OUT << "metricPluginType: " <<
00314 metric.second.getNode("metricPluginType").getValue()
00315 << "\n";
00316 OUT << "level: " <<
00317 metric.second.getNode("metricLevel").getValue()
00318 << "\n";
00319
00320 auto metricParametersGroup = metric.second.getNode("metricParametersLink");
00321 if(!metricParametersGroup.isDisconnected())
00322 {
00323 auto metricParameters = metricParametersGroup.getChildren();
00324 for(auto &metricParameter:metricParameters)
00325 {
00326 if(!metricParameter.second.getNode("Enabled").getValue<bool>())
00327 PUSHCOMMENT;
00328
00329 OUT << metricParameter.second.getNode("metricParameterKey").getValue() <<
00330 ": " <<
00331 metricParameter.second.getNode("metricParameterValue").getValue()
00332 << "\n";
00333
00334 if(!metricParameter.second.getNode("Enabled").getValue<bool>())
00335 POPCOMMENT;
00336
00337 }
00338 }
00339 POPTAB;
00340 OUT << "}\n\n";
00341
00342 if(!metric.second.getNode("Status").getValue<bool>())
00343 POPCOMMENT;
00344 }
00345 }
00346 POPTAB;
00347 OUT << "}\n\n";
00348
00349 POPTAB;
00350 OUT << "}\n\n";
00351
00352
00353 out.close();
00354 }
00355
00356 DEFINE_OTS_CONFIGURATION(ARTDAQBoardReaderConfiguration)