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"
14 AllSupervisorInfo::AllSupervisorInfo(
void) : theSupervisorInfo_(0), theWizardInfo_(0) {}
17 AllSupervisorInfo::AllSupervisorInfo(xdaq::ApplicationContext* applicationContext)
20 init(applicationContext);
24 AllSupervisorInfo::~AllSupervisorInfo(
void) { destroy(); }
27 void AllSupervisorInfo::destroy(
void)
29 allSupervisorInfo_.clear();
30 allFETypeSupervisorInfo_.clear();
31 allDMTypeSupervisorInfo_.clear();
33 theSupervisorInfo_ = 0;
36 SupervisorDescriptorInfoBase::destroy();
42 __COUT__ <<
"Initializing info based on XDAQ context..." << __E__;
44 AllSupervisorInfo::destroy();
45 SupervisorDescriptorInfoBase::init(applicationContext);
47 auto allDescriptors = SupervisorDescriptorInfoBase::getAllDescriptors();
68 bool isWizardMode =
false;
72 for(
const auto& descriptor : allDescriptors)
81 if(tempSupervisorInfo.isGatewaySupervisor())
87 else if(tempSupervisorInfo.isWizardSupervisor())
96 __COUT__ <<
"Initializing info for Wiz mode XDAQ context..." << __E__;
98 __COUT__ <<
"Initializing info for Normal mode XDAQ context..." << __E__;
99 std::unique_ptr<ConfigurationManager> cfgMgr(
107 for(
const auto& descriptor : allDescriptors)
110 allSupervisorInfo_.emplace(std::pair<unsigned int, SupervisorInfo>(
111 descriptor.second->getLocalId(),
115 ? contextConfig->getApplicationUID(
116 descriptor.second->getContextDescriptor()->getURL(),
117 descriptor.second->getLocalId())
120 ? contextConfig->getContextUID(
121 descriptor.second->getContextDescriptor()->getURL())
124 if(!emplacePair.second)
126 __SS__ <<
"Error! Duplicate Application IDs are not allowed. ID ="
127 << descriptor.second->getLocalId() << __E__;
136 if(emplacePair.first->second.isGatewaySupervisor())
138 if(theSupervisorInfo_)
140 __SS__ <<
"Error! Multiple Gateway Supervisors of class "
141 << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS
142 <<
" found. There can only be one. ID ="
143 << descriptor.second->getLocalId() << __E__;
147 theSupervisorInfo_ = &(emplacePair.first->second);
153 if(emplacePair.first->second.isWizardSupervisor())
157 __SS__ <<
"Error! Multiple Wizard Supervisors of class "
158 << XDAQContextTable::WIZARD_SUPERVISOR_CLASS
159 <<
" found. There can only be one. ID ="
160 << descriptor.second->getLocalId() << __E__;
164 theWizardInfo_ = &(emplacePair.first->second);
170 if(emplacePair.first->second.isTypeFESupervisor())
172 allFETypeSupervisorInfo_.emplace(
173 std::pair<unsigned int, const SupervisorInfo&>(
174 emplacePair.first->second.getId(), emplacePair.first->second));
179 if(emplacePair.first->second.isTypeDMSupervisor())
181 allDMTypeSupervisorInfo_.emplace(
182 std::pair<unsigned int, const SupervisorInfo&>(
183 emplacePair.first->second.getId(), emplacePair.first->second));
188 if(emplacePair.first->second.isTypeLogbookSupervisor())
190 allLogbookTypeSupervisorInfo_.emplace(
191 std::pair<unsigned int, const SupervisorInfo&>(
192 emplacePair.first->second.getId(), emplacePair.first->second));
197 if(emplacePair.first->second.isTypeMacroMakerSupervisor())
199 allMacroMakerTypeSupervisorInfo_.emplace(
200 std::pair<unsigned int, const SupervisorInfo&>(
201 emplacePair.first->second.getId(), emplacePair.first->second));
319 if((!theWizardInfo_ && !theSupervisorInfo_) || (theWizardInfo_ && theSupervisorInfo_))
321 __SS__ <<
"Error! Must have one " << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS
322 <<
" OR one " << XDAQContextTable::WIZARD_SUPERVISOR_CLASS
323 <<
" as part of the context configuration! "
324 <<
"Neither were found." << __E__;
328 SupervisorDescriptorInfoBase::destroy();
330 __COUT__ <<
"Init complete" << __E__;
337 const SupervisorInfo& AllSupervisorInfo::getSupervisorInfo(xdaq::Application* app)
const
339 auto it = allSupervisorInfo_.find(app->getApplicationDescriptor()->getLocalId());
340 if(it == allSupervisorInfo_.end())
342 __SS__ <<
"Could not find: " << app->getApplicationDescriptor()->getLocalId()
350 void AllSupervisorInfo::setSupervisorStatus(xdaq::Application* app,
351 const std::string& status)
353 setSupervisorStatus(app->getApplicationDescriptor()->getLocalId(), status);
356 void AllSupervisorInfo::setSupervisorStatus(
const SupervisorInfo& appInfo,
357 const std::string& status)
359 setSupervisorStatus(appInfo.getId(), status);
362 void AllSupervisorInfo::setSupervisorStatus(
const unsigned int&
id,
363 const std::string& status)
365 auto it = allSupervisorInfo_.find(
id);
366 if(it == allSupervisorInfo_.end())
368 __SS__ <<
"Could not find: " <<
id << std::endl;
371 it->second.setStatus(status);
375 const SupervisorInfo& AllSupervisorInfo::getGatewayInfo(
void)
const
377 if(!theSupervisorInfo_)
379 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type "
380 << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS <<
" found!" << __E__;
383 return *theSupervisorInfo_;
386 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getGatewayDescriptor(
389 return getGatewayInfo().getDescriptor();
393 const SupervisorInfo& AllSupervisorInfo::getWizardInfo(
void)
const
397 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type "
398 << XDAQContextTable::WIZARD_SUPERVISOR_CLASS <<
" found!" << __E__;
401 return *theWizardInfo_;
404 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getWizardDescriptor(
407 return getWizardInfo().getDescriptor();
411 std::vector<std::vector<const SupervisorInfo*>>
412 AllSupervisorInfo::getOrderedSupervisorDescriptors(
413 const std::string& stateMachineCommand)
const
415 __COUT__ <<
"getOrderedSupervisorDescriptors" << __E__;
417 std::map<uint64_t , std::vector<
unsigned int >>
423 const std::vector<XDAQContextTable::XDAQContext>& contexts =
426 for(
const auto& context : contexts)
428 for(
const auto& app : context.applications_)
433 auto it = app.stateMachineCommandPriority_.find(stateMachineCommand);
434 if(it == app.stateMachineCommandPriority_.end())
442 orderedByPriority[it->second ? it->second
443 : XDAQContextTable::XDAQApplication::
452 __COUT_ERR__ <<
"SupervisorDescriptorInfoBase could not access the XDAQ Context "
453 "and Application configuration through the Context Table "
459 __COUT__ <<
"Here is the order supervisors will be " << stateMachineCommand
465 std::vector<std::vector<const SupervisorInfo*>> retVec;
466 bool createContainer;
467 for(
const auto& priorityAppVector : orderedByPriority)
469 createContainer =
true;
471 for(
const auto& priorityApp : priorityAppVector.second)
473 auto it = allSupervisorInfo_.find(priorityApp);
474 if(it == allSupervisorInfo_.end())
477 <<
"Error! Was AllSupervisorInfo properly initialized? The app.id_ "
478 << priorityApp <<
" priority "
479 << (
unsigned int)priorityAppVector.first
480 <<
" could not be found in AllSupervisorInfo." << __E__;
488 if(it->second.isGatewaySupervisor())
490 if(it->second.isTypeLogbookSupervisor())
492 if(it->second.isTypeMacroMakerSupervisor())
494 if(it->second.isTypeConfigurationGUISupervisor())
496 if(it->second.isTypeChatSupervisor())
498 if(it->second.isTypeConsoleSupervisor())
503 retVec.push_back(std::vector<const SupervisorInfo*>());
511 createContainer =
false;
513 retVec[retVec.size() - 1].push_back(&(it->second));
515 __COUT__ << it->second.getName() <<
" [LID=" << it->second.getId() <<
"]: "
516 <<
" priority " << (
unsigned int)priorityAppVector.first <<
" count "
517 << retVec[retVec.size() - 1].size() << __E__;
void init(xdaq::ApplicationContext *applicationContext)