1 #include "otsdaq/EventBuilderApp/EventBuilderApp.h"
17 #include "artdaq-core/Utilities/configureMessageFacility.hh"
18 #include "artdaq/BuildInfo/GetPackageBuildInfo.hh"
19 #include "cetlib_except/exception.h"
20 #include "fhiclcpp/make_ParameterSet.h"
21 #include "messagefacility/MessageLogger/MessageLogger.h"
32 #define ARTDAQ_FCL_PATH std::string(getenv("USER_DATA")) + "/" + "ARTDAQConfigurations/"
33 #define ARTDAQ_FILE_PREAMBLE "builder"
36 EventBuilderApp::EventBuilderApp(xdaq::ApplicationStub* stub) :
CoreSupervisorBase(stub)
62 __SUP_COUT__ <<
"Constructor." << __E__;
64 INIT_MF(
"EventBuilderApp");
118 __SUP_COUT__ <<
"Constructed." << __E__;
122 EventBuilderApp::~EventBuilderApp(
void)
124 __SUP_COUT__ <<
"Destructor." << __E__;
126 __SUP_COUT__ <<
"Destructed." << __E__;
130 void EventBuilderApp::init(
void)
132 __SUP_COUT__ <<
"Initializing..." << __E__;
136 artdaq::configureMessageFacility(
"eventbuilder");
137 __SUP_COUT__ <<
"artdaq MF configured." << __E__;
141 std::string name =
"Builder";
142 unsigned short port = 5200;
144 artdaq::setMsgFacAppName(name, port);
146 TLOG(TLVL_DEBUG, name +
"Supervisor")
148 << artdaq::GetPackageBuildInfo::getPackageBuildInfo().getPackageVersion()
150 << artdaq::GetPackageBuildInfo::getPackageBuildInfo().getBuildTimestamp();
154 my_rank = this->getApplicationDescriptor()->getLocalId();
155 theARTDAQEventBuilderInterface_.reset(
new artdaq::EventBuilderApp());
157 __SUP_COUT__ <<
"Initialized." << __E__;
161 void EventBuilderApp::destroy(
void)
163 __SUP_COUT__ <<
"Destroying..." << __E__;
164 theARTDAQEventBuilderInterface_.reset(
nullptr);
165 __SUP_COUT__ <<
"Destroyed." << __E__;
293 void EventBuilderApp::transitionConfiguring(toolbox::Event::Reference e)
295 __SUP_COUT__ <<
"Configuring..." << __E__;
297 __SUP_COUT__ << SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
301 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
303 .getValue(
"ConfigurationTableGroupName"),
304 TableGroupKey(SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
306 .getValue(
"ConfigurationTableGroupKey")));
308 __SUP_COUT__ <<
"Configuration group name: " << theGroup.first
309 <<
" key: " << theGroup.second << __E__;
311 theConfigurationManager_->loadTableGroup(theGroup.first, theGroup.second,
true);
314 fhicl::ParameterSet pset;
316 std::string filename = ARTDAQ_FCL_PATH + ARTDAQ_FILE_PREAMBLE +
"-";
317 const std::string& uid = CorePropertySupervisorBase::getSupervisorUID();
320 for(
unsigned int i = 0; i < uid.size(); ++i)
321 if((uid[i] >=
'a' && uid[i] <=
'z') || (uid[i] >=
'A' && uid[i] <=
'Z') ||
322 (uid[i] >=
'0' && uid[i] <=
'9'))
326 __SUP_COUTV__(filename);
328 std::string fileFclString;
330 std::ifstream in(filename, std::ios::in | std::ios::binary);
333 std::string contents;
334 in.seekg(0, std::ios::end);
335 fileFclString.resize(in.tellg());
336 in.seekg(0, std::ios::beg);
337 in.read(&fileFclString[0], fileFclString.size());
342 __SUP_COUTV__(fileFclString);
346 fhicl::make_ParameterSet(fileFclString, pset);
347 theARTDAQEventBuilderInterface_->initialize(pset, 0, 0);
349 catch(
const cet::coded_exception<fhicl::error, &fhicl::detail::translate>& e)
351 __SUP_SS__ <<
"Error was caught while configuring: " << e.what() << __E__;
352 __SUP_COUT_ERR__ <<
"\n" << ss.str();
353 theStateMachine_.setErrorMessage(ss.str());
354 throw toolbox::fsm::exception::Exception(
357 "EventBuilderApp::transitionConfiguring" ,
363 __SUP_COUT__ <<
"Configured." << __E__;
367 void EventBuilderApp::transitionHalting(toolbox::Event::Reference e)
369 __SUP_COUT__ <<
"Halting..." << __E__;
372 theARTDAQEventBuilderInterface_->stop(45, 0);
377 __SUP_COUT__ <<
"Ignoring error on halt." << __E__;
382 theARTDAQEventBuilderInterface_->shutdown(45);
386 __SUP_COUT_ERR__ <<
"Error occurred during shutdown! State="
387 << theARTDAQEventBuilderInterface_->status();
391 __SUP_COUT__ <<
"Halted." << __E__;
395 void EventBuilderApp::transitionInitializing(toolbox::Event::Reference e)
397 __SUP_COUT__ <<
"Initializing..." << __E__;
399 __SUP_COUT__ <<
"Initialized." << __E__;
403 void EventBuilderApp::transitionPausing(toolbox::Event::Reference e)
405 __SUP_COUT__ <<
"Pausing..." << __E__;
406 theARTDAQEventBuilderInterface_->pause(0, 0);
407 __SUP_COUT__ <<
"Paused." << __E__;
411 void EventBuilderApp::transitionResuming(toolbox::Event::Reference e)
413 __SUP_COUT__ <<
"Resuming..." << __E__;
414 theARTDAQEventBuilderInterface_->resume(0, 0);
415 __SUP_COUT__ <<
"Resumed." << __E__;
419 void EventBuilderApp::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 theARTDAQEventBuilderInterface_->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 EventBuilderApp::transitionStopping(toolbox::Event::Reference e)
443 __SUP_COUT__ <<
"Stopping..." << __E__;
444 theARTDAQEventBuilderInterface_->stop(45, 0);
445 __SUP_COUT__ <<
"Stopped." << __E__;