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(
132 std::string name, contextName;
136 for(
const auto& descriptor : allDescriptors)
138 name = contextConfig ? contextConfig->getApplicationUID(
139 descriptor.second->getContextDescriptor()->getURL(),
140 descriptor.second->getLocalId())
142 contextName = contextConfig
144 descriptor.second->getContextDescriptor()->getURL())
148 allSupervisorInfo_.emplace(std::pair<unsigned int, SupervisorInfo>(
149 descriptor.second->getLocalId(),
151 if(!emplacePair.second)
153 __SS__ <<
"Error! Duplicate Application IDs are not allowed. ID ="
154 << descriptor.second->getLocalId() << __E__;
163 if(emplacePair.first->second.isTypeARTDAQSupervisor())
166 if(theARTDAQSupervisorInfo_)
168 __SS__ <<
"Error! Multiple ARTDAQ Supervisors of class "
169 << XDAQContextTable::ARTDAQ_SUPERVISOR_CLASS
170 <<
" found. There can only be one. ID ="
171 << descriptor.second->getLocalId() << __E__;
175 theARTDAQSupervisorInfo_ = &(emplacePair.first->second);
183 if(emplacePair.first->second.isGatewaySupervisor())
185 if(theSupervisorInfo_)
187 __SS__ <<
"Error! Multiple Gateway Supervisors of class "
188 << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS
189 <<
" found. There can only be one. ID ="
190 << descriptor.second->getLocalId() << __E__;
193 theSupervisorInfo_ = &(emplacePair.first->second);
199 if(emplacePair.first->second.isWizardSupervisor())
203 __SS__ <<
"Error! Multiple Wizard Supervisors of class "
204 << XDAQContextTable::WIZARD_SUPERVISOR_CLASS
205 <<
" found. There can only be one. ID ="
206 << descriptor.second->getLocalId() << __E__;
209 theWizardInfo_ = &(emplacePair.first->second);
216 if(emplacePair.first->second.isTypeFESupervisor())
218 allFETypeSupervisorInfo_.emplace(
219 std::pair<unsigned int, const SupervisorInfo&>(
220 emplacePair.first->second.getId(), emplacePair.first->second));
225 if(emplacePair.first->second.isTypeDMSupervisor())
227 allDMTypeSupervisorInfo_.emplace(
228 std::pair<unsigned int, const SupervisorInfo&>(
229 emplacePair.first->second.getId(), emplacePair.first->second));
234 if(emplacePair.first->second.isTypeLogbookSupervisor())
236 allLogbookTypeSupervisorInfo_.emplace(
237 std::pair<unsigned int, const SupervisorInfo&>(
238 emplacePair.first->second.getId(), emplacePair.first->second));
243 if(emplacePair.first->second.isTypeMacroMakerSupervisor())
245 allMacroMakerTypeSupervisorInfo_.emplace(
246 std::pair<unsigned int, const SupervisorInfo&>(
247 emplacePair.first->second.getId(), emplacePair.first->second));
252 if(AllSupervisorInfo::MACROMAKER_MODE)
254 if(theWizardInfo_ || theSupervisorInfo_)
256 __SS__ <<
"Error! For MacroMaker mode, must not have one "
257 << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS <<
" OR one "
258 << XDAQContextTable::WIZARD_SUPERVISOR_CLASS
259 <<
" as part of the context configuration! "
260 <<
"One was found." << __E__;
263 if(allMacroMakerTypeSupervisorInfo_.size() != 1)
265 __SS__ <<
"Error! For MacroMaker mode, must have one and only one "
266 << *(XDAQContextTable::MacroMakerTypeClassNames_.begin())
267 <<
" as part of the context configuration! "
268 << allMacroMakerTypeSupervisorInfo_.size() <<
" were found." << __E__;
272 else if((!theWizardInfo_ && !theSupervisorInfo_) ||
273 (theWizardInfo_ && theSupervisorInfo_))
275 __SS__ <<
"Error! Must have one " << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS
276 <<
" OR one " << XDAQContextTable::WIZARD_SUPERVISOR_CLASS
277 <<
" as part of the context configuration! "
278 <<
"Neither (or both) were found." << __E__;
285 allTraceControllerSupervisorInfo_.clear();
287 if(theARTDAQSupervisorInfo_)
289 __COUT__ <<
"The ARTDAQ TRACE-controller app for hostname '"
290 << theARTDAQSupervisorInfo_->getHostname()
291 <<
"' is CLASS:LID = " << theARTDAQSupervisorInfo_->getClass() <<
":"
292 << theARTDAQSupervisorInfo_->getId() << __E__;
295 allTraceControllerSupervisorInfo_.emplace(
296 std::pair<std::string, const SupervisorInfo&>(
297 theARTDAQSupervisorInfo_->getHostname(), *theARTDAQSupervisorInfo_));
301 for(
auto& TRACEApp : allSupervisorInfo_)
304 if(allTraceControllerSupervisorInfo_
305 .emplace(std::pair<std::string, const SupervisorInfo&>(
306 TRACEApp.second.getHostname(),
307 allSupervisorInfo_.at(TRACEApp.first)))
310 __COUT__ <<
"The TRACE-controller app for hostname '"
311 << TRACEApp.second.getHostname()
312 <<
"' is CLASS:LID = " << TRACEApp.second.getClass() <<
":"
313 << TRACEApp.second.getId()
314 <<
" name = " << TRACEApp.second.getName() << __E__;
321 __COUT__ <<
"TRACE-controller app count = "
322 << allTraceControllerSupervisorInfo_.size() << __E__;
332 SupervisorDescriptorInfoBase::destroy();
334 __COUT__ <<
"Supervisor Info initialization complete!" << __E__;
341 const SupervisorInfo& AllSupervisorInfo::getSupervisorInfo(xdaq::Application* app)
const
343 auto it = allSupervisorInfo_.find(app->getApplicationDescriptor()->getLocalId());
344 if(it == allSupervisorInfo_.end())
346 __SS__ <<
"Could not find: " << app->getApplicationDescriptor()->getLocalId()
355 xdaq::Application* app,
356 const std::string& status,
357 const unsigned int progress,
358 const std::string& detail,
359 std::vector<SupervisorInfo::SubappInfo> subapps,
360 const uint64_t availableLogSpaceKB,
361 const uint64_t availableDataSpaceKB)
369 availableDataSpaceKB);
374 const std::string& status,
375 const unsigned int progress,
376 const std::string& detail,
377 std::vector<SupervisorInfo::SubappInfo> subapps,
378 const uint64_t availableLogSpaceKB,
379 const uint64_t availableDataSpaceKB)
387 availableDataSpaceKB);
391 const unsigned int&
id,
392 const std::string& status,
393 const unsigned int progress,
394 const std::string& detail,
395 std::vector<SupervisorInfo::SubappInfo> subapps,
396 const uint64_t availableLogSpaceKB,
397 const uint64_t availableDataSpaceKB)
399 auto it = allSupervisorInfo_.find(
id);
400 if(it == allSupervisorInfo_.end())
402 __SS__ <<
"Could not find: " <<
id << __E__;
406 if(allSupervisorInfoMutex_[
id].try_lock())
409 __COUT__ <<
"What happened 2? " << progress << __E__;
410 it->second.setStatus(
411 status, progress, detail, availableLogSpaceKB, availableDataSpaceKB);
413 if(it->second.getSubappInfo().size() != subapps.size())
414 it->second.clearSubapps();
415 for(
auto& subapp : subapps)
417 it->second.copySubappStatus(subapp);
419 allSupervisorInfoMutex_[id].unlock();
424 void AllSupervisorInfo::clearSupervisorSubappsStatus(
const SupervisorInfo& appInfo)
426 auto it = allSupervisorInfo_.find(appInfo.getId());
427 if(it == allSupervisorInfo_.end())
429 __SS__ <<
"Could not find: " << appInfo.getId() << __E__;
433 if(allSupervisorInfoMutex_[appInfo.getId()].try_lock())
435 it->second.clearSubapps();
436 allSupervisorInfoMutex_[appInfo.getId()].unlock();
441 const SupervisorInfo& AllSupervisorInfo::getGatewayInfo(
void)
const
443 if(!theSupervisorInfo_)
445 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type "
446 << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS <<
" found!" << __E__
450 return *theSupervisorInfo_;
453 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getGatewayDescriptor(
460 const SupervisorInfo& AllSupervisorInfo::getWizardInfo(
void)
const
464 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type "
465 << XDAQContextTable::WIZARD_SUPERVISOR_CLASS <<
" found!" << __E__;
468 return *theWizardInfo_;
471 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getWizardDescriptor(
478 const SupervisorInfo& AllSupervisorInfo::getArtdaqSupervisorInfo(
void)
const
480 if(!theARTDAQSupervisorInfo_)
482 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type "
483 << XDAQContextTable::ARTDAQ_SUPERVISOR_CLASS <<
" found!" << __E__;
486 return *theARTDAQSupervisorInfo_;
490 std::vector<std::vector<const SupervisorInfo*>>
491 AllSupervisorInfo::getOrderedSupervisorDescriptors(
492 const std::string& stateMachineCommand,
bool onlyGatewayContextSupervisors)
const
494 __COUT__ <<
"getOrderedSupervisorDescriptors for command " << stateMachineCommand
497 std::map<uint64_t , std::vector<
unsigned int >>
503 const std::vector<XDAQContextTable::XDAQContext>& contexts =
506 for(
const auto& context : contexts)
508 for(
const auto& app : context.applications_)
513 auto it = app.stateMachineCommandPriority_.find(stateMachineCommand);
514 if(it == app.stateMachineCommandPriority_.end())
521 orderedByPriority[it->second ? it->second
531 __COUT_ERR__ <<
"SupervisorDescriptorInfoBase could not access the XDAQ Context "
532 "and Application configuration through the Context Table "
538 __COUT__ <<
"Here is the order supervisors will be " << stateMachineCommand
544 std::vector<std::vector<const SupervisorInfo*>> retVec;
545 bool createContainer;
546 const std::string whitespace =
" ";
547 for(
const auto& priorityAppVector : orderedByPriority)
549 createContainer =
true;
551 for(
const auto& priorityApp : priorityAppVector.second)
553 auto it = allSupervisorInfo_.find(priorityApp);
554 if(it == allSupervisorInfo_.end())
557 <<
"Error! Was AllSupervisorInfo properly initialized? The app.id_ "
558 << priorityApp <<
" priority "
559 << (
unsigned int)priorityAppVector.first
560 <<
" could not be found in AllSupervisorInfo. Was the Context "
561 "changed? Rebooting ots may fix this issue."
570 if(onlyGatewayContextSupervisors &&
571 it->second.getContextName() != theSupervisorInfo_->getContextName())
574 if(it->second.isGatewaySupervisor())
576 if(it->second.isTypeLogbookSupervisor())
578 if(it->second.isTypeMacroMakerSupervisor())
580 if(it->second.isTypeConfigurationGUISupervisor())
582 if(it->second.isTypeChatSupervisor())
584 if(it->second.isTypeConsoleSupervisor())
586 if(it->second.isTypeCodeEditorSupervisor())
591 retVec.push_back(std::vector<const SupervisorInfo*>());
599 createContainer =
false;
601 retVec[retVec.size() - 1].push_back(&(it->second));
603 __COUT__ <<
"\t" << it->second.getName() <<
" [LID=" << it->second.getId()
605 << (it->second.getName().size() > whitespace.size()
608 0, whitespace.size() - it->second.getName().size()))
609 <<
" priority " << (
unsigned int)priorityAppVector.first <<
" count "
610 << retVec[retVec.size() - 1].size() << __E__;
bool isWizardMode(void) const
BOOLs.
void setSupervisorStatus(xdaq::Application *app, const std::string &status, const unsigned int progress=100, const std::string &detail="", std::vector< SupervisorInfo::SubappInfo > subapps={}, const uint64_t availableLogSpaceKB=0, const uint64_t availableDataSpaceKB=0)
SETTERs.
XDAQ_CONST_CALL xdaq::ApplicationDescriptor * getDescriptor(void) const
Getters ----------------—.
std::string getContextUID(const std::string &url) const
defines used also by OtsConfigurationWizardSupervisor
static std::string stackTrace(void)
static const uint8_t DEFAULT_PRIORITY