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