1 #include "otsdaq-core/SupervisorInfo/AllSupervisorInfo.h"
3 #include "otsdaq-core/MessageFacility/MessageFacility.h"
4 #include "otsdaq-core/Macros/CoutMacros.h"
6 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
7 #include "otsdaq-core/ConfigurationPluginDataFormats/XDAQContextConfiguration.h"
19 AllSupervisorInfo::AllSupervisorInfo(
void)
20 : theSupervisorInfo_ (0)
26 AllSupervisorInfo::AllSupervisorInfo(xdaq::ApplicationContext* applicationContext)
29 init(applicationContext);
33 AllSupervisorInfo::~AllSupervisorInfo(
void)
39 void AllSupervisorInfo::destroy(
void)
41 allSupervisorInfo_.clear();
42 allFETypeSupervisorInfo_.clear();
43 allDMTypeSupervisorInfo_.clear();
45 theSupervisorInfo_ = 0;
48 SupervisorDescriptorInfoBase::destroy();
52 void AllSupervisorInfo::init(xdaq::ApplicationContext* applicationContext)
54 __COUT__ <<
"Initializing info based on XDAQ context..." << __E__;
56 AllSupervisorInfo::destroy();
57 SupervisorDescriptorInfoBase::init(applicationContext);
59 auto allDescriptors = SupervisorDescriptorInfoBase::getAllDescriptors();
66 bool isWizardMode =
false;
70 for(
const auto& descriptor:allDescriptors)
79 if(tempSupervisorInfo.isGatewaySupervisor())
85 else if(tempSupervisorInfo.isWizardSupervisor())
97 __COUT__ <<
"Initializing info for Wiz mode XDAQ context..." << __E__;
102 for(
const auto& descriptor:allDescriptors)
104 auto emplacePair = allSupervisorInfo_.emplace(std::pair<unsigned int, SupervisorInfo>(
105 descriptor.second->getLocalId(),
110 if(!emplacePair.second)
112 __SS__ <<
"Error! Duplicate Application IDs are not allowed. ID =" <<
113 descriptor.second->getLocalId() << __E__;
122 if(emplacePair.first->second.isGatewaySupervisor())
124 if(theSupervisorInfo_)
126 __SS__ <<
"Error! Multiple Gateway Supervisors of class " << XDAQContextConfiguration::GATEWAY_SUPERVISOR_CLASS <<
127 " found. There can only be one. ID =" <<
128 descriptor.second->getLocalId() << __E__;
132 theSupervisorInfo_ = &(emplacePair.first->second);
138 if(emplacePair.first->second.isWizardSupervisor())
142 __SS__ <<
"Error! Multiple Wizard Supervisors of class " << XDAQContextConfiguration::WIZARD_SUPERVISOR_CLASS <<
143 " found. There can only be one. ID =" <<
144 descriptor.second->getLocalId() << __E__;
148 theWizardInfo_ = &(emplacePair.first->second);
155 if(emplacePair.first->second.isTypeFESupervisor())
157 allFETypeSupervisorInfo_.emplace(std::pair<unsigned int, const SupervisorInfo&>(
158 emplacePair.first->second.getId(),
159 emplacePair.first->second));
164 if(emplacePair.first->second.isTypeDMSupervisor())
166 allDMTypeSupervisorInfo_.emplace(std::pair<unsigned int, const SupervisorInfo&>(
167 emplacePair.first->second.getId(),
168 emplacePair.first->second));
173 if(emplacePair.first->second.isTypeLogbookSupervisor())
175 allLogbookTypeSupervisorInfo_.emplace(std::pair<unsigned int, const SupervisorInfo&>(
176 emplacePair.first->second.getId(),
177 emplacePair.first->second));
185 __COUT__ <<
"Initializing info for Normal mode XDAQ context..." << __E__;
194 auto allDescriptors = SupervisorDescriptorInfoBase::getAllDescriptors();
195 for(
const auto& descriptor:allDescriptors)
197 auto emplacePair = allSupervisorInfo_.emplace(std::pair<unsigned int, SupervisorInfo>(
198 descriptor.second->getLocalId(),
201 contextConfig->getApplicationUID
203 descriptor.second->getContextDescriptor()->getURL(),
204 descriptor.second->getLocalId()
206 contextConfig->getContextUID(
207 descriptor.second->getContextDescriptor()->getURL())
209 if(!emplacePair.second)
211 __SS__ <<
"Error! Duplicate Application IDs are not allowed. ID =" <<
212 descriptor.second->getLocalId() << __E__;
221 if(emplacePair.first->second.isGatewaySupervisor())
223 if(theSupervisorInfo_)
225 __SS__ <<
"Error! Multiple Gateway Supervisors of class " << XDAQContextConfiguration::GATEWAY_SUPERVISOR_CLASS <<
226 " found. There can only be one. ID =" <<
227 descriptor.second->getLocalId() << __E__;
231 theSupervisorInfo_ = &(emplacePair.first->second);
237 if(emplacePair.first->second.isWizardSupervisor())
241 __SS__ <<
"Error! Multiple Wizard Supervisors of class " << XDAQContextConfiguration::WIZARD_SUPERVISOR_CLASS <<
242 " found. There can only be one. ID =" <<
243 descriptor.second->getLocalId() << __E__;
247 theWizardInfo_ = &(emplacePair.first->second);
254 if(emplacePair.first->second.isTypeFESupervisor())
256 allFETypeSupervisorInfo_.emplace(std::pair<unsigned int, const SupervisorInfo&>(
257 emplacePair.first->second.getId(),
258 emplacePair.first->second));
263 if(emplacePair.first->second.isTypeDMSupervisor())
265 allDMTypeSupervisorInfo_.emplace(std::pair<unsigned int, const SupervisorInfo&>(
266 emplacePair.first->second.getId(),
267 emplacePair.first->second));
272 if(emplacePair.first->second.isTypeLogbookSupervisor())
274 allLogbookTypeSupervisorInfo_.emplace(std::pair<unsigned int, const SupervisorInfo&>(
275 emplacePair.first->second.getId(),
276 emplacePair.first->second));
283 if((!theWizardInfo_ && !theSupervisorInfo_) ||
284 (theWizardInfo_ && theSupervisorInfo_))
286 __SS__ <<
"Error! Must have one " << XDAQContextConfiguration::GATEWAY_SUPERVISOR_CLASS <<
287 " OR one " << XDAQContextConfiguration::WIZARD_SUPERVISOR_CLASS <<
288 " as part of the context configuration! " <<
289 "Neither were found." << __E__;
294 SupervisorDescriptorInfoBase::destroy();
296 __COUT__ <<
"Init complete" << __E__;
303 const SupervisorInfo& AllSupervisorInfo::getSupervisorInfo(xdaq::Application* app)
const
305 auto it = allSupervisorInfo_.find(app->getApplicationDescriptor()->getLocalId());
306 if(it == allSupervisorInfo_.end())
308 __SS__ <<
"Could not find: " << app->getApplicationDescriptor()->getLocalId() << std::endl;
315 void AllSupervisorInfo::setSupervisorStatus(xdaq::Application* app,
316 const std::string& status)
318 setSupervisorStatus(app->getApplicationDescriptor()->getLocalId(), status);
321 void AllSupervisorInfo::setSupervisorStatus(
const SupervisorInfo& appInfo,
322 const std::string& status)
324 setSupervisorStatus(appInfo.getId(), status);
327 void AllSupervisorInfo::setSupervisorStatus(
const unsigned int&
id,
328 const std::string& status)
330 auto it = allSupervisorInfo_.find(
id);
331 if(it == allSupervisorInfo_.end())
333 __SS__ <<
"Could not find: " <<
id << std::endl;
336 it->second.setStatus(status);
340 const SupervisorInfo& AllSupervisorInfo::getGatewayInfo(
void)
const
342 if(!theSupervisorInfo_)
344 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type " <<
345 XDAQContextConfiguration::GATEWAY_SUPERVISOR_CLASS <<
" found!" << __E__;
348 return *theSupervisorInfo_;
351 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getGatewayDescriptor(
void)
const
353 return getGatewayInfo().getDescriptor();
357 const SupervisorInfo& AllSupervisorInfo::getWizardInfo(
void)
const
361 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type " <<
362 XDAQContextConfiguration::WIZARD_SUPERVISOR_CLASS <<
" found!" << __E__;
365 return *theWizardInfo_;
368 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getWizardDescriptor(
void)
const
370 return getWizardInfo().getDescriptor();
375 std::vector<const SupervisorInfo*> AllSupervisorInfo::getOrderedSupervisorDescriptors(
376 const std::string& stateMachineCommand)
const
378 __COUT__ <<
"getOrderedSupervisorDescriptors" << __E__;
380 std::map<uint64_t , std::vector<
unsigned int > > orderedByPriority;
385 const std::vector<XDAQContextConfiguration::XDAQContext>& contexts =
388 for (
const auto& context : contexts)
390 for (
const auto& app : context.applications_)
392 if(!app.status_)
continue;
394 auto it = app.stateMachineCommandPriority_.find(stateMachineCommand);
395 if(it == app.stateMachineCommandPriority_.end())
396 orderedByPriority[100].push_back(app.id_);
398 orderedByPriority[it->second?it->second:100].push_back(app.id_);
405 __COUT_ERR__ <<
"SupervisorDescriptorInfoBase could not access the XDAQ Context and Application configuration through the Configuration Context Group." << __E__;
410 __COUT__ <<
"Here is the order supervisors will be " << stateMachineCommand <<
"'d:" << __E__;
415 std::vector<const SupervisorInfo*> retVec;
416 for (
const auto& priorityAppVector : orderedByPriority)
417 for (
const auto& priorityApp : priorityAppVector.second)
419 auto it = allSupervisorInfo_.find(priorityApp);
420 if(it == allSupervisorInfo_.end())
422 __SS__ <<
"Error! Was AllSupervisorInfo properly initialized? The app.id_ " << priorityApp <<
" priority " <<
423 (
unsigned int)priorityAppVector.first <<
" could not be found in AllSupervisorInfo." << __E__;
430 if(it->second.isGatewaySupervisor())
continue;
431 if(it->second.isTypeLogbookSupervisor())
continue;
432 if(it->second.isTypeMacroMakerSupervisor())
continue;
433 if(it->second.isTypeConfigurationGUISupervisor())
continue;
434 if(it->second.isTypeChatSupervisor())
continue;
435 if(it->second.isTypeConsoleSupervisor())
continue;
437 retVec.push_back(&(it->second));
438 __COUT__ << it->second.getName() <<
" [LID=" << it->second.getId() <<
"]: " <<
" priority " <<
439 (
unsigned int)priorityAppVector.first << __E__;