1 #include "otsdaq-core/DataProcessorPlugins/ARTDAQConsumer.h"
2 #include "otsdaq-core/MessageFacility/MessageFacility.h"
3 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
4 #include "artdaq/Application/Commandable.hh"
5 #include "otsdaq-core/Macros/ProcessorPluginMacros.h"
6 #include "fhiclcpp/make_ParameterSet.h"
7 #include "otsdaq-core/DataManager/DataManagerSingleton.h"
8 #include "otsdaq-core/DataManager/DataManager.h"
18 #define ARTDAQ_FCL_PATH std::string(getenv("USER_DATA")) + "/"+ "ARTDAQConfigurations/"
19 #define ARTDAQ_FILE_PREAMBLE "boardReader"
22 ARTDAQConsumer::ARTDAQConsumer (std::string supervisorApplicationUID, std::string bufferUID, std::string processorUID,
const ConfigurationTree& theXDAQContextConfigTree,
const std::string& configurationPath)
24 ,
DataConsumer (supervisorApplicationUID, bufferUID, processorUID, LowConsumerPriority)
25 ,
Configurable (theXDAQContextConfigTree, configurationPath)
27 __MOUT__ <<
"ARTDAQ CONSUMER CONSTRUCTOR!!!" << std::endl;
31 std::string filename = ARTDAQ_FCL_PATH + ARTDAQ_FILE_PREAMBLE +
"-";
32 std::string uid = theXDAQContextConfigTree.getNode(configurationPath).getValue();
34 __MOUT__ <<
"uid: " << uid << std::endl;
35 for(
unsigned int i=0;i<uid.size();++i)
36 if((uid[i] >=
'a' && uid[i] <=
'z') ||
37 (uid[i] >=
'A' && uid[i] <=
'Z') ||
38 (uid[i] >=
'0' && uid[i] <=
'9'))
42 __MOUT__ << std::endl;
43 __MOUT__ << std::endl;
44 __MOUT__ <<
"filename: " << filename << std::endl;
46 std::string fileFclString;
48 std::ifstream in(filename, std::ios::in | std::ios::binary);
52 in.seekg(0, std::ios::end);
53 fileFclString.resize(in.tellg());
54 in.seekg(0, std::ios::beg);
55 in.read(&fileFclString[0], fileFclString.size());
66 size_t fcli = fileFclString.find(
"fragment_receiver: {") +
67 +strlen(
"fragment_receiver: {");
68 if(fcli == std::string::npos)
70 __SS__ <<
"Could not find 'fragment_receiver: {' in Board Reader fcl string!" << std::endl;
71 __MOUT__ <<
"\n" << ss.str();
72 throw std::runtime_error(ss.str());
76 __MOUT__ <<
"configurationPath " << configurationPath << std::endl;
78 std::string consumerID, bufferID, appID;
79 unsigned int backSteps;
80 size_t backi = -1, backj;
82 for(
unsigned int i=0; i<backSteps; i++)
87 backi = configurationPath.rfind(
'/',backi-1);
93 consumerID = configurationPath.substr(backi+1,backj-backi-1);
95 bufferID = configurationPath.substr(backi+1,backj-backi-1);
97 appID = configurationPath.substr(backi+1,backj-backi-1);
101 fileFclString = fileFclString.substr(0,fcli) +
"\n\t\t" +
102 "SupervisorApplicationUID: \"" + appID +
"\"\n\t\t" +
103 "BufferUID: \"" + bufferID +
"\"\n\t\t" +
104 "ProcessorUID: \"" + consumerID +
"\"\n" +
105 fileFclString.substr(fcli);
107 __MOUT__ << fileFclString << std::endl;
109 fhicl::make_ParameterSet(fileFclString, fhiclConfiguration_);
123 ARTDAQConsumer::~ARTDAQConsumer(
void)
126 __MOUT__ <<
"DONE DELETING!" << std::endl;
130 void ARTDAQConsumer::initLocalGroup(
int rank)
132 name_ =
"BoardReader_" + DataConsumer::processorUID_;
136 #define ARTDAQ_FCL_PATH std::string(getenv("USER_DATA")) + "/"+ "ARTDAQConfigurations/"
137 #define ARTDAQ_FILE_PREAMBLE "boardReader"
140 void ARTDAQConsumer::configure(
int rank)
142 std::cout << __COUT_HDR_FL__ <<
"\tConfigure" << std::endl;
145 external_request_status_ =
true;
151 artdaq::Commandable tmpCommandable;
152 fragment_receiver_ptr_.reset(
nullptr);
153 std::cout << __COUT_HDR_FL__ <<
"\tNew core" << std::endl;
154 fragment_receiver_ptr_.reset(
new artdaq::BoardReaderCore(tmpCommandable, rank, name_));
156 uint64_t timeout = 45;
158 uint64_t timestamp = 184467440737095516;
159 std::cout << __COUT_HDR_FL__ <<
"\tInitialize: " << std::endl;
160 external_request_status_ = fragment_receiver_ptr_->initialize(fhiclConfiguration_, timeout, timestamp);
161 std::cout << __COUT_HDR_FL__ <<
"\tDone Initialize" << std::endl;
162 if (! external_request_status_)
164 report_string_ =
"Error initializing ";
165 report_string_.append(name_ +
" ");
166 report_string_.append(
"with ParameterSet = \"" + fhiclConfiguration_.to_string() +
"\".");
168 std::cout << __COUT_HDR_FL__ <<
"\tDone Configure" << std::endl;
172 void ARTDAQConsumer::halt(
void)
174 std::cout << __COUT_HDR_FL__ <<
"\tHalt" << std::endl;
176 uint64_t timeout = 45;
179 external_request_status_ = fragment_receiver_ptr_->shutdown(timeout);
180 if (! external_request_status_)
182 report_string_ =
"Error shutting down ";
183 report_string_.append(name_ +
".");
188 void ARTDAQConsumer::pauseProcessingData(
void)
190 std::cout << __COUT_HDR_FL__ <<
"\tPause" << std::endl;
192 uint64_t timeout = 45;
193 uint64_t timestamp = 184467440737095516;
195 external_request_status_ = fragment_receiver_ptr_->pause(timeout, timestamp);
196 if (! external_request_status_)
198 report_string_ =
"Error pausing ";
199 report_string_.append(name_ +
".");
202 if (fragment_processing_future_.valid())
204 int number_of_fragments_sent = fragment_processing_future_.get();
205 mf::LogDebug(name_+
"App::do_pause(uint64_t, uint64_t)")
206 <<
"Number of fragments sent = " << number_of_fragments_sent
212 void ARTDAQConsumer::resumeProcessingData(
void)
214 std::cout << __COUT_HDR_FL__ <<
"\tResume" << std::endl;
216 uint64_t timeout = 45;
217 uint64_t timestamp = 184467440737095516;
219 external_request_status_ = fragment_receiver_ptr_->resume(timeout, timestamp);
220 if (! external_request_status_)
222 report_string_ =
"Error resuming ";
223 report_string_.append(name_ +
".");
226 fragment_processing_future_ = std::async(std::launch::async, &artdaq::BoardReaderCore::process_fragments, fragment_receiver_ptr_.get());
231 void ARTDAQConsumer::startProcessingData(std::string runNumber)
233 std::cout << __COUT_HDR_FL__ <<
"\tStart" << std::endl;
235 art::RunID runId((art::RunNumber_t)boost::lexical_cast<art::RunNumber_t>(runNumber));
238 uint64_t timeout = 45;
239 uint64_t timestamp = 184467440737095516;
242 std::cout << __COUT_HDR_FL__ <<
"\tStart run: " << runId << std::endl;
243 external_request_status_ = fragment_receiver_ptr_->start(runId, timeout, timestamp);
244 std::cout << __COUT_HDR_FL__ <<
"\tStart already crashed "<< std::endl;
245 if (! external_request_status_)
247 report_string_ =
"Error starting ";
248 report_string_.append(name_ +
" ");
249 report_string_.append(
"for run number ");
250 report_string_.append(boost::lexical_cast<std::string>(runId.run()));
251 report_string_.append(
", timeout ");
252 report_string_.append(boost::lexical_cast<std::string>(timeout));
253 report_string_.append(
", timestamp ");
254 report_string_.append(boost::lexical_cast<std::string>(timestamp));
255 report_string_.append(
".");
258 std::cout << __COUT_HDR_FL__ <<
"STARTING BOARD READER THREAD" << std::endl;
259 fragment_processing_future_ = std::async(std::launch::async, &artdaq::BoardReaderCore::process_fragments, fragment_receiver_ptr_.get());
264 void ARTDAQConsumer::stopProcessingData(
void)
266 std::cout << __COUT_HDR_FL__ <<
"\tStop" << std::endl;
268 uint64_t timeout = 45;
269 uint64_t timestamp = 184467440737095516;
271 external_request_status_ = fragment_receiver_ptr_->stop(timeout, timestamp);
272 if (! external_request_status_)
274 report_string_ =
"Error stopping ";
275 report_string_.append(name_ +
".");
279 if (fragment_processing_future_.valid())
281 int number_of_fragments_sent = fragment_processing_future_.get();
282 mf::LogDebug(name_ +
"App::do_stop(uint64_t, uint64_t)")
283 <<
"Number of fragments sent = " << number_of_fragments_sent