00001 #include "otsdaq-core/FECore/FEVInterfacesManager.h"
00002 #include "otsdaq-core/MessageFacility/MessageFacility.h"
00003 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
00004 #include "otsdaq-core/FECore/FEVInterface.h"
00005 #include "otsdaq-core/PluginMakers/MakeInterface.h"
00006 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
00007 #include "otsdaq-core/ConfigurationDataFormats/FEInterfaceConfigurationBase.h"
00008 #include "otsdaq-core/ConfigurationPluginDataFormats/FEConfiguration.h"
00009
00010 #include "messagefacility/MessageLogger/MessageLogger.h"
00011 #include "artdaq/DAQdata/configureMessageFacility.hh"
00012 #include "artdaq/BuildInfo/GetPackageBuildInfo.hh"
00013 #include "fhiclcpp/make_ParameterSet.h"
00014
00015 #include <iostream>
00016 #include <sstream>
00017
00018 using namespace ots;
00019
00020
00021 FEVInterfacesManager::FEVInterfacesManager(const ConfigurationTree& theXDAQContextConfigTree, const std::string& supervisorConfigurationPath)
00022 : Configurable(theXDAQContextConfigTree, supervisorConfigurationPath)
00023 {
00024 init();
00025 }
00026
00027
00028 FEVInterfacesManager::~FEVInterfacesManager(void)
00029 {
00030 destroy();
00031 }
00032
00033
00034 void FEVInterfacesManager::init(void)
00035 {
00036 }
00037
00038
00039 void FEVInterfacesManager::destroy(void)
00040 {
00041 for(auto& it : theFEInterfaces_)
00042 it.second.reset();
00043
00044 theFEInterfaces_.clear();
00045 }
00046
00047
00048 void FEVInterfacesManager::createInterfaces(void)
00049 {
00050 destroy();
00051
00052 __MOUT__ << "Path: "<< theConfigurationPath_+"/LinkToFEInterfaceConfiguration" << std::endl;
00053 for(const auto& interface: theXDAQContextConfigTree_.getNode(theConfigurationPath_+"/LinkToFEInterfaceConfiguration").getChildren())
00054 {
00055 try
00056 {
00057 if(!interface.second.getNode("Status").getValue<bool>()) continue;
00058 }
00059 catch(...)
00060 {
00061 __MOUT_INFO__ << "Ignoring FE Status since Status column is missing!" << std::endl;
00062 }
00063
00064 __MOUT__ << "Interface Plugin Name: "<< interface.second.getNode("FEInterfacePluginName").getValue<std::string>() << std::endl;
00065 __MOUT__ << "Interface Name: "<< interface.first << std::endl;
00066 __MOUT__ << "XDAQContext Node: "<< theXDAQContextConfigTree_ << std::endl;
00067 __MOUT__ << "Path to configuration: "<< (theConfigurationPath_ + "/LinkToFEInterfaceConfiguration/" + interface.first + "/LinkToFETypeConfiguration") << std::endl;
00068 theFEInterfaces_[interface.first] = makeInterface(
00069 interface.second.getNode("FEInterfacePluginName").getValue<std::string>(),
00070 interface.first,
00071 theXDAQContextConfigTree_,
00072 (theConfigurationPath_ + "/LinkToFEInterfaceConfiguration/" + interface.first + "/LinkToFETypeConfiguration")
00073 );
00074 }
00075 __MOUT__ << "Done creating interfaces" << std::endl;
00076 }
00077
00078
00079
00080 int FEVInterfacesManager::universalRead(const std::string &interfaceID, char* address, char* returnValue)
00081 {
00082 __MOUT__ << "interfaceID: " << interfaceID << " and size: " << theFEInterfaces_.size() << std::endl;
00083
00084 if (theFEInterfaces_[interfaceID]->universalRead(address, returnValue) < 0) return -1;
00085 return 0;
00086 }
00087
00088
00089
00090
00091 unsigned int FEVInterfacesManager::getInterfaceUniversalAddressSize(const std::string &interfaceID)
00092 { return theFEInterfaces_[interfaceID]->getUniversalAddressSize(); }
00093
00094
00095
00096 unsigned int FEVInterfacesManager::getInterfaceUniversalDataSize(const std::string &interfaceID)
00097 { return theFEInterfaces_[interfaceID]->getUniversalDataSize(); }
00098
00099
00100
00101 void FEVInterfacesManager::universalWrite(const std::string &interfaceID, char* address, char* writeValue)
00102 {
00103
00104 __MOUT__ << "interfaceID: " << interfaceID << " and size: " << theFEInterfaces_.size() << std::endl;
00105
00106 theFEInterfaces_[interfaceID]->universalWrite(address, writeValue);
00107
00108
00109
00110
00111
00112
00113
00114
00115 }
00116
00117
00118
00119
00120
00121
00122 std::string FEVInterfacesManager::getFEListString(const std::string &supervisorLid)
00123 {
00124 std::string retList = "";
00125
00126 for(const auto& it : theFEInterfaces_)
00127 {
00128 __MOUT__ << "Just curious: it.first is " << it.first << std::endl;
00129
00130 retList += it.second->getInterfaceType() +
00131 ":" + supervisorLid + ":" +
00132 it.second->getInterfaceUID() + "\n";
00133 }
00134 return retList;
00135 }
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 void FEVInterfacesManager::runFEMacro(const std::string &interfaceID,
00149 const std::string &feMacroName, const std::string &inputArgs, std::string &outputArgs)
00150 {
00151
00152 auto FEVInterfaceIt = theFEInterfaces_.find(interfaceID);
00153 if(FEVInterfaceIt == theFEInterfaces_.end())
00154 {
00155 __SS__ << "interfaceID '" << interfaceID << "' was not found!" << std::endl;
00156 __MOUT_ERR__ << "\n" << ss.str();
00157 throw std::runtime_error(ss.str());
00158 }
00159
00160
00161 auto FEMacroIt = FEVInterfaceIt->second->getMapOfFEMacroFunctions().find(feMacroName);
00162 if(FEMacroIt == FEVInterfaceIt->second->getMapOfFEMacroFunctions().end())
00163 {
00164 __SS__ << "FE Macro '" << feMacroName << "' of interfaceID '" <<
00165 interfaceID << "' was not found!" << std::endl;
00166 __MOUT_ERR__ << "\n" << ss.str();
00167 throw std::runtime_error(ss.str());
00168 }
00169
00170
00171
00172 std::vector<FEVInterface::frontEndMacroInArg_t> argsIn;
00173 {
00174 std::istringstream inputStream(inputArgs);
00175 std::string splitVal, argName, argValue;
00176 while (getline(inputStream, splitVal, ';'))
00177 {
00178 std::istringstream pairInputStream(splitVal);
00179 getline(pairInputStream, argName, ',');
00180 getline(pairInputStream, argValue, ',');
00181 argsIn.push_back(std::pair<std::string,std::string>(argName,argValue));
00182 }
00183 }
00184
00185
00186 if(FEMacroIt->second.namesOfInputArguments_.size() != argsIn.size())
00187 {
00188 __SS__ << "FE Macro '" << feMacroName << "' of interfaceID '" <<
00189 interfaceID << "' was attempted with a mismatch in" <<
00190 " number of input arguments. " << argsIn.size() <<
00191 " were given. " << FEMacroIt->second.namesOfInputArguments_.size() <<
00192 " expected." << std::endl;
00193 __MOUT_ERR__ << "\n" << ss.str();
00194 throw std::runtime_error(ss.str());
00195 }
00196 for(unsigned int i=0;i<argsIn.size();++i)
00197 if(argsIn[i].first != FEMacroIt->second.namesOfInputArguments_[i])
00198 {
00199 __SS__ << "FE Macro '" << feMacroName << "' of interfaceID '" <<
00200 interfaceID << "' was attempted with a mismatch in" <<
00201 " a name of an input argument. " <<
00202 argsIn[i].first << " were given. " <<
00203 FEMacroIt->second.namesOfInputArguments_[i] <<
00204 " expected." << std::endl;
00205 __MOUT_ERR__ << "\n" << ss.str();
00206 throw std::runtime_error(ss.str());
00207 }
00208
00209
00210
00211
00212 std::vector<std::string> returnStrings;
00213 std::vector<FEVInterface::frontEndMacroOutArg_t> argsOut;
00214
00215 {
00216 std::istringstream inputStream(outputArgs);
00217 std::string argName;
00218 while (getline(inputStream, argName, ','))
00219 {
00220 __MOUT__ << "argName " << argName << std::endl;
00221
00222 returnStrings.push_back( "valueLore" );
00223 argsOut.push_back(FEVInterface::frontEndMacroOutArg_t(
00224 argName,
00225 returnStrings[returnStrings.size()-1]));
00226
00227
00228 __MOUT__ << (uint64_t) &(returnStrings[returnStrings.size()-1]) << std::endl;
00229 }
00230 }
00231
00232
00233 if(FEMacroIt->second.namesOfOutputArguments_.size() != argsOut.size())
00234 {
00235 __SS__ << "FE Macro '" << feMacroName << "' of interfaceID '" <<
00236 interfaceID << "' was attempted with a mismatch in" <<
00237 " number of output arguments. " << argsOut.size() <<
00238 " were given. " << FEMacroIt->second.namesOfOutputArguments_.size() <<
00239 " expected." << std::endl;
00240 __MOUT_ERR__ << "\n" << ss.str();
00241 throw std::runtime_error(ss.str());
00242 }
00243 for(unsigned int i=0;i<argsOut.size();++i)
00244 if(argsOut[i].first != FEMacroIt->second.namesOfOutputArguments_[i])
00245 {
00246 __SS__ << "FE Macro '" << feMacroName << "' of interfaceID '" <<
00247 interfaceID << "' was attempted with a mismatch in" <<
00248 " a name of an output argument. " <<
00249 argsOut[i].first << " were given. " <<
00250 FEMacroIt->second.namesOfOutputArguments_[i] <<
00251 " expected." << std::endl;
00252 __MOUT_ERR__ << "\n" << ss.str();
00253 throw std::runtime_error(ss.str());
00254 }
00255
00256
00257
00258
00259
00260
00261 __MOUT__ << "# of input args = " << argsIn.size() << std::endl;
00262 for(auto &argIn:argsIn)
00263 __MOUT__ << argIn.first << ": " << argIn.second << std::endl;
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274 __MOUT__ << "Trying it " << std::endl;
00275
00276
00277 (FEVInterfaceIt->second.get()->*(FEMacroIt->second.macroFunction_))(argsIn,argsOut);
00278
00279 __MOUT__ << "Made it " << std::endl;
00280
00281 __MOUT__ << "# of output args = " << argsOut.size() << std::endl;
00282 for(const auto &arg:argsOut)
00283 __MOUT__ << arg.first << ": " << arg.second << std::endl;
00284
00285
00286
00287
00288
00289
00290 if(FEMacroIt->second.namesOfOutputArguments_.size() != argsOut.size())
00291 {
00292 __SS__ << "FE Macro '" << feMacroName << "' of interfaceID '" <<
00293 interfaceID << "' was attempted but the FE macro "
00294 "manipulated the output arguments vector. It is illegal "
00295 "to add or remove output vector name/value pairs." << std::endl;
00296 __MOUT_ERR__ << "\n" << ss.str();
00297 throw std::runtime_error(ss.str());
00298 }
00299
00300
00301
00302
00303 outputArgs = "";
00304 for(unsigned int i=0; i<argsOut.size(); ++i)
00305 {
00306 if(i) outputArgs += ";";
00307 outputArgs += argsOut[i].first + "," + argsOut[i].second;
00308 }
00309
00310 __MOUT__ << "outputArgs = " << outputArgs << std::endl;
00311
00312 }
00313
00314
00315
00316
00317
00318
00319
00320
00321 std::string FEVInterfacesManager::getFEMacrosString(const std::string &supervisorLid)
00322 {
00323 std::string retList = "";
00324
00325 for(const auto& it : theFEInterfaces_)
00326 {
00327 __MOUT__ << "FE interface UID = " << it.first << std::endl;
00328
00329 retList += it.second->getInterfaceType() +
00330 ":" + supervisorLid + ":" +
00331 it.second->getInterfaceUID();
00332
00333 for(const auto& macroPair : it.second->getMapOfFEMacroFunctions())
00334 {
00335 __MOUT__ << "FE Macro name = " << macroPair.first << std::endl;
00336 retList +=
00337 ":" + macroPair.first +
00338 ":" + std::to_string(macroPair.second.requiredUserPermissions_) +
00339 ":" + std::to_string(macroPair.second.namesOfInputArguments_.size());
00340 for(const auto& name:macroPair.second.namesOfInputArguments_)
00341 retList += ":" + name;
00342
00343 retList +=
00344 ":" + std::to_string(macroPair.second.namesOfOutputArguments_.size());
00345 for(const auto& name:macroPair.second.namesOfOutputArguments_)
00346 retList += ":" + name;
00347 }
00348
00349 retList += "\n";
00350 }
00351 return retList;
00352 }
00353
00354
00355
00356 void FEVInterfacesManager::configure(void)
00357 {
00358 createInterfaces();
00359 for(const auto& it : theFEInterfaces_)
00360 {
00361
00362
00363
00364 __MOUT__ << "Configuring interface " << it.first << std::endl;
00365 __MOUT__ << "Configuring interface " << it.first << std::endl;
00366 __MOUT__ << "Configuring interface " << it.first << std::endl;
00367 it.second->configure();
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377 __MOUT__ << "Done configuring interface " << it.first << std::endl;
00378 __MOUT__ << "Done configuring interface " << it.first << std::endl;
00379 __MOUT__ << "Done configuring interface " << it.first << std::endl;
00380
00381
00382
00383
00384 }
00385
00386
00387 __MOUT__ << "Done Configure" << std::endl;
00388 }
00389
00390
00391 void FEVInterfacesManager::halt(void)
00392 {
00393 for(const auto& it : theFEInterfaces_)
00394 {
00395 it.second->halt();
00396 it.second->stopWorkLoop();
00397
00398 }
00399
00400 destroy();
00401 }
00402
00403
00404 void FEVInterfacesManager::pause(void)
00405 {
00406 for(const auto& it : theFEInterfaces_)
00407 {
00408 it.second->pause();
00409 it.second->stopWorkLoop();
00410 }
00411 }
00412
00413
00414 void FEVInterfacesManager::resume(void)
00415 {
00416 for(const auto& it : theFEInterfaces_)
00417 {
00418 it.second->resume();
00419 it.second->startWorkLoop();
00420 }
00421 }
00422
00423
00424 void FEVInterfacesManager::start(std::string runNumber)
00425 {
00426 for(const auto& it : theFEInterfaces_)
00427 {
00428 it.second->start(runNumber);
00429 it.second->startWorkLoop();
00430 }
00431 }
00432
00433 void FEVInterfacesManager::stop(void)
00434 {
00435 for(const auto& it : theFEInterfaces_)
00436 {
00437 it.second->stopWorkLoop();
00438 it.second->stop();
00439 }
00440 }