1 #include "otsdaq-core/SupervisorInfo/AllSupervisorInfo.h"
3 #include "otsdaq-core/MessageFacility/MessageFacility.h"
4 #include "otsdaq-core/Macros/CoutHeaderMacros.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 AllSupervisorInfo::destroy();
55 SupervisorDescriptorInfoBase::init(applicationContext);
63 auto allDescriptors = SupervisorDescriptorInfoBase::getAllDescriptors();
64 for(
const auto& descriptor:allDescriptors)
66 auto emplacePair = allSupervisorInfo_.emplace(std::pair<unsigned int, SupervisorInfo>(
67 descriptor.second->getLocalId(),
70 contextConfig->getApplicationUID
72 descriptor.second->getContextDescriptor()->getURL(),
73 descriptor.second->getLocalId()
75 contextConfig->getContextUID(
76 descriptor.second->getContextDescriptor()->getURL())
78 if(!emplacePair.second)
80 __SS__ <<
"Error! Duplicate Application IDs are not allowed. ID =" <<
81 descriptor.second->getLocalId() << __E__;
90 if(emplacePair.first->second.isGatewaySupervisor())
92 if(theSupervisorInfo_)
94 __SS__ <<
"Error! Multiple Gateway Supervisors of class " << XDAQContextConfiguration::GATEWAY_SUPERVISOR_CLASS <<
95 " found. There can only be one. ID =" <<
96 descriptor.second->getLocalId() << __E__;
100 theSupervisorInfo_ = &(emplacePair.first->second);
106 if(emplacePair.first->second.isWizardSupervisor())
110 __SS__ <<
"Error! Multiple Wizard Supervisors of class " << XDAQContextConfiguration::WIZARD_SUPERVISOR_CLASS <<
111 " found. There can only be one. ID =" <<
112 descriptor.second->getLocalId() << __E__;
116 theWizardInfo_ = &(emplacePair.first->second);
123 if(emplacePair.first->second.isTypeFESupervisor())
125 allFETypeSupervisorInfo_.emplace(std::pair<unsigned int, const SupervisorInfo&>(
126 emplacePair.first->second.getId(),
127 emplacePair.first->second));
132 if(emplacePair.first->second.isTypeDMSupervisor())
134 allDMTypeSupervisorInfo_.emplace(std::pair<unsigned int, const SupervisorInfo&>(
135 emplacePair.first->second.getId(),
136 emplacePair.first->second));
141 if(emplacePair.first->second.isTypeLogbookSupervisor())
143 allLogbookTypeSupervisorInfo_.emplace(std::pair<unsigned int, const SupervisorInfo&>(
144 emplacePair.first->second.getId(),
145 emplacePair.first->second));
151 if((!theWizardInfo_ && !theSupervisorInfo_) ||
152 (theWizardInfo_ && theSupervisorInfo_))
154 __SS__ <<
"Error! Must have one " << XDAQContextConfiguration::GATEWAY_SUPERVISOR_CLASS <<
155 " OR one " << XDAQContextConfiguration::WIZARD_SUPERVISOR_CLASS <<
156 " as part of the context configuration! " <<
157 "Neither were found." << __E__;
162 SupervisorDescriptorInfoBase::destroy();
164 __COUT__ <<
"Init" << __E__;
171 const SupervisorInfo& AllSupervisorInfo::getSupervisorInfo(xdaq::Application* app)
const
173 auto it = allSupervisorInfo_.find(app->getApplicationDescriptor()->getLocalId());
174 if(it == allSupervisorInfo_.end())
176 __SS__ <<
"Could not find: " << app->getApplicationDescriptor()->getLocalId() << std::endl;
183 void AllSupervisorInfo::setSupervisorStatus(xdaq::Application* app,
184 const std::string& status)
186 setSupervisorStatus(app->getApplicationDescriptor()->getLocalId(), status);
189 void AllSupervisorInfo::setSupervisorStatus(
const SupervisorInfo& appInfo,
190 const std::string& status)
192 setSupervisorStatus(appInfo.getId(), status);
195 void AllSupervisorInfo::setSupervisorStatus(
const unsigned int&
id,
196 const std::string& status)
198 auto it = allSupervisorInfo_.find(
id);
199 if(it == allSupervisorInfo_.end())
201 __SS__ <<
"Could not find: " <<
id << std::endl;
204 it->second.setStatus(status);
208 const SupervisorInfo& AllSupervisorInfo::getGatewayInfo(
void)
const
210 if(!theSupervisorInfo_)
212 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type " <<
213 XDAQContextConfiguration::GATEWAY_SUPERVISOR_CLASS <<
" found!" << __E__;
216 return *theSupervisorInfo_;
219 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getGatewayDescriptor(
void)
const
221 return getGatewayInfo().getDescriptor();
225 const SupervisorInfo& AllSupervisorInfo::getWizardInfo(
void)
const
229 __SS__ <<
"AllSupervisorInfo was not initialized or no Application of type " <<
230 XDAQContextConfiguration::WIZARD_SUPERVISOR_CLASS <<
" found!" << __E__;
233 return *theWizardInfo_;
236 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getWizardDescriptor(
void)
const
238 return getWizardInfo().getDescriptor();
243 std::vector<const SupervisorInfo*> AllSupervisorInfo::getOrderedSupervisorDescriptors(
244 const std::string& stateMachineCommand)
const
246 __COUT__ <<
"getOrderedSupervisorDescriptors" << __E__;
248 std::map<uint8_t , std::vector<
unsigned int > > orderedByPriority;
253 const std::vector<XDAQContextConfiguration::XDAQContext>& contexts =
256 for (
const auto& context : contexts)
258 for (
const auto& app : context.applications_)
260 if(!app.status_)
continue;
262 auto it = app.stateMachineCommandPriority_.find(stateMachineCommand);
263 if(it == app.stateMachineCommandPriority_.end())
264 orderedByPriority[100].push_back(app.id_);
266 orderedByPriority[it->second?it->second:100].push_back(app.id_);
273 __COUT_ERR__ <<
"SupervisorDescriptorInfoBase could not access the XDAQ Context and Application configuration through the Configuration Context Group." << __E__;
278 __COUT__ <<
"Here is the order supervisors will be " << stateMachineCommand <<
"'d:" << __E__;
283 std::vector<const SupervisorInfo*> retVec;
284 for (
const auto& priorityAppVector : orderedByPriority)
285 for (
const auto& priorityApp : priorityAppVector.second)
287 auto it = allSupervisorInfo_.find(priorityApp);
288 if(it == allSupervisorInfo_.end())
290 __SS__ <<
"Error! Was AllSupervisorInfo properly initialized? The app.id_ " << priorityApp <<
" priority " <<
291 (
unsigned int)priorityAppVector.first <<
" could not be found in AllSupervisorInfo." << __E__;
298 if(it->second.isGatewaySupervisor())
continue;
299 if(it->second.isTypeLogbookSupervisor())
continue;
300 if(it->second.isTypeMacroMakerSupervisor())
continue;
301 if(it->second.isTypeConfigurationGUISupervisor())
continue;
302 if(it->second.isTypeChatSupervisor())
continue;
303 if(it->second.isTypeConsoleSupervisor())
continue;
305 retVec.push_back(&(it->second));
306 __COUT__ << it->second.getName() <<
" [LID=" << it->second.getId() <<
"]: " <<
" priority " <<
307 (
unsigned int)priorityAppVector.first << __E__;