1 #include "otsdaq/DispatcherApp/DispatcherApp.h"
17 #include "artdaq-core/Utilities/configureMessageFacility.hh"
18 #include "artdaq/BuildInfo/GetPackageBuildInfo.hh"
19 #include "artdaq/DAQdata/Globals.hh"
20 #include "cetlib_except/exception.h"
21 #include "fhiclcpp/make_ParameterSet.h"
33 #define ARTDAQ_FCL_PATH std::string(getenv("USER_DATA")) + "/" + "ARTDAQConfigurations/"
34 #define ARTDAQ_FILE_PREAMBLE "aggregator"
57 __SUP_COUT__ <<
"Constructor." << __E__;
59 INIT_MF(
"DispatcherApp");
113 __SUP_COUT__ <<
"Constructed." << __E__;
117 DispatcherApp::~DispatcherApp(
void)
119 __SUP_COUT__ <<
"Destructor." << __E__;
121 __SUP_COUT__ <<
"Destructed." << __E__;
125 void DispatcherApp::init(
void)
127 __SUP_COUT__ <<
"Initializing..." << __E__;
131 artdaq::configureMessageFacility(
"Dispatcher");
132 __SUP_COUT__ <<
"artdaq MF configured." << __E__;
136 std::string name =
"Dispatcher";
137 unsigned short port = 5300;
139 artdaq::setMsgFacAppName(name, port);
141 TLOG(TLVL_DEBUG, name +
"Supervisor")
143 << artdaq::GetPackageBuildInfo::getPackageBuildInfo().getPackageVersion()
145 << artdaq::GetPackageBuildInfo::getPackageBuildInfo().getBuildTimestamp();
149 my_rank = this->getApplicationDescriptor()->getLocalId();
150 theDispatcherInterface_.reset(
new artdaq::DispatcherApp());
154 __SUP_COUT__ <<
"Initialized." << __E__;
158 void DispatcherApp::destroy(
void)
160 __SUP_COUT__ <<
"Destroying..." << __E__;
161 theDispatcherInterface_.reset(
nullptr);
162 __SUP_COUT__ <<
"Destroyed." << __E__;
282 void DispatcherApp::transitionConfiguring(toolbox::Event::Reference e)
284 __SUP_COUT__ <<
"Configuring..." << __E__;
286 __SUP_COUT__ << SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
290 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
292 .getValue(
"ConfigurationTableGroupName"),
293 TableGroupKey(SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
295 .getValue(
"ConfigurationTableGroupKey")));
297 __SUP_COUT__ <<
"Configuration group name: " << theGroup.first
298 <<
" key: " << theGroup.second << __E__;
300 theConfigurationManager_->loadTableGroup(theGroup.first, theGroup.second,
true);
303 fhicl::ParameterSet pset;
305 std::string filename = ARTDAQ_FCL_PATH + ARTDAQ_FILE_PREAMBLE +
"-";
306 const std::string& uid = CorePropertySupervisorBase::getSupervisorUID();
309 for(
unsigned int i = 0; i < uid.size(); ++i)
310 if((uid[i] >=
'a' && uid[i] <=
'z') || (uid[i] >=
'A' && uid[i] <=
'Z') ||
311 (uid[i] >=
'0' && uid[i] <=
'9'))
315 __SUP_COUTV__(filename);
317 std::string fileFclString;
319 std::ifstream in(filename, std::ios::in | std::ios::binary);
322 std::string contents;
323 in.seekg(0, std::ios::end);
324 fileFclString.resize(in.tellg());
325 in.seekg(0, std::ios::beg);
326 in.read(&fileFclString[0], fileFclString.size());
331 __SUP_COUTV__(fileFclString);
335 fhicl::make_ParameterSet(fileFclString, pset);
336 theDispatcherInterface_->initialize(pset, 0, 0);
338 catch(
const cet::coded_exception<fhicl::error, &fhicl::detail::translate>& e)
340 __SUP_SS__ <<
"Error was caught while configuring: " << e.what() << __E__;
341 __SUP_COUT_ERR__ <<
"\n" << ss.str();
342 theStateMachine_.setErrorMessage(ss.str());
343 throw toolbox::fsm::exception::Exception(
346 "DispatcherApp::transitionConfiguring" ,
352 __SUP_COUT__ <<
"Configured." << __E__;
356 void DispatcherApp::transitionHalting(toolbox::Event::Reference e)
358 __SUP_COUT__ <<
"Halting..." << __E__;
361 theDispatcherInterface_->stop(45, 0);
366 __SUP_COUT__ <<
"Ignoring error on halt." << __E__;
371 theDispatcherInterface_->shutdown(45);
375 __SUP_COUT_ERR__ <<
"Error occurred during shutdown! State="
376 << theDispatcherInterface_->status();
381 __SUP_COUT__ <<
"Halted." << __E__;
385 void DispatcherApp::transitionInitializing(toolbox::Event::Reference e)
387 __SUP_COUT__ <<
"Initializing..." << __E__;
389 __SUP_COUT__ <<
"Initialized." << __E__;
393 void DispatcherApp::transitionPausing(toolbox::Event::Reference e)
395 __SUP_COUT__ <<
"Pausing..." << __E__;
396 theDispatcherInterface_->pause(0, 0);
397 __SUP_COUT__ <<
"Paused." << __E__;
401 void DispatcherApp::transitionResuming(toolbox::Event::Reference e)
403 __SUP_COUT__ <<
"Resuming..." << __E__;
404 theDispatcherInterface_->resume(0, 0);
405 __SUP_COUT__ <<
"Resumed." << __E__;
409 void DispatcherApp::transitionStarting(toolbox::Event::Reference e)
411 __SUP_COUT__ <<
"Starting..." << __E__;
413 auto runNumber = SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
415 .getValue(
"RunNumber");
419 (art::RunNumber_t)boost::lexical_cast<art::RunNumber_t>(runNumber));
420 theDispatcherInterface_->start(runId, 0, 0);
422 catch(
const boost::exception& e)
424 __SUP_SS__ <<
"Error parsing string to art::RunNumber_t: " << runNumber << __E__;
427 __SUP_COUT__ <<
"Started." << __E__;
431 void DispatcherApp::transitionStopping(toolbox::Event::Reference e)
433 __SUP_COUT__ <<
"Stopping..." << __E__;
434 theDispatcherInterface_->stop(45, 0);
435 __SUP_COUT__ <<
"Stopped." << __E__;