1 #include "otsdaq-core/FECore/FEVInterfacesManager.h"
2 #include "otsdaq-core/MessageFacility/MessageFacility.h"
3 #include "otsdaq-core/Macros/CoutMacros.h"
4 #include "otsdaq-core/FECore/FEVInterface.h"
5 #include "otsdaq-core/PluginMakers/MakeInterface.h"
6 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
8 #include "messagefacility/MessageLogger/MessageLogger.h"
9 #include "artdaq-core/Utilities/configureMessageFacility.hh"
10 #include "artdaq/BuildInfo/GetPackageBuildInfo.hh"
11 #include "fhiclcpp/make_ParameterSet.h"
19 FEVInterfacesManager::FEVInterfacesManager(
const ConfigurationTree& theXDAQContextConfigTree,
const std::string& supervisorConfigurationPath)
20 :
Configurable(theXDAQContextConfigTree, supervisorConfigurationPath)
26 FEVInterfacesManager::~FEVInterfacesManager(
void)
32 void FEVInterfacesManager::init(
void)
37 void FEVInterfacesManager::destroy(
void)
39 for(
auto& it : theFEInterfaces_)
42 theFEInterfaces_.clear();
46 void FEVInterfacesManager::createInterfaces(
void)
50 __COUT__ <<
"Path: "<< theConfigurationPath_+
"/LinkToFEInterfaceConfiguration" << std::endl;
51 for(
const auto& interface: theXDAQContextConfigTree_.getNode(theConfigurationPath_+
"/LinkToFEInterfaceConfiguration").getChildren())
55 if(!interface.second.getNode(ViewColumnInfo::COL_NAME_STATUS).getValue<
bool>())
continue;
59 __COUT_INFO__ <<
"Ignoring FE Status since Status column is missing!" << std::endl;
62 __COUT__ <<
"Interface Plugin Name: "<< interface.second.getNode(
"FEInterfacePluginName").getValue<std::string>() << std::endl;
63 __COUT__ <<
"Interface Name: "<< interface.first << std::endl;
64 __COUT__ <<
"XDAQContext Node: "<< theXDAQContextConfigTree_ << std::endl;
65 __COUT__ <<
"Path to configuration: "<< (theConfigurationPath_ +
"/LinkToFEInterfaceConfiguration/" + interface.first +
"/LinkToFETypeConfiguration") << std::endl;
69 theFEInterfaces_[interface.first] = makeInterface(
70 interface.second.getNode(
"FEInterfacePluginName").getValue<std::string>(),
72 theXDAQContextConfigTree_,
73 (theConfigurationPath_ +
"/LinkToFEInterfaceConfiguration/" + interface.first +
"/LinkToFETypeConfiguration")
76 catch(
const cet::exception& e)
78 __SS__ <<
"Failed to instantiate plugin named '" <<
79 interface.first <<
"' of type '" <<
80 interface.second.getNode(
"FEInterfacePluginName").getValue<std::string>()
81 <<
"' due to the following error: \n" << e.what() << __E__;
82 __COUT_ERR__ << ss.str();
83 __MOUT_ERR__ << ss.str();
84 throw std::runtime_error(ss.str());
87 __COUT__ <<
"Done creating interfaces" << std::endl;
92 int FEVInterfacesManager::universalRead(
const std::string &interfaceID,
char* address,
char* returnValue)
94 if(theFEInterfaces_.find(interfaceID) == theFEInterfaces_.end())
96 __SS__ <<
"Interface ID '" << interfaceID <<
"' not found in configured interfaces." << __E__;
97 throw std::runtime_error(ss.str());
100 __COUT__ <<
"interfaceID: " << interfaceID <<
" and size: " << theFEInterfaces_.size() << std::endl;
102 if (theFEInterfaces_[interfaceID]->universalRead(address, returnValue) < 0)
return -1;
109 unsigned int FEVInterfacesManager::getInterfaceUniversalAddressSize(
const std::string &interfaceID)
111 if(theFEInterfaces_.find(interfaceID) == theFEInterfaces_.end())
113 __SS__ <<
"Interface ID '" << interfaceID <<
"' not found in configured interfaces." << __E__;
114 throw std::runtime_error(ss.str());
116 return theFEInterfaces_[interfaceID]->getUniversalAddressSize();
121 unsigned int FEVInterfacesManager::getInterfaceUniversalDataSize(
const std::string &interfaceID)
123 if(theFEInterfaces_.find(interfaceID) == theFEInterfaces_.end())
125 __SS__ <<
"Interface ID '" << interfaceID <<
"' not found in configured interfaces." << __E__;
126 throw std::runtime_error(ss.str());
128 return theFEInterfaces_[interfaceID]->getUniversalDataSize();
133 void FEVInterfacesManager::universalWrite(
const std::string &interfaceID,
char* address,
char* writeValue)
135 if(theFEInterfaces_.find(interfaceID) == theFEInterfaces_.end())
137 __SS__ <<
"Interface ID '" << interfaceID <<
"' not found in configured interfaces." << __E__;
138 throw std::runtime_error(ss.str());
141 __COUT__ <<
"interfaceID: " << interfaceID <<
" and size: " << theFEInterfaces_.size() << std::endl;
143 theFEInterfaces_[interfaceID]->universalWrite(address, writeValue);
159 std::string FEVInterfacesManager::getFEListString(
const std::string &supervisorLid)
161 std::string retList =
"";
163 for(
const auto& it : theFEInterfaces_)
165 __COUT__ <<
"FE name = " << it.first << std::endl;
167 retList += it.second->getInterfaceType() +
168 ":" + supervisorLid +
":" +
169 it.second->getInterfaceUID() +
"\n";
185 void FEVInterfacesManager::runFEMacro(
const std::string &interfaceID,
186 const std::string &feMacroName,
const std::string &inputArgs, std::string &outputArgs)
189 auto FEVInterfaceIt = theFEInterfaces_.find(interfaceID);
190 if(FEVInterfaceIt == theFEInterfaces_.end())
192 __SS__ <<
"interfaceID '" << interfaceID <<
"' was not found!" << std::endl;
193 __COUT_ERR__ <<
"\n" << ss.str();
194 throw std::runtime_error(ss.str());
198 auto FEMacroIt = FEVInterfaceIt->second->getMapOfFEMacroFunctions().find(feMacroName);
199 if(FEMacroIt == FEVInterfaceIt->second->getMapOfFEMacroFunctions().end())
201 __SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" <<
202 interfaceID <<
"' was not found!" << std::endl;
203 __COUT_ERR__ <<
"\n" << ss.str();
204 throw std::runtime_error(ss.str());
209 std::vector<FEVInterface::frontEndMacroInArg_t> argsIn;
211 std::istringstream inputStream(inputArgs);
212 std::string splitVal, argName, argValue;
213 while (getline(inputStream, splitVal,
';'))
215 std::istringstream pairInputStream(splitVal);
216 getline(pairInputStream, argName,
',');
217 getline(pairInputStream, argValue,
',');
218 argsIn.push_back(std::pair<std::string,std::string>(argName,argValue));
223 if(FEMacroIt->second.namesOfInputArguments_.size() != argsIn.size())
225 __SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" <<
226 interfaceID <<
"' was attempted with a mismatch in" <<
227 " number of input arguments. " << argsIn.size() <<
228 " were given. " << FEMacroIt->second.namesOfInputArguments_.size() <<
229 " expected." << std::endl;
230 __COUT_ERR__ <<
"\n" << ss.str();
231 throw std::runtime_error(ss.str());
233 for(
unsigned int i=0;i<argsIn.size();++i)
234 if(argsIn[i].first != FEMacroIt->second.namesOfInputArguments_[i])
236 __SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" <<
237 interfaceID <<
"' was attempted with a mismatch in" <<
238 " a name of an input argument. " <<
239 argsIn[i].first <<
" were given. " <<
240 FEMacroIt->second.namesOfInputArguments_[i] <<
241 " expected." << std::endl;
242 __COUT_ERR__ <<
"\n" << ss.str();
243 throw std::runtime_error(ss.str());
249 std::vector<std::string> returnStrings;
250 std::vector<FEVInterface::frontEndMacroOutArg_t> argsOut;
253 std::istringstream inputStream(outputArgs);
255 while (getline(inputStream, argName,
','))
257 __COUT__ <<
"argName " << argName << std::endl;
259 returnStrings.push_back(
"DEFAULT" );
260 argsOut.push_back(FEVInterface::frontEndMacroOutArg_t(
262 returnStrings[returnStrings.size()-1]));
265 __COUT__ << (uint64_t) &(returnStrings[returnStrings.size()-1]) << std::endl;
270 if(FEMacroIt->second.namesOfOutputArguments_.size() != argsOut.size())
272 __SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" <<
273 interfaceID <<
"' was attempted with a mismatch in" <<
274 " number of output arguments. " << argsOut.size() <<
275 " were given. " << FEMacroIt->second.namesOfOutputArguments_.size() <<
276 " expected." << std::endl;
277 __COUT_ERR__ <<
"\n" << ss.str();
278 throw std::runtime_error(ss.str());
280 for(
unsigned int i=0;i<argsOut.size();++i)
281 if(argsOut[i].first != FEMacroIt->second.namesOfOutputArguments_[i])
283 __SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" <<
284 interfaceID <<
"' was attempted with a mismatch in" <<
285 " a name of an output argument. " <<
286 argsOut[i].first <<
" were given. " <<
287 FEMacroIt->second.namesOfOutputArguments_[i] <<
288 " expected." << std::endl;
289 __COUT_ERR__ <<
"\n" << ss.str();
290 throw std::runtime_error(ss.str());
298 __COUT__ <<
"# of input args = " << argsIn.size() << std::endl;
299 for(
auto &argIn:argsIn)
300 __COUT__ << argIn.first <<
": " << argIn.second << std::endl;
311 __MOUT__ <<
"Launching FE Macro '" << feMacroName <<
"' ..." << std::endl;
312 __COUT__ <<
"Launching FE Macro '" << feMacroName <<
"' ..." << std::endl;
315 (FEVInterfaceIt->second.get()->*(FEMacroIt->second.macroFunction_))(argsIn,argsOut);
317 __COUT__ <<
"FE Macro complete!" << std::endl;
319 __COUT__ <<
"# of output args = " << argsOut.size() << std::endl;
320 for(
const auto &arg:argsOut)
321 __COUT__ << arg.first <<
": " << arg.second << std::endl;
328 if(FEMacroIt->second.namesOfOutputArguments_.size() != argsOut.size())
330 __SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" <<
331 interfaceID <<
"' was attempted but the FE macro "
332 "manipulated the output arguments vector. It is illegal "
333 "to add or remove output vector name/value pairs." << std::endl;
334 __COUT_ERR__ <<
"\n" << ss.str();
335 throw std::runtime_error(ss.str());
342 for(
unsigned int i=0; i<argsOut.size(); ++i)
344 if(i) outputArgs +=
";";
345 outputArgs += argsOut[i].first +
"," + argsOut[i].second;
348 __COUT__ <<
"outputArgs = " << outputArgs << std::endl;
359 std::string FEVInterfacesManager::getFEMacrosString(
const std::string &supervisorLid)
361 std::string retList =
"";
363 for(
const auto& it : theFEInterfaces_)
365 __COUT__ <<
"FE interface UID = " << it.first << std::endl;
367 retList += it.second->getInterfaceType() +
368 ":" + supervisorLid +
":" +
369 it.second->getInterfaceUID();
371 for(
const auto& macroPair : it.second->getMapOfFEMacroFunctions())
373 __COUT__ <<
"FE Macro name = " << macroPair.first << std::endl;
375 ":" + macroPair.first +
376 ":" + std::to_string(macroPair.second.requiredUserPermissions_) +
377 ":" + std::to_string(macroPair.second.namesOfInputArguments_.size());
378 for(
const auto& name:macroPair.second.namesOfInputArguments_)
379 retList +=
":" + name;
382 ":" + std::to_string(macroPair.second.namesOfOutputArguments_.size());
383 for(
const auto& name:macroPair.second.namesOfOutputArguments_)
384 retList +=
":" + name;
393 bool FEVInterfacesManager::allFEWorkloopsAreDone(
void)
395 bool allFEWorkloopsAreDone =
true;
398 for(
const auto& FEInterface: theFEInterfaces_)
400 isActive = FEInterface.second->isActive();
401 __COUT__ << FEInterface.second->getInterfaceUID() <<
" of type " <<
402 FEInterface.second->getInterfaceType() <<
": \t" <<
403 "workLoop_->isActive() " <<
404 (isActive?
"yes":
"no") << std::endl;
408 allFEWorkloopsAreDone =
false;
413 return allFEWorkloopsAreDone;
417 void FEVInterfacesManager::configure(
void)
420 for(
const auto& it : theFEInterfaces_)
425 __COUT__ <<
"Configuring interface " << it.first << std::endl;
426 __COUT__ <<
"Configuring interface " << it.first << std::endl;
427 __COUT__ <<
"Configuring interface " << it.first << std::endl;
429 it.second->configure();
439 __COUT__ <<
"Done configuring interface " << it.first << std::endl;
440 __COUT__ <<
"Done configuring interface " << it.first << std::endl;
441 __COUT__ <<
"Done configuring interface " << it.first << std::endl;
449 __COUT__ <<
"Done Configure" << std::endl;
453 void FEVInterfacesManager::halt(
void)
455 for(
const auto& it : theFEInterfaces_)
458 it.second->stopWorkLoop();
466 void FEVInterfacesManager::pause(
void)
468 for(
const auto& it : theFEInterfaces_)
471 it.second->stopWorkLoop();
476 void FEVInterfacesManager::resume(
void)
478 for(
const auto& it : theFEInterfaces_)
481 it.second->startWorkLoop();
486 void FEVInterfacesManager::start(std::string runNumber)
488 for(
const auto& it : theFEInterfaces_)
490 it.second->start(runNumber);
491 it.second->startWorkLoop();
495 void FEVInterfacesManager::stop(
void)
497 for(
const auto& it : theFEInterfaces_)
499 it.second->stopWorkLoop();