1 #include "otsdaq/SupervisorInfo/AllSupervisorInfo.h"
3 #include "otsdaq/Macros/CoutMacros.h"
4 #include "otsdaq/MessageFacility/MessageFacility.h"
6 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
7 #include "otsdaq/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);
399 void AllSupervisorInfo::setSupervisorProgress(
const SupervisorInfo& appInfo,
400 const unsigned int progress)
402 setSupervisorProgress(appInfo.getId(), progress);
405 void AllSupervisorInfo::setSupervisorProgress(
const unsigned int&
id,
406 const unsigned int progress)
408 auto it = allSupervisorInfo_.find(
id);
409 if(it == allSupervisorInfo_.end())
411 __SS__ <<
"Could not find: " <<
id << std::endl;
414 it->second.setProgress(progress);
418 const SupervisorInfo& AllSupervisorInfo::getGatewayInfo(
void)
const
420 if(!theSupervisorInfo_)
422 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type "
423 << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS <<
" found!" << __E__;
426 return *theSupervisorInfo_;
429 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getGatewayDescriptor(
432 return getGatewayInfo().getDescriptor();
436 const SupervisorInfo& AllSupervisorInfo::getWizardInfo(
void)
const
440 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type "
441 << XDAQContextTable::WIZARD_SUPERVISOR_CLASS <<
" found!" << __E__;
444 return *theWizardInfo_;
447 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getWizardDescriptor(
450 return getWizardInfo().getDescriptor();
454 std::vector<std::vector<const SupervisorInfo*>>
455 AllSupervisorInfo::getOrderedSupervisorDescriptors(
456 const std::string& stateMachineCommand)
const
458 __COUT__ <<
"getOrderedSupervisorDescriptors" << __E__;
460 std::map<uint64_t , std::vector<
unsigned int >>
466 const std::vector<XDAQContextTable::XDAQContext>& contexts =
469 for(
const auto& context : contexts)
471 for(
const auto& app : context.applications_)
476 auto it = app.stateMachineCommandPriority_.find(stateMachineCommand);
477 if(it == app.stateMachineCommandPriority_.end())
485 orderedByPriority[it->second ? it->second
486 : XDAQContextTable::XDAQApplication::
495 __COUT_ERR__ <<
"SupervisorDescriptorInfoBase could not access the XDAQ Context "
496 "and Application configuration through the Context Table "
502 __COUT__ <<
"Here is the order supervisors will be " << stateMachineCommand
508 std::vector<std::vector<const SupervisorInfo*>> retVec;
509 bool createContainer;
510 for(
const auto& priorityAppVector : orderedByPriority)
512 createContainer =
true;
514 for(
const auto& priorityApp : priorityAppVector.second)
516 auto it = allSupervisorInfo_.find(priorityApp);
517 if(it == allSupervisorInfo_.end())
520 <<
"Error! Was AllSupervisorInfo properly initialized? The app.id_ "
521 << priorityApp <<
" priority "
522 << (
unsigned int)priorityAppVector.first
523 <<
" could not be found in AllSupervisorInfo." << __E__;
531 if(it->second.isGatewaySupervisor())
533 if(it->second.isTypeLogbookSupervisor())
535 if(it->second.isTypeMacroMakerSupervisor())
537 if(it->second.isTypeConfigurationGUISupervisor())
539 if(it->second.isTypeChatSupervisor())
541 if(it->second.isTypeConsoleSupervisor())
546 retVec.push_back(std::vector<const SupervisorInfo*>());
554 createContainer =
false;
556 retVec[retVec.size() - 1].push_back(&(it->second));
558 __COUT__ << it->second.getName() <<
" [LID=" << it->second.getId() <<
"]: "
559 <<
" priority " << (
unsigned int)priorityAppVector.first <<
" count "
560 << retVec[retVec.size() - 1].size() << __E__;
void init(xdaq::ApplicationContext *applicationContext)