1 #include "otsdaq-core/SupervisorInfo/AllSupervisorInfo.h"
3 #include "otsdaq-core/Macros/CoutMacros.h"
4 #include "otsdaq-core/MessageFacility/MessageFacility.h"
6 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
7 #include "otsdaq-core/TablePluginDataFormats/XDAQContextTable.h"
13 const bool AllSupervisorInfo::MACROMAKER_MODE =
14 (std::string(__ENV__(
"MACROMAKER_MODE")) ==
"1") ?
true :
false;
17 AllSupervisorInfo::AllSupervisorInfo(
void) : theSupervisorInfo_(0), theWizardInfo_(0) {}
20 AllSupervisorInfo::AllSupervisorInfo(xdaq::ApplicationContext* applicationContext)
23 init(applicationContext);
27 AllSupervisorInfo::~AllSupervisorInfo(
void) { destroy(); }
30 void AllSupervisorInfo::destroy(
void)
32 allSupervisorInfo_.clear();
33 allFETypeSupervisorInfo_.clear();
34 allDMTypeSupervisorInfo_.clear();
36 theSupervisorInfo_ = 0;
39 SupervisorDescriptorInfoBase::destroy();
45 __COUT__ <<
"Initializing info based on XDAQ context..." << __E__;
47 AllSupervisorInfo::destroy();
48 SupervisorDescriptorInfoBase::init(applicationContext);
50 auto allDescriptors = SupervisorDescriptorInfoBase::getAllDescriptors();
71 bool isWizardMode =
false;
75 for(
const auto& descriptor : allDescriptors)
84 if(tempSupervisorInfo.isGatewaySupervisor())
90 else if(tempSupervisorInfo.isWizardSupervisor())
98 if(AllSupervisorInfo::MACROMAKER_MODE)
99 __COUT__ <<
"Initializing info for Macro Maker mode XDAQ context..." << __E__;
100 else if(isWizardMode)
101 __COUT__ <<
"Initializing info for Wiz mode XDAQ context..." << __E__;
103 __COUT__ <<
"Initializing info for Normal mode XDAQ context..." << __E__;
104 std::unique_ptr<ConfigurationManager> cfgMgr(
105 (isWizardMode || AllSupervisorInfo::MACROMAKER_MODE)
109 (isWizardMode || AllSupervisorInfo::MACROMAKER_MODE)
116 for(
const auto& descriptor : allDescriptors)
119 allSupervisorInfo_.emplace(std::pair<unsigned int, SupervisorInfo>(
120 descriptor.second->getLocalId(),
124 ? contextConfig->getApplicationUID(
125 descriptor.second->getContextDescriptor()->getURL(),
126 descriptor.second->getLocalId())
129 ? contextConfig->getContextUID(
130 descriptor.second->getContextDescriptor()->getURL())
133 if(!emplacePair.second)
135 __SS__ <<
"Error! Duplicate Application IDs are not allowed. ID ="
136 << descriptor.second->getLocalId() << __E__;
145 if(emplacePair.first->second.isGatewaySupervisor())
147 if(theSupervisorInfo_)
149 __SS__ <<
"Error! Multiple Gateway Supervisors of class "
150 << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS
151 <<
" found. There can only be one. ID ="
152 << descriptor.second->getLocalId() << __E__;
156 theSupervisorInfo_ = &(emplacePair.first->second);
162 if(emplacePair.first->second.isWizardSupervisor())
166 __SS__ <<
"Error! Multiple Wizard Supervisors of class "
167 << XDAQContextTable::WIZARD_SUPERVISOR_CLASS
168 <<
" found. There can only be one. ID ="
169 << descriptor.second->getLocalId() << __E__;
173 theWizardInfo_ = &(emplacePair.first->second);
179 if(emplacePair.first->second.isTypeFESupervisor())
181 allFETypeSupervisorInfo_.emplace(
182 std::pair<unsigned int, const SupervisorInfo&>(
183 emplacePair.first->second.getId(), emplacePair.first->second));
188 if(emplacePair.first->second.isTypeDMSupervisor())
190 allDMTypeSupervisorInfo_.emplace(
191 std::pair<unsigned int, const SupervisorInfo&>(
192 emplacePair.first->second.getId(), emplacePair.first->second));
197 if(emplacePair.first->second.isTypeLogbookSupervisor())
199 allLogbookTypeSupervisorInfo_.emplace(
200 std::pair<unsigned int, const SupervisorInfo&>(
201 emplacePair.first->second.getId(), emplacePair.first->second));
206 if(emplacePair.first->second.isTypeMacroMakerSupervisor())
208 allMacroMakerTypeSupervisorInfo_.emplace(
209 std::pair<unsigned int, const SupervisorInfo&>(
210 emplacePair.first->second.getId(), emplacePair.first->second));
328 if(AllSupervisorInfo::MACROMAKER_MODE)
330 if(theWizardInfo_ || theSupervisorInfo_)
332 __SS__ <<
"Error! For MacroMaker mode, must not have one "
333 << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS <<
" OR one "
334 << XDAQContextTable::WIZARD_SUPERVISOR_CLASS
335 <<
" as part of the context configuration! "
336 <<
"One was found." << __E__;
340 else if((!theWizardInfo_ && !theSupervisorInfo_) ||
341 (theWizardInfo_ && theSupervisorInfo_))
343 __SS__ <<
"Error! Must have one " << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS
344 <<
" OR one " << XDAQContextTable::WIZARD_SUPERVISOR_CLASS
345 <<
" as part of the context configuration! "
346 <<
"Neither (or both) were found." << __E__;
350 SupervisorDescriptorInfoBase::destroy();
352 __COUT__ <<
"Supervisor Info initialization complete!" << __E__;
359 const SupervisorInfo& AllSupervisorInfo::getSupervisorInfo(xdaq::Application* app)
const
361 auto it = allSupervisorInfo_.find(app->getApplicationDescriptor()->getLocalId());
362 if(it == allSupervisorInfo_.end())
364 __SS__ <<
"Could not find: " << app->getApplicationDescriptor()->getLocalId()
372 void AllSupervisorInfo::setSupervisorStatus(xdaq::Application* app,
373 const std::string& status)
375 setSupervisorStatus(app->getApplicationDescriptor()->getLocalId(), status);
378 void AllSupervisorInfo::setSupervisorStatus(
const SupervisorInfo& appInfo,
379 const std::string& status)
381 setSupervisorStatus(appInfo.getId(), status);
384 void AllSupervisorInfo::setSupervisorStatus(
const unsigned int&
id,
385 const std::string& status)
387 auto it = allSupervisorInfo_.find(
id);
388 if(it == allSupervisorInfo_.end())
390 __SS__ <<
"Could not find: " <<
id << std::endl;
393 it->second.setStatus(status);
397 const SupervisorInfo& AllSupervisorInfo::getGatewayInfo(
void)
const
399 if(!theSupervisorInfo_)
401 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type "
402 << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS <<
" found!" << __E__;
405 return *theSupervisorInfo_;
408 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getGatewayDescriptor(
411 return getGatewayInfo().getDescriptor();
415 const SupervisorInfo& AllSupervisorInfo::getWizardInfo(
void)
const
419 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type "
420 << XDAQContextTable::WIZARD_SUPERVISOR_CLASS <<
" found!" << __E__;
423 return *theWizardInfo_;
426 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getWizardDescriptor(
429 return getWizardInfo().getDescriptor();
433 std::vector<std::vector<const SupervisorInfo*>>
434 AllSupervisorInfo::getOrderedSupervisorDescriptors(
435 const std::string& stateMachineCommand)
const
437 __COUT__ <<
"getOrderedSupervisorDescriptors" << __E__;
439 std::map<uint64_t , std::vector<
unsigned int >>
445 const std::vector<XDAQContextTable::XDAQContext>& contexts =
448 for(
const auto& context : contexts)
450 for(
const auto& app : context.applications_)
455 auto it = app.stateMachineCommandPriority_.find(stateMachineCommand);
456 if(it == app.stateMachineCommandPriority_.end())
464 orderedByPriority[it->second ? it->second
465 : XDAQContextTable::XDAQApplication::
474 __COUT_ERR__ <<
"SupervisorDescriptorInfoBase could not access the XDAQ Context "
475 "and Application configuration through the Context Table "
481 __COUT__ <<
"Here is the order supervisors will be " << stateMachineCommand
487 std::vector<std::vector<const SupervisorInfo*>> retVec;
488 bool createContainer;
489 for(
const auto& priorityAppVector : orderedByPriority)
491 createContainer =
true;
493 for(
const auto& priorityApp : priorityAppVector.second)
495 auto it = allSupervisorInfo_.find(priorityApp);
496 if(it == allSupervisorInfo_.end())
499 <<
"Error! Was AllSupervisorInfo properly initialized? The app.id_ "
500 << priorityApp <<
" priority "
501 << (
unsigned int)priorityAppVector.first
502 <<
" could not be found in AllSupervisorInfo." << __E__;
510 if(it->second.isGatewaySupervisor())
512 if(it->second.isTypeLogbookSupervisor())
514 if(it->second.isTypeMacroMakerSupervisor())
516 if(it->second.isTypeConfigurationGUISupervisor())
518 if(it->second.isTypeChatSupervisor())
520 if(it->second.isTypeConsoleSupervisor())
525 retVec.push_back(std::vector<const SupervisorInfo*>());
533 createContainer =
false;
535 retVec[retVec.size() - 1].push_back(&(it->second));
537 __COUT__ << it->second.getName() <<
" [LID=" << it->second.getId() <<
"]: "
538 <<
" priority " << (
unsigned int)priorityAppVector.first <<
" count "
539 << retVec[retVec.size() - 1].size() << __E__;
void init(xdaq::ApplicationContext *applicationContext)