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 = ((getenv(
"MACROMAKER_MODE") == NULL)
15 : ((std::string(__ENV__(
"MACROMAKER_MODE")) ==
"1") ?
true :
false));
18 AllSupervisorInfo::AllSupervisorInfo(
void) : theSupervisorInfo_(0), theWizardInfo_(0) {}
21 AllSupervisorInfo::AllSupervisorInfo(xdaq::ApplicationContext* applicationContext) :
AllSupervisorInfo() { 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();
40 void AllSupervisorInfo::init(xdaq::ApplicationContext* applicationContext)
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)
75 descriptor.second ,
"" ,
""
79 if(tempSupervisorInfo.isGatewaySupervisor())
85 else if(tempSupervisorInfo.isWizardSupervisor())
93 if(AllSupervisorInfo::MACROMAKER_MODE)
94 __COUT__ <<
"Initializing info for Macro Maker mode XDAQ context..." << __E__;
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((isWizardMode || AllSupervisorInfo::MACROMAKER_MODE) ? 0 :
new ConfigurationManager());
105 for(
const auto& descriptor : allDescriptors)
107 auto emplacePair = allSupervisorInfo_.emplace(std::pair<unsigned int, SupervisorInfo>(
108 descriptor.second->getLocalId(),
111 contextConfig ? contextConfig->getApplicationUID(descriptor.second->getContextDescriptor()->getURL(), descriptor.second->getLocalId())
113 contextConfig ? contextConfig->getContextUID(descriptor.second->getContextDescriptor()->getURL()) :
""
115 if(!emplacePair.second)
117 __SS__ <<
"Error! Duplicate Application IDs are not allowed. ID =" << descriptor.second->getLocalId() << __E__;
126 if(emplacePair.first->second.isGatewaySupervisor())
128 if(theSupervisorInfo_)
130 __SS__ <<
"Error! Multiple Gateway Supervisors of class " << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS
131 <<
" found. There can only be one. ID =" << descriptor.second->getLocalId() << __E__;
135 theSupervisorInfo_ = &(emplacePair.first->second);
141 if(emplacePair.first->second.isWizardSupervisor())
145 __SS__ <<
"Error! Multiple Wizard Supervisors of class " << XDAQContextTable::WIZARD_SUPERVISOR_CLASS
146 <<
" found. There can only be one. ID =" << descriptor.second->getLocalId() << __E__;
150 theWizardInfo_ = &(emplacePair.first->second);
156 if(emplacePair.first->second.isTypeFESupervisor())
158 allFETypeSupervisorInfo_.emplace(std::pair<unsigned int, const SupervisorInfo&>(emplacePair.first->second.getId(), emplacePair.first->second));
163 if(emplacePair.first->second.isTypeDMSupervisor())
165 allDMTypeSupervisorInfo_.emplace(std::pair<unsigned int, const SupervisorInfo&>(emplacePair.first->second.getId(), emplacePair.first->second));
170 if(emplacePair.first->second.isTypeLogbookSupervisor())
172 allLogbookTypeSupervisorInfo_.emplace(std::pair<unsigned int, const SupervisorInfo&>(emplacePair.first->second.getId(), emplacePair.first->second));
177 if(emplacePair.first->second.isTypeMacroMakerSupervisor())
179 allMacroMakerTypeSupervisorInfo_.emplace(
180 std::pair<unsigned int, const SupervisorInfo&>(emplacePair.first->second.getId(), emplacePair.first->second));
185 if(AllSupervisorInfo::MACROMAKER_MODE)
187 if(theWizardInfo_ || theSupervisorInfo_)
189 __SS__ <<
"Error! For MacroMaker mode, must not have one " << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS <<
" OR one "
190 << XDAQContextTable::WIZARD_SUPERVISOR_CLASS <<
" as part of the context configuration! "
191 <<
"One was found." << __E__;
195 else if((!theWizardInfo_ && !theSupervisorInfo_) || (theWizardInfo_ && theSupervisorInfo_))
197 __SS__ <<
"Error! Must have one " << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS <<
" OR one " << XDAQContextTable::WIZARD_SUPERVISOR_CLASS
198 <<
" as part of the context configuration! "
199 <<
"Neither (or both) were found." << __E__;
203 SupervisorDescriptorInfoBase::destroy();
205 __COUT__ <<
"Supervisor Info initialization complete!" << __E__;
212 const SupervisorInfo& AllSupervisorInfo::getSupervisorInfo(xdaq::Application* app)
const
214 auto it = allSupervisorInfo_.find(app->getApplicationDescriptor()->getLocalId());
215 if(it == allSupervisorInfo_.end())
217 __SS__ <<
"Could not find: " << app->getApplicationDescriptor()->getLocalId() << std::endl;
224 void AllSupervisorInfo::setSupervisorStatus(xdaq::Application* app,
const std::string& status,
const unsigned int progress,
const std::string& detail)
226 setSupervisorStatus(app->getApplicationDescriptor()->getLocalId(), status, progress, detail);
229 void AllSupervisorInfo::setSupervisorStatus(
const SupervisorInfo& appInfo,
const std::string& status,
const unsigned int progress,
const std::string& detail)
231 setSupervisorStatus(appInfo.getId(), status, progress, detail);
234 void AllSupervisorInfo::setSupervisorStatus(
const unsigned int&
id,
const std::string& status,
const unsigned int progress,
const std::string& detail)
236 auto it = allSupervisorInfo_.find(
id);
237 if(it == allSupervisorInfo_.end())
239 __SS__ <<
"Could not find: " <<
id << __E__;
242 it->second.setStatus(status, progress, detail);
246 const SupervisorInfo& AllSupervisorInfo::getGatewayInfo(
void)
const
248 if(!theSupervisorInfo_)
250 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type " << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS <<
" found!" << __E__;
253 return *theSupervisorInfo_;
256 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getGatewayDescriptor(
void)
const {
return getGatewayInfo().getDescriptor(); }
259 const SupervisorInfo& AllSupervisorInfo::getWizardInfo(
void)
const
263 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type " << XDAQContextTable::WIZARD_SUPERVISOR_CLASS <<
" found!" << __E__;
266 return *theWizardInfo_;
269 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getWizardDescriptor(
void)
const {
return getWizardInfo().getDescriptor(); }
272 std::vector<std::vector<const SupervisorInfo*>> AllSupervisorInfo::getOrderedSupervisorDescriptors(
const std::string& stateMachineCommand)
const
274 __COUT__ <<
"getOrderedSupervisorDescriptors" << __E__;
276 std::map<uint64_t , std::vector<
unsigned int >> orderedByPriority;
281 const std::vector<XDAQContextTable::XDAQContext>& contexts = cfgMgr.__GET_CONFIG__(
XDAQContextTable)->getContexts();
283 for(
const auto& context : contexts)
285 for(
const auto& app : context.applications_)
290 auto it = app.stateMachineCommandPriority_.find(stateMachineCommand);
291 if(it == app.stateMachineCommandPriority_.end())
292 orderedByPriority[XDAQContextTable::XDAQApplication::DEFAULT_PRIORITY].push_back(
297 orderedByPriority[it->second ? it->second : XDAQContextTable::XDAQApplication::DEFAULT_PRIORITY].push_back(app.id_);
304 __COUT_ERR__ <<
"SupervisorDescriptorInfoBase could not access the XDAQ Context "
305 "and Application configuration through the Context Table "
311 __COUT__ <<
"Here is the order supervisors will be " << stateMachineCommand <<
"'d:" << __E__;
316 std::vector<std::vector<const SupervisorInfo*>> retVec;
317 bool createContainer;
318 for(
const auto& priorityAppVector : orderedByPriority)
320 createContainer =
true;
322 for(
const auto& priorityApp : priorityAppVector.second)
324 auto it = allSupervisorInfo_.find(priorityApp);
325 if(it == allSupervisorInfo_.end())
327 __SS__ <<
"Error! Was AllSupervisorInfo properly initialized? The app.id_ " << priorityApp <<
" priority "
328 << (
unsigned int)priorityAppVector.first <<
" could not be found in AllSupervisorInfo." << __E__;
336 if(it->second.isGatewaySupervisor())
338 if(it->second.isTypeLogbookSupervisor())
340 if(it->second.isTypeMacroMakerSupervisor())
342 if(it->second.isTypeConfigurationGUISupervisor())
344 if(it->second.isTypeChatSupervisor())
346 if(it->second.isTypeConsoleSupervisor())
351 retVec.push_back(std::vector<const SupervisorInfo*>());
359 createContainer =
false;
361 retVec[retVec.size() - 1].push_back(&(it->second));
363 __COUT__ << it->second.getName() <<
" [LID=" << it->second.getId() <<
"]: "
364 <<
" priority " << (
unsigned int)priorityAppVector.first <<
" count " << retVec[retVec.size() - 1].size() << __E__;