1 #include "otsdaq-core/FECore/FEVInterfacesManager.h"
2 #include "otsdaq-core/MessageFacility/MessageFacility.h"
3 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
4 #include "otsdaq-core/FECore/FEVInterface.h"
5 #include "otsdaq-core/PluginMakers/MakeInterface.h"
6 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
7 #include "otsdaq-core/ConfigurationDataFormats/FEInterfaceConfigurationBase.h"
8 #include "otsdaq-core/ConfigurationPluginDataFormats/FEConfiguration.h"
10 #include "messagefacility/MessageLogger/MessageLogger.h"
11 #include "artdaq/DAQdata/configureMessageFacility.hh"
12 #include "artdaq/BuildInfo/GetPackageBuildInfo.hh"
13 #include "fhiclcpp/make_ParameterSet.h"
21 FEVInterfacesManager::FEVInterfacesManager(
const ConfigurationTree& theXDAQContextConfigTree,
const std::string& supervisorConfigurationPath)
22 :
Configurable(theXDAQContextConfigTree, supervisorConfigurationPath)
28 FEVInterfacesManager::~FEVInterfacesManager(
void)
34 void FEVInterfacesManager::init(
void)
39 void FEVInterfacesManager::destroy(
void)
41 for(
auto& it : theFEInterfaces_)
44 theFEInterfaces_.clear();
48 void FEVInterfacesManager::createInterfaces(
void)
52 __MOUT__ <<
"Path: "<< theConfigurationPath_+
"/LinkToFEInterfaceConfiguration" << std::endl;
53 for(
const auto& interface: theXDAQContextConfigTree_.getNode(theConfigurationPath_+
"/LinkToFEInterfaceConfiguration").getChildren())
57 if(!interface.second.getNode(
"Status").getValue<
bool>())
continue;
61 __MOUT_INFO__ <<
"Ignoring FE Status since Status column is missing!" << std::endl;
64 __MOUT__ <<
"Interface Plugin Name: "<< interface.second.getNode(
"FEInterfacePluginName").getValue<std::string>() << std::endl;
65 __MOUT__ <<
"Interface Name: "<< interface.first << std::endl;
66 __MOUT__ <<
"XDAQContext Node: "<< theXDAQContextConfigTree_ << std::endl;
67 __MOUT__ <<
"Path to configuration: "<< (theConfigurationPath_ +
"/LinkToFEInterfaceConfiguration/" + interface.first +
"/LinkToFETypeConfiguration") << std::endl;
68 theFEInterfaces_[interface.first] = makeInterface(
69 interface.second.getNode(
"FEInterfacePluginName").getValue<std::string>(),
71 theXDAQContextConfigTree_,
72 (theConfigurationPath_ +
"/LinkToFEInterfaceConfiguration/" + interface.first +
"/LinkToFETypeConfiguration")
75 __MOUT__ <<
"Done creating interfaces" << std::endl;
80 int FEVInterfacesManager::universalRead(
const std::string &interfaceID,
char* address,
char* returnValue)
82 __MOUT__ <<
"interfaceID: " << interfaceID <<
" and size: " << theFEInterfaces_.size() << std::endl;
84 if (theFEInterfaces_[interfaceID]->universalRead(address, returnValue) < 0)
return -1;
91 unsigned int FEVInterfacesManager::getInterfaceUniversalAddressSize(
const std::string &interfaceID)
92 {
return theFEInterfaces_[interfaceID]->getUniversalAddressSize(); }
96 unsigned int FEVInterfacesManager::getInterfaceUniversalDataSize(
const std::string &interfaceID)
97 {
return theFEInterfaces_[interfaceID]->getUniversalDataSize(); }
101 void FEVInterfacesManager::universalWrite(
const std::string &interfaceID,
char* address,
char* writeValue)
104 __MOUT__ <<
"interfaceID: " << interfaceID <<
" and size: " << theFEInterfaces_.size() << std::endl;
106 theFEInterfaces_[interfaceID]->universalWrite(address, writeValue);
122 std::string FEVInterfacesManager::getFEListString(
const std::string &supervisorLid)
124 std::string retList =
"";
126 for(
const auto& it : theFEInterfaces_)
128 __MOUT__ <<
"Just curious: it.first is " << it.first << std::endl;
130 retList += it.second->getInterfaceType() +
131 ":" + supervisorLid +
":" +
132 it.second->getInterfaceUID() +
"\n";
148 void FEVInterfacesManager::runFEMacro(
const std::string &interfaceID,
149 const std::string &feMacroName,
const std::string &inputArgs, std::string &outputArgs)
152 auto FEVInterfaceIt = theFEInterfaces_.find(interfaceID);
153 if(FEVInterfaceIt == theFEInterfaces_.end())
155 __SS__ <<
"interfaceID '" << interfaceID <<
"' was not found!" << std::endl;
156 __MOUT_ERR__ <<
"\n" << ss.str();
157 throw std::runtime_error(ss.str());
161 auto FEMacroIt = FEVInterfaceIt->second->getMapOfFEMacroFunctions().find(feMacroName);
162 if(FEMacroIt == FEVInterfaceIt->second->getMapOfFEMacroFunctions().end())
164 __SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" <<
165 interfaceID <<
"' was not found!" << std::endl;
166 __MOUT_ERR__ <<
"\n" << ss.str();
167 throw std::runtime_error(ss.str());
172 std::vector<FEVInterface::frontEndMacroInArg_t> argsIn;
174 std::istringstream inputStream(inputArgs);
175 std::string splitVal, argName, argValue;
176 while (getline(inputStream, splitVal,
';'))
178 std::istringstream pairInputStream(splitVal);
179 getline(pairInputStream, argName,
',');
180 getline(pairInputStream, argValue,
',');
181 argsIn.push_back(std::pair<std::string,std::string>(argName,argValue));
186 if(FEMacroIt->second.namesOfInputArguments_.size() != argsIn.size())
188 __SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" <<
189 interfaceID <<
"' was attempted with a mismatch in" <<
190 " number of input arguments. " << argsIn.size() <<
191 " were given. " << FEMacroIt->second.namesOfInputArguments_.size() <<
192 " expected." << std::endl;
193 __MOUT_ERR__ <<
"\n" << ss.str();
194 throw std::runtime_error(ss.str());
196 for(
unsigned int i=0;i<argsIn.size();++i)
197 if(argsIn[i].first != FEMacroIt->second.namesOfInputArguments_[i])
199 __SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" <<
200 interfaceID <<
"' was attempted with a mismatch in" <<
201 " a name of an input argument. " <<
202 argsIn[i].first <<
" were given. " <<
203 FEMacroIt->second.namesOfInputArguments_[i] <<
204 " expected." << std::endl;
205 __MOUT_ERR__ <<
"\n" << ss.str();
206 throw std::runtime_error(ss.str());
212 std::vector<std::string> returnStrings;
213 std::vector<FEVInterface::frontEndMacroOutArg_t> argsOut;
216 std::istringstream inputStream(outputArgs);
218 while (getline(inputStream, argName,
','))
220 __MOUT__ <<
"argName " << argName << std::endl;
222 returnStrings.push_back(
"valueLore" );
223 argsOut.push_back(FEVInterface::frontEndMacroOutArg_t(
225 returnStrings[returnStrings.size()-1]));
228 __MOUT__ << (uint64_t) &(returnStrings[returnStrings.size()-1]) << std::endl;
233 if(FEMacroIt->second.namesOfOutputArguments_.size() != argsOut.size())
235 __SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" <<
236 interfaceID <<
"' was attempted with a mismatch in" <<
237 " number of output arguments. " << argsOut.size() <<
238 " were given. " << FEMacroIt->second.namesOfOutputArguments_.size() <<
239 " expected." << std::endl;
240 __MOUT_ERR__ <<
"\n" << ss.str();
241 throw std::runtime_error(ss.str());
243 for(
unsigned int i=0;i<argsOut.size();++i)
244 if(argsOut[i].first != FEMacroIt->second.namesOfOutputArguments_[i])
246 __SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" <<
247 interfaceID <<
"' was attempted with a mismatch in" <<
248 " a name of an output argument. " <<
249 argsOut[i].first <<
" were given. " <<
250 FEMacroIt->second.namesOfOutputArguments_[i] <<
251 " expected." << std::endl;
252 __MOUT_ERR__ <<
"\n" << ss.str();
253 throw std::runtime_error(ss.str());
261 __MOUT__ <<
"# of input args = " << argsIn.size() << std::endl;
262 for(
auto &argIn:argsIn)
263 __MOUT__ << argIn.first <<
": " << argIn.second << std::endl;
274 __MOUT__ <<
"Trying it " << std::endl;
277 (FEVInterfaceIt->second.get()->*(FEMacroIt->second.macroFunction_))(argsIn,argsOut);
279 __MOUT__ <<
"Made it " << std::endl;
281 __MOUT__ <<
"# of output args = " << argsOut.size() << std::endl;
282 for(
const auto &arg:argsOut)
283 __MOUT__ << arg.first <<
": " << arg.second << std::endl;
290 if(FEMacroIt->second.namesOfOutputArguments_.size() != argsOut.size())
292 __SS__ <<
"FE Macro '" << feMacroName <<
"' of interfaceID '" <<
293 interfaceID <<
"' was attempted but the FE macro "
294 "manipulated the output arguments vector. It is illegal "
295 "to add or remove output vector name/value pairs." << std::endl;
296 __MOUT_ERR__ <<
"\n" << ss.str();
297 throw std::runtime_error(ss.str());
304 for(
unsigned int i=0; i<argsOut.size(); ++i)
306 if(i) outputArgs +=
";";
307 outputArgs += argsOut[i].first +
"," + argsOut[i].second;
310 __MOUT__ <<
"outputArgs = " << outputArgs << std::endl;
321 std::string FEVInterfacesManager::getFEMacrosString(
const std::string &supervisorLid)
323 std::string retList =
"";
325 for(
const auto& it : theFEInterfaces_)
327 __MOUT__ <<
"FE interface UID = " << it.first << std::endl;
329 retList += it.second->getInterfaceType() +
330 ":" + supervisorLid +
":" +
331 it.second->getInterfaceUID();
333 for(
const auto& macroPair : it.second->getMapOfFEMacroFunctions())
335 __MOUT__ <<
"FE Macro name = " << macroPair.first << std::endl;
337 ":" + macroPair.first +
338 ":" + std::to_string(macroPair.second.requiredUserPermissions_) +
339 ":" + std::to_string(macroPair.second.namesOfInputArguments_.size());
340 for(
const auto& name:macroPair.second.namesOfInputArguments_)
341 retList +=
":" + name;
344 ":" + std::to_string(macroPair.second.namesOfOutputArguments_.size());
345 for(
const auto& name:macroPair.second.namesOfOutputArguments_)
346 retList +=
":" + name;
356 void FEVInterfacesManager::configure(
void)
359 for(
const auto& it : theFEInterfaces_)
364 __MOUT__ <<
"Configuring interface " << it.first << std::endl;
365 __MOUT__ <<
"Configuring interface " << it.first << std::endl;
366 __MOUT__ <<
"Configuring interface " << it.first << std::endl;
367 it.second->configure();
377 __MOUT__ <<
"Done configuring interface " << it.first << std::endl;
378 __MOUT__ <<
"Done configuring interface " << it.first << std::endl;
379 __MOUT__ <<
"Done configuring interface " << it.first << std::endl;
385 __MOUT__ <<
"Done Configure" << std::endl;
389 void FEVInterfacesManager::halt(
void)
391 for(
const auto& it : theFEInterfaces_)
394 it.second->stopWorkLoop();
402 void FEVInterfacesManager::pause(
void)
404 for(
const auto& it : theFEInterfaces_)
407 it.second->stopWorkLoop();
412 void FEVInterfacesManager::resume(
void)
414 for(
const auto& it : theFEInterfaces_)
417 it.second->startWorkLoop();
422 void FEVInterfacesManager::start(std::string runNumber)
424 for(
const auto& it : theFEInterfaces_)
426 it.second->start(runNumber);
427 it.second->startWorkLoop();
431 void FEVInterfacesManager::stop(
void)
433 for(
const auto& it : theFEInterfaces_)
435 it.second->stopWorkLoop();