$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "otsdaq-core/SupervisorInfo/AllSupervisorInfo.h" 00002 00003 #include "otsdaq-core/Macros/CoutMacros.h" 00004 #include "otsdaq-core/MessageFacility/MessageFacility.h" 00005 00006 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h" 00007 #include "otsdaq-core/TablePluginDataFormats/XDAQContextTable.h" 00008 00009 #include <iostream> 00010 00011 using namespace ots; 00012 00013 //======================================================================================================================== 00014 AllSupervisorInfo::AllSupervisorInfo(void) : theSupervisorInfo_(0), theWizardInfo_(0) {} 00015 00016 //======================================================================================================================== 00017 AllSupervisorInfo::AllSupervisorInfo(xdaq::ApplicationContext* applicationContext) 00018 : AllSupervisorInfo() 00019 { 00020 init(applicationContext); 00021 } 00022 00023 //======================================================================================================================== 00024 AllSupervisorInfo::~AllSupervisorInfo(void) { destroy(); } 00025 00026 //======================================================================================================================== 00027 void AllSupervisorInfo::destroy(void) 00028 { 00029 allSupervisorInfo_.clear(); 00030 allFETypeSupervisorInfo_.clear(); 00031 allDMTypeSupervisorInfo_.clear(); 00032 00033 theSupervisorInfo_ = 0; 00034 theWizardInfo_ = 0; 00035 00036 SupervisorDescriptorInfoBase::destroy(); 00037 } 00038 00039 //======================================================================================================================== 00040 void AllSupervisorInfo::init(xdaq::ApplicationContext* applicationContext) 00041 { 00042 __COUT__ << "Initializing info based on XDAQ context..." << __E__; 00043 00044 AllSupervisorInfo::destroy(); 00045 SupervisorDescriptorInfoBase::init(applicationContext); 00046 00047 auto allDescriptors = SupervisorDescriptorInfoBase::getAllDescriptors(); 00048 // ready.. loop through all descriptors, and organize 00049 00050 // for(const auto& descriptor:allDescriptors) 00051 // { 00052 // SupervisorInfo tempSupervisorInfo( 00053 // descriptor.second /* descriptor */, 00054 // "" /* config app name */,"" /* config parent context name */ 00056 // ); 00057 // 00058 // __COUT__ << "id " << descriptor.second->getLocalId() << " url " << 00059 // descriptor.second->getContextDescriptor()->getURL() << __E__; 00060 // 00061 // } 00062 // __COUTV__(XDAQContextTable::GATEWAY_SUPERVISOR_CLASS); 00063 00064 // Steps: 00065 // 1. first pass, identify Wiz mode or not 00066 // 2. second pass, organize supervisors 00067 00068 bool isWizardMode = false; 00069 00070 // first pass, identify Wiz mode or not 00071 // accept first encountered (wizard or gateway) as the mode 00072 for(const auto& descriptor : allDescriptors) 00073 { 00074 SupervisorInfo tempSupervisorInfo( 00075 descriptor.second /* descriptor */, 00076 "" /* config app name */, 00077 "" /* config parent context name */ // skip configuration info 00078 ); 00079 00080 // check for gateway supervisor 00081 if(tempSupervisorInfo.isGatewaySupervisor()) 00082 { 00083 // found normal mode, done with first pass 00084 isWizardMode = false; 00085 break; 00086 } 00087 else if(tempSupervisorInfo.isWizardSupervisor()) 00088 { 00089 // found wiz mode, done with first pass 00090 isWizardMode = true; 00091 break; 00092 } 00093 } 00094 00095 if(isWizardMode) 00096 __COUT__ << "Initializing info for Wiz mode XDAQ context..." << __E__; 00097 else 00098 __COUT__ << "Initializing info for Normal mode XDAQ context..." << __E__; 00099 std::unique_ptr<ConfigurationManager> cfgMgr( 00100 isWizardMode ? 0 : new ConfigurationManager()); 00101 const XDAQContextTable* contextConfig = 00102 isWizardMode ? 0 : cfgMgr->__GET_CONFIG__(XDAQContextTable); 00103 00104 // do not involve the Configuration Manager 00105 // as it adds no valid information to the supervisors 00106 // present in wiz mode 00107 for(const auto& descriptor : allDescriptors) 00108 { 00109 auto /*<iterator,bool>*/ emplacePair = 00110 allSupervisorInfo_.emplace(std::pair<unsigned int, SupervisorInfo>( 00111 descriptor.second->getLocalId(), // descriptor.first, 00112 SupervisorInfo( 00113 descriptor.second /* descriptor */, 00114 contextConfig 00115 ? contextConfig->getApplicationUID( 00116 descriptor.second->getContextDescriptor()->getURL(), 00117 descriptor.second->getLocalId()) 00118 : "" /* config app name */, 00119 contextConfig 00120 ? contextConfig->getContextUID( 00121 descriptor.second->getContextDescriptor()->getURL()) 00122 : "" /* config parent context name */ 00123 ))); 00124 if(!emplacePair.second) 00125 { 00126 __SS__ << "Error! Duplicate Application IDs are not allowed. ID =" 00127 << descriptor.second->getLocalId() << __E__; 00128 __SS_THROW__; 00129 } 00130 00132 // now organize new descriptor by class... 00133 00134 // check for gateway supervisor 00135 // note: necessarily exclusive to other Supervisor types 00136 if(emplacePair.first->second.isGatewaySupervisor()) 00137 { 00138 if(theSupervisorInfo_) 00139 { 00140 __SS__ << "Error! Multiple Gateway Supervisors of class " 00141 << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS 00142 << " found. There can only be one. ID =" 00143 << descriptor.second->getLocalId() << __E__; 00144 __SS_THROW__; 00145 } 00146 // copy and erase from map 00147 theSupervisorInfo_ = &(emplacePair.first->second); 00148 continue; 00149 } 00150 00151 // check for wizard supervisor 00152 // note: necessarily exclusive to other Supervisor types 00153 if(emplacePair.first->second.isWizardSupervisor()) 00154 { 00155 if(theWizardInfo_) 00156 { 00157 __SS__ << "Error! Multiple Wizard Supervisors of class " 00158 << XDAQContextTable::WIZARD_SUPERVISOR_CLASS 00159 << " found. There can only be one. ID =" 00160 << descriptor.second->getLocalId() << __E__; 00161 __SS_THROW__; 00162 } 00163 // copy and erase from map 00164 theWizardInfo_ = &(emplacePair.first->second); 00165 continue; 00166 } 00167 00168 // check for FE type, then add to FE group 00169 // note: not necessarily exclusive to other Supervisor types 00170 if(emplacePair.first->second.isTypeFESupervisor()) 00171 { 00172 allFETypeSupervisorInfo_.emplace( 00173 std::pair<unsigned int, const SupervisorInfo&>( 00174 emplacePair.first->second.getId(), emplacePair.first->second)); 00175 } 00176 00177 // check for DM type, then add to DM group 00178 // note: not necessarily exclusive to other Supervisor types 00179 if(emplacePair.first->second.isTypeDMSupervisor()) 00180 { 00181 allDMTypeSupervisorInfo_.emplace( 00182 std::pair<unsigned int, const SupervisorInfo&>( 00183 emplacePair.first->second.getId(), emplacePair.first->second)); 00184 } 00185 00186 // check for Logbook type, then add to Logbook group 00187 // note: not necessarily exclusive to other Supervisor types 00188 if(emplacePair.first->second.isTypeLogbookSupervisor()) 00189 { 00190 allLogbookTypeSupervisorInfo_.emplace( 00191 std::pair<unsigned int, const SupervisorInfo&>( 00192 emplacePair.first->second.getId(), emplacePair.first->second)); 00193 } 00194 00195 // check for MacroMaker type, then add to MacroMaker group 00196 // note: not necessarily exclusive to other Supervisor types 00197 if(emplacePair.first->second.isTypeMacroMakerSupervisor()) 00198 { 00199 allMacroMakerTypeSupervisorInfo_.emplace( 00200 std::pair<unsigned int, const SupervisorInfo&>( 00201 emplacePair.first->second.getId(), emplacePair.first->second)); 00202 } 00203 00204 } // end main extraction loop 00205 00206 //} //end wiz mode extraction 00207 // else 00208 // { 00209 // __COUT__ << "Initializing info for Normal mode XDAQ context..." << __E__; 00210 // 00211 // 00212 // ConfigurationManager cfgMgr; 00213 // const XDAQContextTable* contextConfig = 00214 // cfgMgr.__GET_CONFIG__(XDAQContextTable); 00215 // 00216 // 00217 // //second pass, organize supervisors 00218 // auto allDescriptors = SupervisorDescriptorInfoBase::getAllDescriptors(); 00219 // for(const auto& descriptor:allDescriptors) 00220 // { 00221 // auto /*<iterator,bool>*/ emplacePair = 00222 // allSupervisorInfo_.emplace(std::pair<unsigned int, SupervisorInfo>( 00223 // descriptor.second->getLocalId(),//descriptor.first, 00224 // SupervisorInfo( 00225 // descriptor.second /* descriptor */, 00226 // contextConfig->getApplicationUID 00227 // ( 00228 // descriptor.second->getContextDescriptor()->getURL(), 00229 // descriptor.second->getLocalId() 00230 // ) /* name */, 00231 // contextConfig->getContextUID( 00232 // descriptor.second->getContextDescriptor()->getURL()) 00234 // ))); 00235 // if(!emplacePair.second) 00236 // { 00237 // __SS__ << "Error! Duplicate Application IDs are not allowed. ID =" << 00238 // descriptor.second->getLocalId() << __E__; 00239 // __SS_THROW__; 00240 // } 00241 // 00242 // ///////////////////////////////////////////// 00243 // // now organize new descriptor by class... 00244 // 00245 // //check for gateway supervisor 00246 // // note: necessarily exclusive to other Supervisor types 00247 // if(emplacePair.first->second.isGatewaySupervisor()) 00248 // { 00249 // if(theSupervisorInfo_) 00250 // { 00251 // __SS__ << "Error! Multiple Gateway Supervisors of class " << 00252 // XDAQContextTable::GATEWAY_SUPERVISOR_CLASS << " 00253 // found. There can only be one. ID =" << 00254 // descriptor.second->getLocalId() << __E__; 00255 // __SS_THROW__; 00256 // } 00257 // //copy and erase from map 00258 // theSupervisorInfo_ = &(emplacePair.first->second); 00259 // continue; 00260 // } 00261 // 00262 // //check for wizard supervisor 00263 // // note: necessarily exclusive to other Supervisor types 00264 // if(emplacePair.first->second.isWizardSupervisor()) 00265 // { 00266 // if(theWizardInfo_) 00267 // { 00268 // __SS__ << "Error! Multiple Wizard Supervisors of class " << 00269 // XDAQContextTable::WIZARD_SUPERVISOR_CLASS << 00270 // " found. There can only be one. ID =" << 00271 // descriptor.second->getLocalId() << __E__; 00272 // __SS_THROW__; 00273 // } 00274 // //copy and erase from map 00275 // theWizardInfo_ = &(emplacePair.first->second); 00276 // continue; 00277 // } 00278 // 00279 // 00280 // //check for FE type, then add to FE group 00281 // // note: not necessarily exclusive to other Supervisor types 00282 // if(emplacePair.first->second.isTypeFESupervisor()) 00283 // { 00284 // allFETypeSupervisorInfo_.emplace(std::pair<unsigned int, const 00285 // SupervisorInfo&>( emplacePair.first->second.getId(), 00286 // emplacePair.first->second)); 00287 // } 00288 // 00289 // //check for DM type, then add to DM group 00290 // // note: not necessarily exclusive to other Supervisor types 00291 // if(emplacePair.first->second.isTypeDMSupervisor()) 00292 // { 00293 // allDMTypeSupervisorInfo_.emplace(std::pair<unsigned int, const 00294 // SupervisorInfo&>( emplacePair.first->second.getId(), 00295 // emplacePair.first->second)); 00296 // } 00297 // 00298 // //check for Logbook type, then add to Logbook group 00299 // // note: not necessarily exclusive to other Supervisor types 00300 // if(emplacePair.first->second.isTypeLogbookSupervisor()) 00301 // { 00302 // allLogbookTypeSupervisorInfo_.emplace(std::pair<unsigned int, const 00303 // SupervisorInfo&>( emplacePair.first->second.getId(), 00304 // emplacePair.first->second)); 00305 // } 00306 // 00307 // //check for MacroMaker type, then add to MacroMaker group 00308 // // note: not necessarily exclusive to other Supervisor types 00309 // if(emplacePair.first->second.isTypeMacroMakerSupervisor()) 00310 // { 00311 // allMacroMakerTypeSupervisorInfo_.emplace(std::pair<unsigned int, const 00312 // SupervisorInfo&>( emplacePair.first->second.getId(), 00313 // emplacePair.first->second)); 00314 // } 00315 // 00316 // } //end main extraction loop 00317 // } //end normal mode extraction 00318 00319 if((!theWizardInfo_ && !theSupervisorInfo_) || (theWizardInfo_ && theSupervisorInfo_)) 00320 { 00321 __SS__ << "Error! Must have one " << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS 00322 << " OR one " << XDAQContextTable::WIZARD_SUPERVISOR_CLASS 00323 << " as part of the context configuration! " 00324 << "Neither were found." << __E__; 00325 __SS_THROW__; 00326 } 00327 00328 SupervisorDescriptorInfoBase::destroy(); 00329 00330 __COUT__ << "Init complete" << __E__; 00331 00332 // for debugging 00333 // getOrderedSupervisorDescriptors("Configure"); 00334 } 00335 00336 //======================================================================================================================== 00337 const SupervisorInfo& AllSupervisorInfo::getSupervisorInfo(xdaq::Application* app) const 00338 { 00339 auto it = allSupervisorInfo_.find(app->getApplicationDescriptor()->getLocalId()); 00340 if(it == allSupervisorInfo_.end()) 00341 { 00342 __SS__ << "Could not find: " << app->getApplicationDescriptor()->getLocalId() 00343 << std::endl; 00344 __SS_THROW__; 00345 } 00346 return it->second; 00347 } 00348 00349 //======================================================================================================================== 00350 void AllSupervisorInfo::setSupervisorStatus(xdaq::Application* app, 00351 const std::string& status) 00352 { 00353 setSupervisorStatus(app->getApplicationDescriptor()->getLocalId(), status); 00354 } 00355 //======================================================================================================================== 00356 void AllSupervisorInfo::setSupervisorStatus(const SupervisorInfo& appInfo, 00357 const std::string& status) 00358 { 00359 setSupervisorStatus(appInfo.getId(), status); 00360 } 00361 //======================================================================================================================== 00362 void AllSupervisorInfo::setSupervisorStatus(const unsigned int& id, 00363 const std::string& status) 00364 { 00365 auto it = allSupervisorInfo_.find(id); 00366 if(it == allSupervisorInfo_.end()) 00367 { 00368 __SS__ << "Could not find: " << id << std::endl; 00369 __SS_THROW__; 00370 } 00371 it->second.setStatus(status); 00372 } 00373 00374 //======================================================================================================================== 00375 const SupervisorInfo& AllSupervisorInfo::getGatewayInfo(void) const 00376 { 00377 if(!theSupervisorInfo_) 00378 { 00379 __SS__ << "AllSupervisorInfo was not initialized or no Application of type " 00380 << XDAQContextTable::GATEWAY_SUPERVISOR_CLASS << " found!" << __E__; 00381 __SS_THROW__; 00382 } 00383 return *theSupervisorInfo_; 00384 } 00385 //======================================================================================================================== 00386 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getGatewayDescriptor( 00387 void) const 00388 { 00389 return getGatewayInfo().getDescriptor(); 00390 } 00391 00392 //======================================================================================================================== 00393 const SupervisorInfo& AllSupervisorInfo::getWizardInfo(void) const 00394 { 00395 if(!theWizardInfo_) 00396 { 00397 __SS__ << "AllSupervisorInfo was not initialized or no Application of type " 00398 << XDAQContextTable::WIZARD_SUPERVISOR_CLASS << " found!" << __E__; 00399 __SS_THROW__; 00400 } 00401 return *theWizardInfo_; 00402 } 00403 //======================================================================================================================== 00404 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* AllSupervisorInfo::getWizardDescriptor( 00405 void) const 00406 { 00407 return getWizardInfo().getDescriptor(); 00408 } 00409 00410 //======================================================================================================================== 00411 std::vector<std::vector<const SupervisorInfo*>> 00412 AllSupervisorInfo::getOrderedSupervisorDescriptors( 00413 const std::string& stateMachineCommand) const 00414 { 00415 __COUT__ << "getOrderedSupervisorDescriptors" << __E__; 00416 00417 std::map<uint64_t /*priority*/, std::vector<unsigned int /*appId*/>> 00418 orderedByPriority; 00419 00420 try 00421 { 00422 ConfigurationManager cfgMgr; 00423 const std::vector<XDAQContextTable::XDAQContext>& contexts = 00424 cfgMgr.__GET_CONFIG__(XDAQContextTable)->getContexts(); 00425 00426 for(const auto& context : contexts) 00427 if(context.status_) 00428 for(const auto& app : context.applications_) 00429 { 00430 if(!app.status_) 00431 continue; // skip disabled apps 00432 00433 auto it = app.stateMachineCommandPriority_.find(stateMachineCommand); 00434 if(it == app.stateMachineCommandPriority_.end()) 00435 orderedByPriority[XDAQContextTable::XDAQApplication:: 00436 DEFAULT_PRIORITY] 00437 .push_back( 00438 app.id_); // if no priority, then default to 00439 // XDAQContextTable::XDAQApplication::DEFAULT_PRIORITY 00440 else // take value, and do not allow DEFAULT value of 0 -> force to 00441 // XDAQContextTable::XDAQApplication::DEFAULT_PRIORITY 00442 orderedByPriority[it->second ? it->second 00443 : XDAQContextTable::XDAQApplication:: 00444 DEFAULT_PRIORITY] 00445 .push_back(app.id_); 00446 00447 //__COUT__ << "app.id_ " << app.id_ << __E__; 00448 } 00449 } 00450 catch(...) 00451 { 00452 __COUT_ERR__ << "SupervisorDescriptorInfoBase could not access the XDAQ Context " 00453 "and Application configuration through the Context Table " 00454 "Group." 00455 << __E__; 00456 throw; 00457 } 00458 00459 __COUT__ << "Here is the order supervisors will be " << stateMachineCommand 00460 << "'d:" << __E__; 00461 00462 // return ordered set of supervisor infos 00463 // skip over Gateway Supervisor, 00464 // and other supervisors that do not need state transitions. 00465 std::vector<std::vector<const SupervisorInfo*>> retVec; 00466 bool createContainer; 00467 for(const auto& priorityAppVector : orderedByPriority) 00468 { 00469 createContainer = true; 00470 00471 for(const auto& priorityApp : priorityAppVector.second) 00472 { 00473 auto it = allSupervisorInfo_.find(priorityApp); 00474 if(it == allSupervisorInfo_.end()) 00475 { 00476 __SS__ 00477 << "Error! Was AllSupervisorInfo properly initialized? The app.id_ " 00478 << priorityApp << " priority " 00479 << (unsigned int)priorityAppVector.first 00480 << " could not be found in AllSupervisorInfo." << __E__; 00481 __SS_THROW__; 00482 } 00483 00484 //__COUT__ << it->second.getName() << " [" << it->second.getId() << "]: " << " 00485 // priority? " << (unsigned int)priorityAppVector.first << 00486 //__E__; 00487 00488 if(it->second.isGatewaySupervisor()) 00489 continue; // skip gateway supervisor 00490 if(it->second.isTypeLogbookSupervisor()) 00491 continue; // skip logbook supervisor(s) 00492 if(it->second.isTypeMacroMakerSupervisor()) 00493 continue; // skip macromaker supervisor(s) 00494 if(it->second.isTypeConfigurationGUISupervisor()) 00495 continue; // skip configurationGUI supervisor(s) 00496 if(it->second.isTypeChatSupervisor()) 00497 continue; // skip chat supervisor(s) 00498 if(it->second.isTypeConsoleSupervisor()) 00499 continue; // skip console supervisor(s) 00500 00501 if(createContainer) // create container first time 00502 { 00503 retVec.push_back(std::vector<const SupervisorInfo*>()); 00504 00505 // if default priority, create a new vector container for each entry 00506 // so they happen in sequence by default 00507 // if(priorityAppVector.first != 00508 // XDAQContextTable::XDAQApplication::DEFAULT_PRIORITY) 00509 // createContainer = false; 00510 00511 createContainer = false; 00512 } 00513 retVec[retVec.size() - 1].push_back(&(it->second)); 00514 00515 __COUT__ << it->second.getName() << " [LID=" << it->second.getId() << "]: " 00516 << " priority " << (unsigned int)priorityAppVector.first << " count " 00517 << retVec[retVec.size() - 1].size() << __E__; 00518 } 00519 } // end equal priority loop 00520 return retVec; 00521 }