00001 #include "otsdaq-core/SupervisorInfo/AllSupervisorInfo.h"
00002
00003 #include "otsdaq-core/MessageFacility/MessageFacility.h"
00004 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
00005
00006 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
00007 #include "otsdaq-core/ConfigurationPluginDataFormats/XDAQContextConfiguration.h"
00008
00009
00010 #include <iostream>
00011
00012
00013
00014 using namespace ots;
00015
00016
00017
00018
00019 AllSupervisorInfo::AllSupervisorInfo(void)
00020 : theSupervisorInfo_ (0)
00021 , theWizardInfo_ (0)
00022 {
00023 }
00024
00025
00026 AllSupervisorInfo::AllSupervisorInfo(xdaq::ApplicationContext* applicationContext)
00027 : AllSupervisorInfo()
00028 {
00029 init(applicationContext);
00030 }
00031
00032
00033 AllSupervisorInfo::~AllSupervisorInfo(void)
00034 {
00035 destroy();
00036 }
00037
00038
00039 void AllSupervisorInfo::destroy(void)
00040 {
00041 allSupervisorInfo_.clear();
00042 allFETypeSupervisorInfo_.clear();
00043 allDMTypeSupervisorInfo_.clear();
00044
00045 theSupervisorInfo_ = 0;
00046 theWizardInfo_ = 0;
00047
00048 SupervisorDescriptorInfoBase::destroy();
00049 }
00050
00051
00052 void AllSupervisorInfo::init(xdaq::ApplicationContext* applicationContext)
00053 {
00054 AllSupervisorInfo::destroy();
00055 SupervisorDescriptorInfoBase::init(applicationContext);
00056
00057
00058
00059 ConfigurationManager cfgMgr;
00060 const XDAQContextConfiguration* contextConfig =
00061 cfgMgr.__GET_CONFIG__(XDAQContextConfiguration);
00062
00063 auto allDescriptors = SupervisorDescriptorInfoBase::getAllDescriptors();
00064 for(const auto& descriptor:allDescriptors)
00065 {
00066 auto emplacePair = allSupervisorInfo_.emplace(std::pair<unsigned int, SupervisorInfo>(
00067 descriptor.second->getLocalId(),
00068 SupervisorInfo(
00069 descriptor.second ,
00070 contextConfig->getApplicationUID
00071 (
00072 descriptor.second->getContextDescriptor()->getURL(),
00073 descriptor.second->getLocalId()
00074 ) ,
00075 contextConfig->getContextUID(
00076 descriptor.second->getContextDescriptor()->getURL())
00077 )));
00078 if(!emplacePair.second)
00079 {
00080 __SS__ << "Error! Duplicate Application IDs are not allowed. ID =" <<
00081 descriptor.second->getLocalId() << __E__;
00082 __SS_THROW__;
00083 }
00084
00086
00087
00088
00089
00090 if(emplacePair.first->second.isGatewaySupervisor())
00091 {
00092 if(theSupervisorInfo_)
00093 {
00094 __SS__ << "Error! Multiple Gateway Supervisors of class " << XDAQContextConfiguration::GATEWAY_SUPERVISOR_CLASS <<
00095 " found. There can only be one. ID =" <<
00096 descriptor.second->getLocalId() << __E__;
00097 __SS_THROW__;
00098 }
00099
00100 theSupervisorInfo_ = &(emplacePair.first->second);
00101 continue;
00102 }
00103
00104
00105
00106 if(emplacePair.first->second.isWizardSupervisor())
00107 {
00108 if(theWizardInfo_)
00109 {
00110 __SS__ << "Error! Multiple Wizard Supervisors of class " << XDAQContextConfiguration::WIZARD_SUPERVISOR_CLASS <<
00111 " found. There can only be one. ID =" <<
00112 descriptor.second->getLocalId() << __E__;
00113 __SS_THROW__;
00114 }
00115
00116 theWizardInfo_ = &(emplacePair.first->second);
00117 continue;
00118 }
00119
00120
00121
00122
00123 if(emplacePair.first->second.isTypeFESupervisor())
00124 {
00125 allFETypeSupervisorInfo_.emplace(std::pair<unsigned int, const SupervisorInfo&>(
00126 emplacePair.first->second.getId(),
00127 emplacePair.first->second));
00128 }
00129
00130
00131
00132 if(emplacePair.first->second.isTypeDMSupervisor())
00133 {
00134 allDMTypeSupervisorInfo_.emplace(std::pair<unsigned int, const SupervisorInfo&>(
00135 emplacePair.first->second.getId(),
00136 emplacePair.first->second));
00137 }
00138
00139
00140
00141 if(emplacePair.first->second.isTypeLogbookSupervisor())
00142 {
00143 allLogbookTypeSupervisorInfo_.emplace(std::pair<unsigned int, const SupervisorInfo&>(
00144 emplacePair.first->second.getId(),
00145 emplacePair.first->second));
00146 }
00147
00148 }
00149
00150
00151 if((!theWizardInfo_ && !theSupervisorInfo_) ||
00152 (theWizardInfo_ && theSupervisorInfo_))
00153 {
00154 __SS__ << "Error! Must have one " << XDAQContextConfiguration::GATEWAY_SUPERVISOR_CLASS <<
00155 " OR one " << XDAQContextConfiguration::WIZARD_SUPERVISOR_CLASS <<
00156 " as part of the context configuration! " <<
00157 "Neither were found." << __E__;
00158 __SS_THROW__;
00159 }
00160
00161
00162 SupervisorDescriptorInfoBase::destroy();
00163
00164 __COUT__ << "Init" << __E__;
00165
00166
00167
00168 }
00169
00170
00171 const SupervisorInfo& AllSupervisorInfo::getSupervisorInfo(xdaq::Application* app) const
00172 {
00173 auto it = allSupervisorInfo_.find(app->getApplicationDescriptor()->getLocalId());
00174 if(it == allSupervisorInfo_.end())
00175 {
00176 __SS__ << "Could not find: " << app->getApplicationDescriptor()->getLocalId() << std::endl;
00177 __SS_THROW__;
00178 }
00179 return it->second;
00180 }
00181
00182
00183 void AllSupervisorInfo::setSupervisorStatus(xdaq::Application* app,
00184 const std::string& status)
00185 {
00186 setSupervisorStatus(app->getApplicationDescriptor()->getLocalId(), status);
00187 }
00188
00189 void AllSupervisorInfo::setSupervisorStatus(const SupervisorInfo& appInfo,
00190 const std::string& status)
00191 {
00192 setSupervisorStatus(appInfo.getId(), status);
00193 }
00194
00195 void AllSupervisorInfo::setSupervisorStatus(const unsigned int& id,
00196 const std::string& status)
00197 {
00198 auto it = allSupervisorInfo_.find(id);
00199 if(it == allSupervisorInfo_.end())
00200 {
00201 __SS__ << "Could not find: " << id << std::endl;
00202 __SS_THROW__;
00203 }
00204 it->second.setStatus(status);
00205 }
00206
00207
00208 const SupervisorInfo& AllSupervisorInfo::getGatewayInfo(void) const
00209 {
00210 if(!theSupervisorInfo_)
00211 {
00212 __SS__ << "AllSupervisorInfo was not initialized or no Application of type " <<
00213 XDAQContextConfiguration::GATEWAY_SUPERVISOR_CLASS << " found!" << __E__;
00214 __SS_THROW__;
00215 }
00216 return *theSupervisorInfo_;
00217 }
00218
00219 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getGatewayDescriptor(void) const
00220 {
00221 return getGatewayInfo().getDescriptor();
00222 }
00223
00224
00225 const SupervisorInfo& AllSupervisorInfo::getWizardInfo(void) const
00226 {
00227 if(!theWizardInfo_)
00228 {
00229 __SS__ << "AllSupervisorInfo was not initialized or no Application of type " <<
00230 XDAQContextConfiguration::WIZARD_SUPERVISOR_CLASS << " found!" << __E__;
00231 __SS_THROW__;
00232 }
00233 return *theWizardInfo_;
00234 }
00235
00236 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getWizardDescriptor(void) const
00237 {
00238 return getWizardInfo().getDescriptor();
00239 }
00240
00241
00242
00243 std::vector<const SupervisorInfo*> AllSupervisorInfo::getOrderedSupervisorDescriptors(
00244 const std::string& stateMachineCommand) const
00245 {
00246 __COUT__ << "getOrderedSupervisorDescriptors" << __E__;
00247
00248 std::map<uint8_t , std::vector< unsigned int > > orderedByPriority;
00249
00250 try
00251 {
00252 ConfigurationManager cfgMgr;
00253 const std::vector<XDAQContextConfiguration::XDAQContext>& contexts =
00254 cfgMgr.__GET_CONFIG__(XDAQContextConfiguration)->getContexts();
00255
00256 for (const auto& context : contexts)
00257 if(context.status_)
00258 for (const auto& app : context.applications_)
00259 {
00260 if(!app.status_) continue;
00261
00262 auto it = app.stateMachineCommandPriority_.find(stateMachineCommand);
00263 if(it == app.stateMachineCommandPriority_.end())
00264 orderedByPriority[100].push_back(app.id_);
00265 else
00266 orderedByPriority[it->second?it->second:100].push_back(app.id_);
00267
00268
00269 }
00270 }
00271 catch(...)
00272 {
00273 __COUT_ERR__ << "SupervisorDescriptorInfoBase could not access the XDAQ Context and Application configuration through the Configuration Context Group." << __E__;
00274 throw;
00275 }
00276
00277
00278 __COUT__ << "Here is the order supervisors will be " << stateMachineCommand << "'d:" << __E__;
00279
00280
00281
00282
00283 std::vector<const SupervisorInfo*> retVec;
00284 for (const auto& priorityAppVector : orderedByPriority)
00285 for (const auto& priorityApp : priorityAppVector.second)
00286 {
00287 auto it = allSupervisorInfo_.find(priorityApp);
00288 if(it == allSupervisorInfo_.end())
00289 {
00290 __SS__ << "Error! Was AllSupervisorInfo properly initialized? The app.id_ " << priorityApp << " priority " <<
00291 (unsigned int)priorityAppVector.first << " could not be found in AllSupervisorInfo." << __E__;
00292 __SS_THROW__;
00293 }
00294
00295
00296
00297
00298 if(it->second.isGatewaySupervisor()) continue;
00299 if(it->second.isTypeLogbookSupervisor()) continue;
00300 if(it->second.isTypeMacroMakerSupervisor()) continue;
00301 if(it->second.isTypeConfigurationGUISupervisor()) continue;
00302 if(it->second.isTypeChatSupervisor()) continue;
00303 if(it->second.isTypeConsoleSupervisor()) continue;
00304
00305 retVec.push_back(&(it->second));
00306 __COUT__ << it->second.getName() << " [LID=" << it->second.getId() << "]: " << " priority " <<
00307 (unsigned int)priorityAppVector.first << __E__;
00308 }
00309 return retVec;
00310 }
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320