1 #include "otsdaq/ARTDAQReaderCore/ARTDAQReaderProcessorBase.h"
2 #include "artdaq/Application/Commandable.hh"
3 #include "otsdaq/DataManager/DataManager.h"
4 #include "otsdaq/DataManager/DataManagerSingleton.h"
5 #include "otsdaq/Macros/CoutMacros.h"
7 #include "otsdaq/MessageFacility/MessageFacility.h"
16 #define ARTDAQ_FCL_PATH std::string(__ENV__("USER_DATA")) + "/" + "ARTDAQConfigurations/"
17 #define ARTDAQ_FILE_PREAMBLE "boardReader"
20 ARTDAQReaderProcessorBase::ARTDAQReaderProcessorBase(
23 std::string processorUID,
25 const std::string& configurationPath)
30 :
Configurable(theXDAQContextConfigTree, configurationPath)
31 , name_(
"BoardReader_" + processorUID)
35 __CFG_COUT__ <<
"Constructing..." << __E__;
40 std::string filename = ARTDAQ_FCL_PATH + ARTDAQ_FILE_PREAMBLE +
"-";
41 std::string uid = theXDAQContextConfigTree.
getNode(configurationPath).
getValue();
43 __CFG_COUT__ <<
"uid: " << uid << __E__;
44 for(
unsigned int i = 0; i < uid.size(); ++i)
45 if((uid[i] >=
'a' && uid[i] <=
'z') || (uid[i] >=
'A' && uid[i] <=
'Z') ||
46 (uid[i] >=
'0' && uid[i] <=
'9'))
50 __CFG_COUT__ << __E__;
51 __CFG_COUT__ << __E__;
52 __CFG_COUT__ <<
"filename: " << filename << __E__;
54 std::string fileFclString;
56 std::ifstream in(filename, std::ios::in | std::ios::binary);
60 in.seekg(0, std::ios::end);
61 fileFclString.resize(in.tellg());
62 in.seekg(0, std::ios::beg);
63 in.read(&fileFclString[0], fileFclString.size());
75 fileFclString.find(
"fragment_receiver: {") + +strlen(
"fragment_receiver: {");
76 if(fcli == std::string::npos)
78 __SS__ <<
"Could not find 'fragment_receiver: {' in Board Reader fcl string!"
80 __CFG_COUT__ <<
"\n" << ss.str();
85 __CFG_COUT__ <<
"configurationPath " << configurationPath << __E__;
87 std::string consumerID, bufferID, appID;
88 unsigned int backSteps;
89 size_t backi = -1, backj;
91 for(
unsigned int i = 0; i < backSteps; i++)
96 backi = configurationPath.rfind(
'/', backi - 1);
103 consumerID = configurationPath.substr(backi + 1, backj - backi - 1);
105 bufferID = configurationPath.substr(backi + 1, backj - backi - 1);
107 appID = configurationPath.substr(backi + 1, backj - backi - 1);
111 fileFclString = fileFclString.substr(0, fcli) +
"\n\t\t" +
112 "SupervisorApplicationUID: \"" + appID +
"\"\n\t\t" +
113 "BufferUID: \"" + bufferID +
"\"\n\t\t" +
"ProcessorUID: \"" +
114 consumerID +
"\"\n" + fileFclString.substr(fcli);
116 __CFG_COUT__ << fileFclString << __E__;
120 fhiclConfiguration_ = fhicl::ParameterSet::make(fileFclString);
122 catch(
const cet::coded_exception<fhicl::error, &fhicl::detail::translate>& e)
124 __CFG_SS__ <<
"Error was caught while configuring: " << e.what() << __E__;
127 catch(
const cet::exception& e)
129 __CFG_SS__ <<
"Error was caught while configuring: " << e.explain_self() << __E__;
134 __CFG_SS__ <<
"Unknown error was caught while configuring." << __E__;
151 ARTDAQReaderProcessorBase::~ARTDAQReaderProcessorBase(
void)
154 __CFG_COUT__ <<
"DONE DELETING!" << __E__;
160 #define ARTDAQ_FCL_PATH std::string(__ENV__("USER_DATA")) + "/" + "ARTDAQConfigurations/"
161 #define ARTDAQ_FILE_PREAMBLE "boardReader"
164 void ARTDAQReaderProcessorBase::configure(
int rank)
166 __CFG_COUT__ <<
"Configuring..." << __E__;
172 fragment_receiver_ptr_.reset(
nullptr);
173 __CFG_COUT__ <<
"New core" << __E__;
176 fragment_receiver_ptr_.reset(
new artdaq::BoardReaderApp());
180 uint64_t timeout = 45;
181 uint64_t timestamp = 184467440737095516;
182 __CFG_COUT__ <<
"Initializing '" << name_ <<
"'"
185 if(!fragment_receiver_ptr_->initialize(fhiclConfiguration_, timeout, timestamp))
187 __CFG_SS__ <<
"Error initializing '" << name_ <<
"' with ParameterSet = \n"
188 << fhiclConfiguration_.to_string() << __E__;
189 ss <<
"Here is the Board Reader report: \n"
190 << fragment_receiver_ptr_->report(
"" ) << __E__;
193 __CFG_COUT__ <<
"Done Initializing." << __E__;
197 __CFG_COUT__ <<
"Configured." << __E__;
201 void ARTDAQReaderProcessorBase::halt(
void)
203 __CFG_COUT__ <<
"Halting..." << __E__;
207 uint64_t timeout = 45;
209 if(!fragment_receiver_ptr_->shutdown(timeout))
211 __CFG_SS__ <<
"Error shutting down '" << name_ <<
".'" << __E__;
215 __CFG_COUT__ <<
"Halted." << __E__;
219 void ARTDAQReaderProcessorBase::pause(
void)
221 __CFG_COUT__ <<
"Pausing..." << __E__;
225 uint64_t timeout = 45;
226 uint64_t timestamp = 184467440737095516;
228 if(!fragment_receiver_ptr_->pause(timeout, timestamp))
230 __CFG_SS__ <<
"Error pausing '" << name_ <<
".'" << __E__;
234 __CFG_COUT__ <<
"Paused." << __E__;
238 void ARTDAQReaderProcessorBase::resume(
void)
240 __CFG_COUT__ <<
"Resuming..." << __E__;
244 uint64_t timeout = 45;
245 uint64_t timestamp = 184467440737095516;
247 if(!fragment_receiver_ptr_->resume(timeout, timestamp))
249 __CFG_SS__ <<
"Error resuming '" << name_ <<
".'" << __E__;
253 __CFG_COUT__ <<
"Resumed." << __E__;
257 void ARTDAQReaderProcessorBase::start(
const std::string& runNumber)
259 __CFG_COUT__ <<
"Starting..." << __E__;
261 art::RunID runId((art::RunNumber_t)boost::lexical_cast<art::RunNumber_t>(runNumber));
265 uint64_t timeout = 45;
266 uint64_t timestamp = 184467440737095516;
268 __CFG_COUT__ <<
"Start run: " << runId << __E__;
269 if(!fragment_receiver_ptr_->start(runId, timeout, timestamp))
271 __CFG_SS__ <<
"Error starting '" << name_ <<
"' for run number '" << runId <<
",'"
276 __CFG_COUT__ <<
"Started." << __E__;
280 void ARTDAQReaderProcessorBase::stop(
void)
282 __CFG_COUT__ <<
"Stop" << __E__;
286 uint64_t timeout = 45;
287 uint64_t timestamp = 184467440737095516;
289 auto sts = fragment_receiver_ptr_->status();
292 __CFG_COUT__ <<
"Already stopped - never started!" << __E__;
296 if(!fragment_receiver_ptr_->stop(timeout, timestamp))
298 __CFG_SS__ <<
"Error stopping '" << name_ <<
".'" << __E__;
302 __CFG_COUT__ <<
"Stopped." << __E__;
void initLocalGroup(int rank)
these functions are not inherited, they define the core reader functionality
ConfigurationTree getNode(const std::string &nodeName, bool doNotThrowOnBrokenUIDLinks=false) const
navigating between nodes
void getValue(T &value) const
void INIT_MF(const char *name)