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/TablePlugins/XDAQContextTable.h"
13 const bool AllSupervisorInfo::MACROMAKER_MODE =
14 ((getenv(
"MACROMAKER_MODE") ==
17 : ((std::string(__ENV__(
"MACROMAKER_MODE")) ==
"1") ?
true :
false));
20 AllSupervisorInfo::AllSupervisorInfo(
void) : theSupervisorInfo_(0), theWizardInfo_(0) {}
23 AllSupervisorInfo::AllSupervisorInfo(xdaq::ApplicationContext* applicationContext)
26 init(applicationContext);
30 AllSupervisorInfo::~AllSupervisorInfo(
void) { destroy(); }
33 void AllSupervisorInfo::destroy(
void)
35 allSupervisorInfo_.clear();
36 allFETypeSupervisorInfo_.clear();
37 allDMTypeSupervisorInfo_.clear();
39 theSupervisorInfo_ = 0;
42 SupervisorDescriptorInfoBase::destroy();
48 __COUT__ <<
"Initializing info based on XDAQ context..." << __E__;
50 AllSupervisorInfo::destroy();
51 SupervisorDescriptorInfoBase::init(applicationContext);
53 auto allDescriptors = SupervisorDescriptorInfoBase::getAllDescriptors();
74 bool isWizardMode =
false;
78 for(
const auto& descriptor : allDescriptors)
87 if(tempSupervisorInfo.isGatewaySupervisor())
93 else if(tempSupervisorInfo.isWizardSupervisor())
101 if(AllSupervisorInfo::MACROMAKER_MODE)
102 __COUT__ <<
"Initializing info for Macro Maker mode XDAQ context..." << __E__;
103 else if(isWizardMode)
104 __COUT__ <<
"Initializing info for Wiz mode XDAQ context..." << __E__;
106 __COUT__ <<
"Initializing info for Normal mode XDAQ context..." << __E__;
107 std::unique_ptr<ConfigurationManager> cfgMgr(
108 (isWizardMode || AllSupervisorInfo::MACROMAKER_MODE)
112 (isWizardMode || AllSupervisorInfo::MACROMAKER_MODE)
119 for(
const auto& descriptor : allDescriptors)
122 allSupervisorInfo_.emplace(std::pair<unsigned int, SupervisorInfo>(
123 descriptor.second->getLocalId(),
127 ? contextConfig->getApplicationUID(
128 descriptor.second->getContextDescriptor()->getURL(),
129 descriptor.second->getLocalId())
132 ? contextConfig->getContextUID(
133 descriptor.second->getContextDescriptor()->getURL())
136 if(!emplacePair.second)
138 __SS__ <<
"Error! Duplicate Application IDs are not allowed. ID ="
139 << descriptor.second->getLocalId() << __E__;
148 if(emplacePair.first->second.isGatewaySupervisor())
150 if(theSupervisorInfo_)
152 __SS__ <<
"Error! Multiple Gateway Supervisors of class "
153 << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS
154 <<
" found. There can only be one. ID ="
155 << descriptor.second->getLocalId() << __E__;
159 theSupervisorInfo_ = &(emplacePair.first->second);
165 if(emplacePair.first->second.isWizardSupervisor())
169 __SS__ <<
"Error! Multiple Wizard Supervisors of class "
170 << XDAQContextTable::WIZARD_SUPERVISOR_CLASS
171 <<
" found. There can only be one. ID ="
172 << descriptor.second->getLocalId() << __E__;
176 theWizardInfo_ = &(emplacePair.first->second);
182 if(emplacePair.first->second.isTypeFESupervisor())
184 allFETypeSupervisorInfo_.emplace(
185 std::pair<unsigned int, const SupervisorInfo&>(
186 emplacePair.first->second.getId(), emplacePair.first->second));
191 if(emplacePair.first->second.isTypeDMSupervisor())
193 allDMTypeSupervisorInfo_.emplace(
194 std::pair<unsigned int, const SupervisorInfo&>(
195 emplacePair.first->second.getId(), emplacePair.first->second));
200 if(emplacePair.first->second.isTypeLogbookSupervisor())
202 allLogbookTypeSupervisorInfo_.emplace(
203 std::pair<unsigned int, const SupervisorInfo&>(
204 emplacePair.first->second.getId(), emplacePair.first->second));
209 if(emplacePair.first->second.isTypeMacroMakerSupervisor())
211 allMacroMakerTypeSupervisorInfo_.emplace(
212 std::pair<unsigned int, const SupervisorInfo&>(
213 emplacePair.first->second.getId(), emplacePair.first->second));
331 if(AllSupervisorInfo::MACROMAKER_MODE)
333 if(theWizardInfo_ || theSupervisorInfo_)
335 __SS__ <<
"Error! For MacroMaker mode, must not have one "
336 << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS <<
" OR one "
337 << XDAQContextTable::WIZARD_SUPERVISOR_CLASS
338 <<
" as part of the context configuration! "
339 <<
"One was found." << __E__;
343 else if((!theWizardInfo_ && !theSupervisorInfo_) ||
344 (theWizardInfo_ && theSupervisorInfo_))
346 __SS__ <<
"Error! Must have one " << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS
347 <<
" OR one " << XDAQContextTable::WIZARD_SUPERVISOR_CLASS
348 <<
" as part of the context configuration! "
349 <<
"Neither (or both) were found." << __E__;
353 SupervisorDescriptorInfoBase::destroy();
355 __COUT__ <<
"Supervisor Info initialization complete!" << __E__;
362 const SupervisorInfo& AllSupervisorInfo::getSupervisorInfo(xdaq::Application* app)
const
364 auto it = allSupervisorInfo_.find(app->getApplicationDescriptor()->getLocalId());
365 if(it == allSupervisorInfo_.end())
367 __SS__ <<
"Could not find: " << app->getApplicationDescriptor()->getLocalId()
375 void AllSupervisorInfo::setSupervisorStatus(xdaq::Application* app,
376 const std::string& status)
378 setSupervisorStatus(app->getApplicationDescriptor()->getLocalId(), status);
381 void AllSupervisorInfo::setSupervisorStatus(
const SupervisorInfo& appInfo,
382 const std::string& status)
384 setSupervisorStatus(appInfo.getId(), status);
387 void AllSupervisorInfo::setSupervisorStatus(
const unsigned int&
id,
388 const std::string& status)
390 auto it = allSupervisorInfo_.find(
id);
391 if(it == allSupervisorInfo_.end())
393 __SS__ <<
"Could not find: " <<
id << std::endl;
396 it->second.setStatus(status);
400 const SupervisorInfo& AllSupervisorInfo::getGatewayInfo(
void)
const
402 if(!theSupervisorInfo_)
404 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type "
405 << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS <<
" found!" << __E__;
408 return *theSupervisorInfo_;
411 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getGatewayDescriptor(
414 return getGatewayInfo().getDescriptor();
418 const SupervisorInfo& AllSupervisorInfo::getWizardInfo(
void)
const
422 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type "
423 << XDAQContextTable::WIZARD_SUPERVISOR_CLASS <<
" found!" << __E__;
426 return *theWizardInfo_;
429 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getWizardDescriptor(
432 return getWizardInfo().getDescriptor();
436 std::vector<std::vector<const SupervisorInfo*>>
437 AllSupervisorInfo::getOrderedSupervisorDescriptors(
438 const std::string& stateMachineCommand)
const
440 __COUT__ <<
"getOrderedSupervisorDescriptors" << __E__;
442 std::map<uint64_t , std::vector<
unsigned int >>
448 const std::vector<XDAQContextTable::XDAQContext>& contexts =
451 for(
const auto& context : contexts)
453 for(
const auto& app : context.applications_)
458 auto it = app.stateMachineCommandPriority_.find(stateMachineCommand);
459 if(it == app.stateMachineCommandPriority_.end())
467 orderedByPriority[it->second ? it->second
468 : XDAQContextTable::XDAQApplication::
477 __COUT_ERR__ <<
"SupervisorDescriptorInfoBase could not access the XDAQ Context "
478 "and Application configuration through the Context Table "
484 __COUT__ <<
"Here is the order supervisors will be " << stateMachineCommand
490 std::vector<std::vector<const SupervisorInfo*>> retVec;
491 bool createContainer;
492 for(
const auto& priorityAppVector : orderedByPriority)
494 createContainer =
true;
496 for(
const auto& priorityApp : priorityAppVector.second)
498 auto it = allSupervisorInfo_.find(priorityApp);
499 if(it == allSupervisorInfo_.end())
502 <<
"Error! Was AllSupervisorInfo properly initialized? The app.id_ "
503 << priorityApp <<
" priority "
504 << (
unsigned int)priorityAppVector.first
505 <<
" could not be found in AllSupervisorInfo." << __E__;
513 if(it->second.isGatewaySupervisor())
515 if(it->second.isTypeLogbookSupervisor())
517 if(it->second.isTypeMacroMakerSupervisor())
519 if(it->second.isTypeConfigurationGUISupervisor())
521 if(it->second.isTypeChatSupervisor())
523 if(it->second.isTypeConsoleSupervisor())
528 retVec.push_back(std::vector<const SupervisorInfo*>());
536 createContainer =
false;
538 retVec[retVec.size() - 1].push_back(&(it->second));
540 __COUT__ << it->second.getName() <<
" [LID=" << it->second.getId() <<
"]: "
541 <<
" priority " << (
unsigned int)priorityAppVector.first <<
" count "
542 << retVec[retVec.size() - 1].size() << __E__;
void init(xdaq::ApplicationContext *applicationContext)