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/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)
21 : theSupervisorInfo_(nullptr)
22 , theWizardInfo_(nullptr)
23 , theARTDAQSupervisorInfo_(nullptr)
28 AllSupervisorInfo::AllSupervisorInfo(xdaq::ApplicationContext* applicationContext)
31 init(applicationContext);
35 AllSupervisorInfo::~AllSupervisorInfo(
void) { destroy(); }
38 void AllSupervisorInfo::destroy(
void)
40 allSupervisorInfo_.clear();
41 allFETypeSupervisorInfo_.clear();
42 allDMTypeSupervisorInfo_.clear();
44 theSupervisorInfo_ =
nullptr;
45 theWizardInfo_ =
nullptr;
46 theARTDAQSupervisorInfo_ =
nullptr;
48 SupervisorDescriptorInfoBase::destroy();
53 void AllSupervisorInfo::init(xdaq::ApplicationContext* applicationContext)
55 __COUT__ <<
"Initializing info based on XDAQ context..." << __E__;
57 AllSupervisorInfo::destroy();
58 SupervisorDescriptorInfoBase::init(applicationContext);
60 auto allDescriptors = SupervisorDescriptorInfoBase::getAllDescriptors();
82 theSupervisorInfo_ =
nullptr;
83 theWizardInfo_ =
nullptr;
84 theARTDAQSupervisorInfo_ =
nullptr;
88 for(
const auto& descriptor : allDescriptors)
97 if(tempSupervisorInfo.isGatewaySupervisor())
103 else if(tempSupervisorInfo.isWizardSupervisor())
111 if(AllSupervisorInfo::MACROMAKER_MODE)
112 __COUT__ <<
"Initializing info for Macro Maker mode XDAQ context..." << __E__;
114 __COUT__ <<
"Initializing info for Wiz mode XDAQ context..." << __E__;
116 __COUT__ <<
"Initializing info for Normal mode XDAQ context..." << __E__;
117 std::unique_ptr<ConfigurationManager> cfgMgr(
130 std::string name, contextName;
134 for(
const auto& descriptor : allDescriptors)
136 name = contextConfig ? contextConfig->getApplicationUID(
137 descriptor.second->getContextDescriptor()->getURL(),
138 descriptor.second->getLocalId())
140 contextName = contextConfig
142 descriptor.second->getContextDescriptor()->getURL())
146 allSupervisorInfo_.emplace(std::pair<unsigned int, SupervisorInfo>(
147 descriptor.second->getLocalId(),
149 if(!emplacePair.second)
151 __SS__ <<
"Error! Duplicate Application IDs are not allowed. ID ="
152 << descriptor.second->getLocalId() << __E__;
161 if(emplacePair.first->second.isTypeARTDAQSupervisor())
164 if(theARTDAQSupervisorInfo_)
166 __SS__ <<
"Error! Multiple ARTDAQ Supervisors of class "
167 << XDAQContextTable::ARTDAQ_SUPERVISOR_CLASS
168 <<
" found. There can only be one. ID ="
169 << descriptor.second->getLocalId() << __E__;
173 theARTDAQSupervisorInfo_ = &(emplacePair.first->second);
181 if(emplacePair.first->second.isGatewaySupervisor())
183 if(theSupervisorInfo_)
185 __SS__ <<
"Error! Multiple Gateway Supervisors of class "
186 << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS
187 <<
" found. There can only be one. ID ="
188 << descriptor.second->getLocalId() << __E__;
191 theSupervisorInfo_ = &(emplacePair.first->second);
197 if(emplacePair.first->second.isWizardSupervisor())
201 __SS__ <<
"Error! Multiple Wizard Supervisors of class "
202 << XDAQContextTable::WIZARD_SUPERVISOR_CLASS
203 <<
" found. There can only be one. ID ="
204 << descriptor.second->getLocalId() << __E__;
207 theWizardInfo_ = &(emplacePair.first->second);
214 if(emplacePair.first->second.isTypeFESupervisor())
216 allFETypeSupervisorInfo_.emplace(
217 std::pair<unsigned int, const SupervisorInfo&>(
218 emplacePair.first->second.getId(), emplacePair.first->second));
223 if(emplacePair.first->second.isTypeDMSupervisor())
225 allDMTypeSupervisorInfo_.emplace(
226 std::pair<unsigned int, const SupervisorInfo&>(
227 emplacePair.first->second.getId(), emplacePair.first->second));
232 if(emplacePair.first->second.isTypeLogbookSupervisor())
234 allLogbookTypeSupervisorInfo_.emplace(
235 std::pair<unsigned int, const SupervisorInfo&>(
236 emplacePair.first->second.getId(), emplacePair.first->second));
241 if(emplacePair.first->second.isTypeMacroMakerSupervisor())
243 allMacroMakerTypeSupervisorInfo_.emplace(
244 std::pair<unsigned int, const SupervisorInfo&>(
245 emplacePair.first->second.getId(), emplacePair.first->second));
250 if(AllSupervisorInfo::MACROMAKER_MODE)
252 if(theWizardInfo_ || theSupervisorInfo_)
254 __SS__ <<
"Error! For MacroMaker mode, must not have one "
255 << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS <<
" OR one "
256 << XDAQContextTable::WIZARD_SUPERVISOR_CLASS
257 <<
" as part of the context configuration! "
258 <<
"One was found." << __E__;
261 if(allMacroMakerTypeSupervisorInfo_.size() != 1)
263 __SS__ <<
"Error! For MacroMaker mode, must have one and only one "
264 << *(XDAQContextTable::MacroMakerTypeClassNames_.begin())
265 <<
" as part of the context configuration! "
266 << allMacroMakerTypeSupervisorInfo_.size() <<
" were found." << __E__;
270 else if((!theWizardInfo_ && !theSupervisorInfo_) ||
271 (theWizardInfo_ && theSupervisorInfo_))
273 __SS__ <<
"Error! Must have one " << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS
274 <<
" OR one " << XDAQContextTable::WIZARD_SUPERVISOR_CLASS
275 <<
" as part of the context configuration! "
276 <<
"Neither (or both) were found." << __E__;
283 allTraceControllerSupervisorInfo_.clear();
285 if(theARTDAQSupervisorInfo_)
287 __COUT__ <<
"The ARTDAQ TRACE-controller app for hostname '"
288 << theARTDAQSupervisorInfo_->getHostname()
289 <<
"' is CLASS:LID = " << theARTDAQSupervisorInfo_->getClass() <<
":"
290 << theARTDAQSupervisorInfo_->getId() << __E__;
293 allTraceControllerSupervisorInfo_.emplace(
294 std::pair<std::string, const SupervisorInfo&>(
295 theARTDAQSupervisorInfo_->getHostname(), *theARTDAQSupervisorInfo_));
299 for(
auto& TRACEApp : allSupervisorInfo_)
302 if(allTraceControllerSupervisorInfo_
303 .emplace(std::pair<std::string, const SupervisorInfo&>(
304 TRACEApp.second.getHostname(),
305 allSupervisorInfo_.at(TRACEApp.first)))
308 __COUT__ <<
"The TRACE-controller app for hostname '"
309 << TRACEApp.second.getHostname()
310 <<
"' is CLASS:LID = " << TRACEApp.second.getClass() <<
":"
311 << TRACEApp.second.getId()
312 <<
" name = " << TRACEApp.second.getName() << __E__;
319 __COUT__ <<
"TRACE-controller app count = "
320 << allTraceControllerSupervisorInfo_.size() << __E__;
330 SupervisorDescriptorInfoBase::destroy();
332 __COUT__ <<
"Supervisor Info initialization complete!" << __E__;
339 const SupervisorInfo& AllSupervisorInfo::getSupervisorInfo(xdaq::Application* app)
const
341 auto it = allSupervisorInfo_.find(app->getApplicationDescriptor()->getLocalId());
342 if(it == allSupervisorInfo_.end())
344 __SS__ <<
"Could not find: " << app->getApplicationDescriptor()->getLocalId()
353 xdaq::Application* app,
354 const std::string& status,
355 const unsigned int progress,
356 const std::string& detail,
357 std::vector<SupervisorInfo::SubappInfo> subapps)
360 app->getApplicationDescriptor()->getLocalId(), status, progress, detail, subapps);
365 const std::string& status,
366 const unsigned int progress,
367 const std::string& detail,
368 std::vector<SupervisorInfo::SubappInfo> subapps)
374 const unsigned int&
id,
375 const std::string& status,
376 const unsigned int progress,
377 const std::string& detail,
378 std::vector<SupervisorInfo::SubappInfo> subapps)
380 auto it = allSupervisorInfo_.find(
id);
381 if(it == allSupervisorInfo_.end())
383 __SS__ <<
"Could not find: " <<
id << __E__;
387 if(allSupervisorInfoMutex_[
id].try_lock())
389 it->second.setStatus(status, progress, detail);
391 if(it->second.getSubappInfo().size() != subapps.size())
392 it->second.clearSubapps();
393 for(
auto& subapp : subapps)
395 it->second.copySubappStatus(subapp);
397 allSupervisorInfoMutex_[id].unlock();
402 void AllSupervisorInfo::clearSupervisorSubappsStatus(
const SupervisorInfo& appInfo)
404 auto it = allSupervisorInfo_.find(appInfo.getId());
405 if(it == allSupervisorInfo_.end())
407 __SS__ <<
"Could not find: " << appInfo.getId() << __E__;
411 if(allSupervisorInfoMutex_[appInfo.getId()].try_lock())
413 it->second.clearSubapps();
414 allSupervisorInfoMutex_[appInfo.getId()].unlock();
419 const SupervisorInfo& AllSupervisorInfo::getGatewayInfo(
void)
const
421 if(!theSupervisorInfo_)
423 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type "
424 << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS <<
" found!" << __E__
428 return *theSupervisorInfo_;
431 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getGatewayDescriptor(
438 const SupervisorInfo& AllSupervisorInfo::getWizardInfo(
void)
const
442 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type "
443 << XDAQContextTable::WIZARD_SUPERVISOR_CLASS <<
" found!" << __E__;
446 return *theWizardInfo_;
449 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getWizardDescriptor(
456 const SupervisorInfo& AllSupervisorInfo::getArtdaqSupervisorInfo(
void)
const
458 if(!theARTDAQSupervisorInfo_)
460 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type "
461 << XDAQContextTable::ARTDAQ_SUPERVISOR_CLASS <<
" found!" << __E__;
464 return *theARTDAQSupervisorInfo_;
468 std::vector<std::vector<const SupervisorInfo*>>
469 AllSupervisorInfo::getOrderedSupervisorDescriptors(
470 const std::string& stateMachineCommand,
bool onlyGatewayContextSupervisors)
const
472 __COUT__ <<
"getOrderedSupervisorDescriptors for command " << stateMachineCommand
475 std::map<uint64_t , std::vector<
unsigned int >>
481 const std::vector<XDAQContextTable::XDAQContext>& contexts =
484 for(
const auto& context : contexts)
486 for(
const auto& app : context.applications_)
491 auto it = app.stateMachineCommandPriority_.find(stateMachineCommand);
492 if(it == app.stateMachineCommandPriority_.end())
499 orderedByPriority[it->second ? it->second
509 __COUT_ERR__ <<
"SupervisorDescriptorInfoBase could not access the XDAQ Context "
510 "and Application configuration through the Context Table "
516 __COUT__ <<
"Here is the order supervisors will be " << stateMachineCommand
522 std::vector<std::vector<const SupervisorInfo*>> retVec;
523 bool createContainer;
524 const std::string whitespace =
" ";
525 for(
const auto& priorityAppVector : orderedByPriority)
527 createContainer =
true;
529 for(
const auto& priorityApp : priorityAppVector.second)
531 auto it = allSupervisorInfo_.find(priorityApp);
532 if(it == allSupervisorInfo_.end())
535 <<
"Error! Was AllSupervisorInfo properly initialized? The app.id_ "
536 << priorityApp <<
" priority "
537 << (
unsigned int)priorityAppVector.first
538 <<
" could not be found in AllSupervisorInfo. Was the Context "
539 "changed? Rebooting ots may fix this issue."
548 if(onlyGatewayContextSupervisors &&
549 it->second.getContextName() != theSupervisorInfo_->getContextName())
552 if(it->second.isGatewaySupervisor())
554 if(it->second.isTypeLogbookSupervisor())
556 if(it->second.isTypeMacroMakerSupervisor())
558 if(it->second.isTypeConfigurationGUISupervisor())
560 if(it->second.isTypeChatSupervisor())
562 if(it->second.isTypeConsoleSupervisor())
564 if(it->second.isTypeCodeEditorSupervisor())
569 retVec.push_back(std::vector<const SupervisorInfo*>());
577 createContainer =
false;
579 retVec[retVec.size() - 1].push_back(&(it->second));
581 __COUT__ <<
"\t" << it->second.getName() <<
" [LID=" << it->second.getId()
583 << (it->second.getName().size() > whitespace.size()
586 0, whitespace.size() - it->second.getName().size()))
587 <<
" priority " << (
unsigned int)priorityAppVector.first <<
" count "
588 << retVec[retVec.size() - 1].size() << __E__;
void setSupervisorStatus(xdaq::Application *app, const std::string &status, const unsigned int progress=100, const std::string &detail="", std::vector< SupervisorInfo::SubappInfo > subapps={})
SETTERs.
bool isWizardMode(void) const
BOOLs.
XDAQ_CONST_CALL xdaq::ApplicationDescriptor * getDescriptor(void) const
Getters ----------------—.
std::string getContextUID(const std::string &url) const
static std::string stackTrace(void)
static const uint8_t DEFAULT_PRIORITY