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(__ENV__("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 =
318 theConfigurationManager_
319 ->getNode(ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME +
"/" +
320 CorePropertySupervisorBase::getSupervisorUID() +
"/" +
321 "LinkToSupervisorTable")
325 for(
unsigned int i = 0; i < uid.size(); ++i)
326 if((uid[i] >=
'a' && uid[i] <=
'z') || (uid[i] >=
'A' && uid[i] <=
'Z') ||
327 (uid[i] >=
'0' && uid[i] <=
'9'))
331 __SUP_COUTV__(filename);
333 std::string fileFclString;
335 std::ifstream in(filename, std::ios::in | std::ios::binary);
338 std::string contents;
339 in.seekg(0, std::ios::end);
340 fileFclString.resize(in.tellg());
341 in.seekg(0, std::ios::beg);
342 in.read(&fileFclString[0], fileFclString.size());
347 __SUP_SS__ <<
"Fhicl file not found! " << filename << __E__;
352 __SUP_COUTV__(fileFclString);
356 fhicl::make_ParameterSet(fileFclString, pset);
357 theARTDAQEventBuilderInterface_->initialize(pset, 0, 0);
359 catch(
const cet::coded_exception<fhicl::error, &fhicl::detail::translate>& e)
361 __SUP_SS__ <<
"Error was caught while configuring: " << e.what() << __E__;
362 __SUP_COUT_ERR__ <<
"\n" << ss.str();
363 theStateMachine_.setErrorMessage(ss.str());
364 throw toolbox::fsm::exception::Exception(
367 "EventBuilderApp::transitionConfiguring" ,
373 __SUP_COUT__ <<
"Configured." << __E__;
377 void EventBuilderApp::transitionHalting(toolbox::Event::Reference e)
379 __SUP_COUT__ <<
"Halting..." << __E__;
382 theARTDAQEventBuilderInterface_->stop(45, 0);
387 __SUP_COUT__ <<
"Ignoring error on halt." << __E__;
392 theARTDAQEventBuilderInterface_->shutdown(45);
396 __SUP_COUT_ERR__ <<
"Error occurred during shutdown! State="
397 << theARTDAQEventBuilderInterface_->status();
401 __SUP_COUT__ <<
"Halted." << __E__;
405 void EventBuilderApp::transitionInitializing(toolbox::Event::Reference e)
407 __SUP_COUT__ <<
"Initializing..." << __E__;
409 __SUP_COUT__ <<
"Initialized." << __E__;
413 void EventBuilderApp::transitionPausing(toolbox::Event::Reference e)
415 __SUP_COUT__ <<
"Pausing..." << __E__;
416 theARTDAQEventBuilderInterface_->pause(0, 0);
417 __SUP_COUT__ <<
"Paused." << __E__;
421 void EventBuilderApp::transitionResuming(toolbox::Event::Reference e)
423 __SUP_COUT__ <<
"Resuming..." << __E__;
424 theARTDAQEventBuilderInterface_->resume(0, 0);
425 __SUP_COUT__ <<
"Resumed." << __E__;
429 void EventBuilderApp::transitionStarting(toolbox::Event::Reference e)
431 __SUP_COUT__ <<
"Starting..." << __E__;
433 auto runNumber = SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
435 .getValue(
"RunNumber");
439 (art::RunNumber_t)boost::lexical_cast<art::RunNumber_t>(runNumber));
440 theARTDAQEventBuilderInterface_->start(runId, 0, 0);
442 catch(
const boost::exception& e)
444 __SUP_SS__ <<
"Error parsing string to art::RunNumber_t: " << runNumber << __E__;
447 __SUP_COUT__ <<
"Started." << __E__;
451 void EventBuilderApp::transitionStopping(toolbox::Event::Reference e)
453 __SUP_COUT__ <<
"Stopping..." << __E__;
454 theARTDAQEventBuilderInterface_->stop(45, 0);
455 __SUP_COUT__ <<
"Stopped." << __E__;