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(__ENV__("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 =
307 theConfigurationManager_
308 ->getNode(ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME +
"/" +
309 CorePropertySupervisorBase::getSupervisorUID() +
"/" +
310 "LinkToSupervisorTable")
314 for(
unsigned int i = 0; i < uid.size(); ++i)
315 if((uid[i] >=
'a' && uid[i] <=
'z') || (uid[i] >=
'A' && uid[i] <=
'Z') ||
316 (uid[i] >=
'0' && uid[i] <=
'9'))
320 __SUP_COUTV__(filename);
322 std::string fileFclString;
324 std::ifstream in(filename, std::ios::in | std::ios::binary);
327 std::string contents;
328 in.seekg(0, std::ios::end);
329 fileFclString.resize(in.tellg());
330 in.seekg(0, std::ios::beg);
331 in.read(&fileFclString[0], fileFclString.size());
336 __SUP_SS__ <<
"Fhicl file not found! " << filename << __E__;
341 __SUP_COUTV__(fileFclString);
345 fhicl::make_ParameterSet(fileFclString, pset);
346 theDispatcherInterface_->initialize(pset, 0, 0);
348 catch(
const cet::coded_exception<fhicl::error, &fhicl::detail::translate>& e)
350 __SUP_SS__ <<
"Error was caught while configuring: " << e.what() << __E__;
351 __SUP_COUT_ERR__ <<
"\n" << ss.str();
352 theStateMachine_.setErrorMessage(ss.str());
353 throw toolbox::fsm::exception::Exception(
356 "DispatcherApp::transitionConfiguring" ,
362 __SUP_COUT__ <<
"Configured." << __E__;
366 void DispatcherApp::transitionHalting(toolbox::Event::Reference e)
368 __SUP_COUT__ <<
"Halting..." << __E__;
371 theDispatcherInterface_->stop(45, 0);
376 __SUP_COUT__ <<
"Ignoring error on halt." << __E__;
381 theDispatcherInterface_->shutdown(45);
385 __SUP_COUT_ERR__ <<
"Error occurred during shutdown! State="
386 << theDispatcherInterface_->status();
391 __SUP_COUT__ <<
"Halted." << __E__;
395 void DispatcherApp::transitionInitializing(toolbox::Event::Reference e)
397 __SUP_COUT__ <<
"Initializing..." << __E__;
399 __SUP_COUT__ <<
"Initialized." << __E__;
403 void DispatcherApp::transitionPausing(toolbox::Event::Reference e)
405 __SUP_COUT__ <<
"Pausing..." << __E__;
406 theDispatcherInterface_->pause(0, 0);
407 __SUP_COUT__ <<
"Paused." << __E__;
411 void DispatcherApp::transitionResuming(toolbox::Event::Reference e)
413 __SUP_COUT__ <<
"Resuming..." << __E__;
414 theDispatcherInterface_->resume(0, 0);
415 __SUP_COUT__ <<
"Resumed." << __E__;
419 void DispatcherApp::transitionStarting(toolbox::Event::Reference e)
421 __SUP_COUT__ <<
"Starting..." << __E__;
423 auto runNumber = SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
425 .getValue(
"RunNumber");
429 (art::RunNumber_t)boost::lexical_cast<art::RunNumber_t>(runNumber));
430 theDispatcherInterface_->start(runId, 0, 0);
432 catch(
const boost::exception& e)
434 __SUP_SS__ <<
"Error parsing string to art::RunNumber_t: " << runNumber << __E__;
437 __SUP_COUT__ <<
"Started." << __E__;
441 void DispatcherApp::transitionStopping(toolbox::Event::Reference e)
443 __SUP_COUT__ <<
"Stopping..." << __E__;
444 theDispatcherInterface_->stop(45, 0);
445 __SUP_COUT__ <<
"Stopped." << __E__;