$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "otsdaq/DispatcherApp/DispatcherApp.h" 00002 //#include "otsdaq-core/Macros/CoutMacros.h" 00003 //#include "otsdaq-core/MessageFacility/MessageFacility.h" 00004 //#include "otsdaq-core/SOAPUtilities/SOAPCommand.h" 00005 //#include "otsdaq-core/SOAPUtilities/SOAPUtilities.h" 00006 //#include "otsdaq-core/XmlUtilities/HttpXmlDocument.h" 00007 // 00008 //#include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h" 00009 //#include "otsdaq-core/TablePluginDataFormats/XDAQContextTable.h" 00010 // 00011 //#include <toolbox/fsm/FailedEvent.h> 00012 // 00013 //#include <xdaq/NamespaceURI.h> 00014 //#include <xoap/Method.h> 00015 00016 //#include <memory> 00017 #include "artdaq-core/Utilities/configureMessageFacility.hh" 00018 #include "artdaq/BuildInfo/GetPackageBuildInfo.hh" 00019 #include "artdaq/DAQdata/Globals.hh" 00020 #include "cetlib_except/exception.h" 00021 #include "fhiclcpp/make_ParameterSet.h" 00022 //#include "messagefacility/MessageLogger/MessageLogger.h" 00023 00024 //#include <cassert> 00025 //#include <fstream> 00026 //#include <iostream> 00027 //#include "otsdaq-core/TableCore/TableGroupKey.h" 00028 00029 using namespace ots; 00030 00031 XDAQ_INSTANTIATOR_IMPL(DispatcherApp) 00032 00033 #define ARTDAQ_FCL_PATH std::string(getenv("USER_DATA")) + "/" + "ARTDAQConfigurations/" 00034 #define ARTDAQ_FILE_PREAMBLE "aggregator" 00035 00036 //======================================================================================================================== 00037 DispatcherApp::DispatcherApp(xdaq::ApplicationStub* s) : CoreSupervisorBase(s) 00038 // : xdaq::Application(s) 00039 // , SOAPMessenger(this) 00040 // , stateMachineWorkLoopManager_( 00041 // toolbox::task::bind(this, &DispatcherApp::stateMachineThread, "StateMachine")) 00042 // , stateMachineSemaphore_(toolbox::BSem::FULL) 00043 // , theConfigurationManager_( 00044 // new ConfigurationManager) //(Singleton<ConfigurationManager>::getInstance()) 00045 // ////I always load the full config but if I want to 00046 // // load a partial configuration (new 00047 // // ConfigurationManager) 00048 // , XDAQContextTableName_( 00049 // theConfigurationManager_->__GET_CONFIG__(XDAQContextTable)->getTableName()) 00050 // , supervisorConfigurationPath_( 00051 // "INITIALIZED INSIDE THE CONTRUCTOR BECAUSE IT NEEDS supervisorContextUID_ and 00052 // " "supervisorApplicationUID_") 00053 // , supervisorContextUID_("INITIALIZED INSIDE THE CONTRUCTOR TO LAUNCH AN EXCEPTION") 00054 // , supervisorApplicationUID_( 00055 // "INITIALIZED INSIDE THE CONTRUCTOR TO LAUNCH AN EXCEPTION") 00056 { 00057 __SUP_COUT__ << "Constructor." << __E__; 00058 00059 INIT_MF("DispatcherApp"); 00060 00061 // xgi::bind(this, &DispatcherApp::Default, "Default"); 00062 // xgi::bind(this, &DispatcherApp::stateMachineXgiHandler, "StateMachineXgiHandler"); 00063 // 00064 // xoap::bind(this, 00065 // &DispatcherApp::stateMachineStateRequest, 00066 // "StateMachineStateRequest", 00067 // XDAQ_NS_URI); 00068 // xoap::bind(this, 00069 // &DispatcherApp::stateMachineErrorMessageRequest, 00070 // "StateMachineErrorMessageRequest", 00071 // XDAQ_NS_URI); 00072 // 00073 // try 00074 // { 00075 // supervisorContextUID_ = 00076 // theConfigurationManager_->__GET_CONFIG__(XDAQContextTable) 00077 // ->getContextUID( 00078 // getApplicationContext()->getContextDescriptor()->getURL()); 00079 // } 00080 // catch(...) 00081 // { 00082 // __COUT_ERR__ 00083 // << "XDAQ Supervisor could not access it's configuration through " 00084 // "the Configuration Manager." 00085 // << ". The getApplicationContext()->getContextDescriptor()->getURL() = " 00086 // << getApplicationContext()->getContextDescriptor()->getURL() << __E__; 00087 // throw; 00088 // } 00089 // try 00090 // { 00091 // supervisorApplicationUID_ = 00092 // theConfigurationManager_->__GET_CONFIG__(XDAQContextTable) 00093 // ->getApplicationUID( 00094 // getApplicationContext()->getContextDescriptor()->getURL(), 00095 // getApplicationDescriptor()->getLocalId()); 00096 // } 00097 // catch(...) 00098 // { 00099 // __COUT_ERR__ << "XDAQ Supervisor could not access it's configuration through " 00100 // "the Configuration Manager." 00101 // << " The supervisorContextUID_ = " << supervisorContextUID_ 00102 // << ". The supervisorApplicationUID = " << 00103 // supervisorApplicationUID_ 00104 // << __E__; 00105 // throw; 00106 // } 00107 // supervisorConfigurationPath_ = "/" + supervisorContextUID_ + 00108 // "/LinkToApplicationTable/" + 00109 // supervisorApplicationUID_ + 00110 //"/LinkToSupervisorTable"; 00111 // 00112 // setStateMachineName(supervisorApplicationUID_); 00113 __SUP_COUT__ << "Constructed." << __E__; 00114 } // end constructor() 00115 00116 //======================================================================================================================== 00117 DispatcherApp::~DispatcherApp(void) 00118 { 00119 __SUP_COUT__ << "Destructor." << __E__; 00120 destroy(); 00121 __SUP_COUT__ << "Destructed." << __E__; 00122 } // end destructor() 00123 00124 //======================================================================================================================== 00125 void DispatcherApp::init(void) 00126 { 00127 __SUP_COUT__ << "Initializing..." << __E__; 00128 00129 // allSupervisorInfo_.init(getApplicationContext()); 00130 00131 artdaq::configureMessageFacility("Dispatcher"); 00132 __SUP_COUT__ << "artdaq MF configured." << __E__; 00133 00134 // initialization 00135 00136 std::string name = "Dispatcher"; 00137 unsigned short port = 5300; 00138 // artdaq::setMsgFacAppName(supervisorApplicationUID_, port); 00139 artdaq::setMsgFacAppName(name, port); 00140 // mf::LogDebug(supervisorApplicationUID_) << "artdaq version " << 00141 TLOG(TLVL_DEBUG, name + "Supervisor") 00142 << "artdaq version " 00143 << artdaq::GetPackageBuildInfo::getPackageBuildInfo().getPackageVersion() 00144 << ", built " 00145 << artdaq::GetPackageBuildInfo::getPackageBuildInfo().getBuildTimestamp(); 00146 00147 // create the DispatcherInterface 00148 app_name = name; 00149 my_rank = this->getApplicationDescriptor()->getLocalId(); 00150 theDispatcherInterface_.reset(new artdaq::DispatcherApp()); 00151 // theDispatcherInterface_ = new DispatcherInterface(mpiSentry_->rank(), 00152 // local_group_comm, supervisorApplicationUID_ ); 00153 00154 __SUP_COUT__ << "Initialized." << __E__; 00155 } // end init() 00156 00157 //======================================================================================================================== 00158 void DispatcherApp::destroy(void) 00159 { 00160 __SUP_COUT__ << "Destroying..." << __E__; 00161 theDispatcherInterface_.reset(nullptr); 00162 __SUP_COUT__ << "Destroyed." << __E__; 00163 } // end destroy() 00164 // 00166 // void DispatcherApp::Default(xgi::Input* in, xgi::Output* out) 00167 //{ 00168 // *out << "<!DOCTYPE HTML><html lang='en'><frameset col='100%' row='100%'><frame " 00169 // "src='/WebPath/html/DispatcherApp.html?urn=" 00170 // << this->getApplicationDescriptor()->getLocalId() << "'></frameset></html>"; 00171 //} 00172 // 00174 // void DispatcherApp::stateMachineXgiHandler(xgi::Input* in, xgi::Output* out) {} 00175 // 00177 // void DispatcherApp::stateMachineResultXgiHandler(xgi::Input* in, xgi::Output* out) {} 00178 // 00180 // xoap::MessageReference DispatcherApp::stateMachineXoapHandler( 00181 // xoap::MessageReference message) 00182 //{ 00183 // std::cout << __COUT_HDR_FL__ << "Soap Handler!" << __E__; 00184 // stateMachineWorkLoopManager_.removeProcessedRequests(); 00185 // stateMachineWorkLoopManager_.processRequest(message); 00186 // std::cout << __COUT_HDR_FL__ << "Done - Soap Handler!" << __E__; 00187 // return message; 00188 //} 00189 // 00191 // xoap::MessageReference DispatcherApp::stateMachineResultXoapHandler( 00192 // xoap::MessageReference message) 00193 //{ 00194 // std::cout << __COUT_HDR_FL__ << "Soap Handler!" << __E__; 00195 // // stateMachineWorkLoopManager_.removeProcessedRequests(); 00196 // // stateMachineWorkLoopManager_.processRequest(message); 00197 // std::cout << __COUT_HDR_FL__ << "Done - Soap Handler!" << __E__; 00198 // return message; 00199 //} 00200 // 00202 // bool DispatcherApp::stateMachineThread(toolbox::task::WorkLoop* workLoop) 00203 //{ 00204 // stateMachineSemaphore_.take(); 00205 // std::cout << __COUT_HDR_FL__ << "Re-sending message..." 00206 // << SOAPUtilities::translate( 00207 // stateMachineWorkLoopManager_.getMessage(workLoop)) 00208 // .getCommand() 00209 // << __E__; 00210 // std::string reply = send(this->getApplicationDescriptor(), 00211 // stateMachineWorkLoopManager_.getMessage(workLoop)); 00212 // stateMachineWorkLoopManager_.report(workLoop, reply, 100, true); 00213 // std::cout << __COUT_HDR_FL__ << "Done with message" << __E__; 00214 // stateMachineSemaphore_.give(); 00215 // return false; // execute once and automatically remove the workloop so in 00216 // // WorkLoopManager the try workLoop->remove(job_) could be commented 00217 // // out return true;//go on and then you must do the 00218 // // workLoop->remove(job_) in WorkLoopManager 00219 //} 00220 // 00222 // xoap::MessageReference DispatcherApp::stateMachineStateRequest( 00223 // xoap::MessageReference message) 00224 //{ 00225 // std::cout << __COUT_HDR_FL__ << theStateMachine_.getCurrentStateName() << __E__; 00226 // return SOAPUtilities::makeSOAPMessageReference( 00227 // theStateMachine_.getCurrentStateName()); 00228 //} 00229 // 00231 // xoap::MessageReference DispatcherApp::stateMachineErrorMessageRequest( 00232 // xoap::MessageReference message) 00233 // 00234 //{ 00235 // __COUT__ << "theStateMachine_.getErrorMessage() = " 00236 // << theStateMachine_.getErrorMessage() << __E__; 00237 // 00238 // SOAPParameters retParameters; 00239 // retParameters.addParameter("ErrorMessage", theStateMachine_.getErrorMessage()); 00240 // return SOAPUtilities::makeSOAPMessageReference("stateMachineErrorMessageRequestReply", 00241 // retParameters); 00242 //} 00243 // 00245 // void DispatcherApp::stateInitial(toolbox::fsm::FiniteStateMachine& fsm) {} 00246 // 00248 // void DispatcherApp::stateHalted(toolbox::fsm::FiniteStateMachine& fsm) {} 00249 // 00251 // void DispatcherApp::stateRunning(toolbox::fsm::FiniteStateMachine& fsm) {} 00252 // 00254 // void DispatcherApp::stateConfigured(toolbox::fsm::FiniteStateMachine& fsm) {} 00255 // 00257 // void DispatcherApp::statePaused(toolbox::fsm::FiniteStateMachine& fsm) {} 00258 // 00260 // void DispatcherApp::inError(toolbox::fsm::FiniteStateMachine& fsm) 00261 //{ 00262 // std::cout << __COUT_HDR_FL__ 00263 // << "Fsm current state: " << theStateMachine_.getCurrentStateName() << __E__; 00264 // // rcmsStateNotifier_.stateChanged("Error", ""); 00265 //} 00266 // 00268 // void DispatcherApp::enteringError(toolbox::Event::Reference e) 00269 //{ 00270 // std::cout << __COUT_HDR_FL__ 00271 // << "Fsm current state: " << theStateMachine_.getCurrentStateName() << __E__; 00272 // toolbox::fsm::FailedEvent& failedEvent = dynamic_cast<toolbox::fsm::FailedEvent&>(*e); 00273 // std::ostringstream error; 00274 // error << "Failure performing transition from " << failedEvent.getFromState() << " to " 00275 // << failedEvent.getToState() 00276 // << " exception: " << failedEvent.getException().what(); 00277 // std::cout << __COUT_HDR_FL__ << error.str() << __E__; 00278 // // diagService_->reportError(errstr.str(),DIAGERROR); 00279 //} 00280 00281 //======================================================================================================================== 00282 void DispatcherApp::transitionConfiguring(toolbox::Event::Reference e) 00283 { 00284 __SUP_COUT__ << "Configuring..." << __E__; 00285 00286 __SUP_COUT__ << SOAPUtilities::translate(theStateMachine_.getCurrentMessage()) 00287 << __E__; 00288 00289 std::pair<std::string /*group name*/, TableGroupKey> theGroup( 00290 SOAPUtilities::translate(theStateMachine_.getCurrentMessage()) 00291 .getParameters() 00292 .getValue("ConfigurationTableGroupName"), 00293 TableGroupKey(SOAPUtilities::translate(theStateMachine_.getCurrentMessage()) 00294 .getParameters() 00295 .getValue("ConfigurationTableGroupKey"))); 00296 00297 __SUP_COUT__ << "Configuration group name: " << theGroup.first 00298 << " key: " << theGroup.second << __E__; 00299 00300 theConfigurationManager_->loadTableGroup(theGroup.first, theGroup.second, true); 00301 00302 // load fcl string from dedicated file 00303 fhicl::ParameterSet pset; 00304 00305 std::string filename = ARTDAQ_FCL_PATH + ARTDAQ_FILE_PREAMBLE + "-"; 00306 const std::string& uid = CorePropertySupervisorBase::getSupervisorUID(); 00307 00308 __SUP_COUTV__(uid); 00309 for(unsigned int i = 0; i < uid.size(); ++i) 00310 if((uid[i] >= 'a' && uid[i] <= 'z') || (uid[i] >= 'A' && uid[i] <= 'Z') || 00311 (uid[i] >= '0' && uid[i] <= '9')) // only allow alpha numeric in file name 00312 filename += uid[i]; 00313 filename += ".fcl"; 00314 00315 __SUP_COUTV__(filename); 00316 00317 std::string fileFclString; 00318 { 00319 std::ifstream in(filename, std::ios::in | std::ios::binary); 00320 if(in) 00321 { 00322 std::string contents; 00323 in.seekg(0, std::ios::end); 00324 fileFclString.resize(in.tellg()); 00325 in.seekg(0, std::ios::beg); 00326 in.read(&fileFclString[0], fileFclString.size()); 00327 in.close(); 00328 } 00329 } 00330 00331 __SUP_COUTV__(fileFclString); 00332 00333 try 00334 { 00335 fhicl::make_ParameterSet(fileFclString, pset); 00336 theDispatcherInterface_->initialize(pset, 0, 0); 00337 } 00338 catch(const cet::coded_exception<fhicl::error, &fhicl::detail::translate>& e) 00339 { 00340 __SUP_SS__ << "Error was caught while configuring: " << e.what() << __E__; 00341 __SUP_COUT_ERR__ << "\n" << ss.str(); 00342 theStateMachine_.setErrorMessage(ss.str()); 00343 throw toolbox::fsm::exception::Exception( 00344 "Transition Error" /*name*/, 00345 ss.str() /* message*/, 00346 "DispatcherApp::transitionConfiguring" /*module*/, 00347 __LINE__ /*line*/, 00348 __FUNCTION__ /*function*/ 00349 ); 00350 } 00351 00352 __SUP_COUT__ << "Configured." << __E__; 00353 } // end transitionConfiguring() 00354 00355 //======================================================================================================================== 00356 void DispatcherApp::transitionHalting(toolbox::Event::Reference e) 00357 { 00358 __SUP_COUT__ << "Halting..." << __E__; 00359 try 00360 { 00361 theDispatcherInterface_->stop(45, 0); 00362 } 00363 catch(...) 00364 { 00365 // It is okay for this to fail, esp. if already stopped... 00366 __SUP_COUT__ << "Ignoring error on halt." << __E__; 00367 } 00368 00369 try 00370 { 00371 theDispatcherInterface_->shutdown(45); 00372 } 00373 catch(...) 00374 { 00375 __SUP_COUT_ERR__ << "Error occurred during shutdown! State=" 00376 << theDispatcherInterface_->status(); 00377 } 00378 00379 init(); 00380 00381 __SUP_COUT__ << "Halted." << __E__; 00382 } // end transitionHalting() 00383 00384 //======================================================================================================================== 00385 void DispatcherApp::transitionInitializing(toolbox::Event::Reference e) 00386 { 00387 __SUP_COUT__ << "Initializing..." << __E__; 00388 init(); 00389 __SUP_COUT__ << "Initialized." << __E__; 00390 } // end transitionInitializing() 00391 00392 //======================================================================================================================== 00393 void DispatcherApp::transitionPausing(toolbox::Event::Reference e) 00394 { 00395 __SUP_COUT__ << "Pausing..." << __E__; 00396 theDispatcherInterface_->pause(0, 0); 00397 __SUP_COUT__ << "Paused." << __E__; 00398 } // end transitionPausing() 00399 00400 //======================================================================================================================== 00401 void DispatcherApp::transitionResuming(toolbox::Event::Reference e) 00402 { 00403 __SUP_COUT__ << "Resuming..." << __E__; 00404 theDispatcherInterface_->resume(0, 0); 00405 __SUP_COUT__ << "Resumed." << __E__; 00406 } // end transitionResuming() 00407 00408 //======================================================================================================================== 00409 void DispatcherApp::transitionStarting(toolbox::Event::Reference e) 00410 { 00411 __SUP_COUT__ << "Starting..." << __E__; 00412 00413 auto runNumber = SOAPUtilities::translate(theStateMachine_.getCurrentMessage()) 00414 .getParameters() 00415 .getValue("RunNumber"); 00416 try 00417 { 00418 art::RunID runId( 00419 (art::RunNumber_t)boost::lexical_cast<art::RunNumber_t>(runNumber)); 00420 theDispatcherInterface_->start(runId, 0, 0); 00421 } 00422 catch(const boost::exception& e) 00423 { 00424 __SUP_SS__ << "Error parsing string to art::RunNumber_t: " << runNumber << __E__; 00425 __SUP_SS_THROW__; 00426 } 00427 __SUP_COUT__ << "Started." << __E__; 00428 } // end transitionStarting() 00429 00430 //======================================================================================================================== 00431 void DispatcherApp::transitionStopping(toolbox::Event::Reference e) 00432 { 00433 __SUP_COUT__ << "Stopping..." << __E__; 00434 theDispatcherInterface_->stop(45, 0); 00435 __SUP_COUT__ << "Stopped." << __E__; 00436 } // end transitionStopping()