1 #include "canvas/Utilities/Exception.h"
2 #include "art/Framework/Art/artapp.h"
4 #define TRACE_NAME "DataReceiverCore"
5 #include "artdaq/DAQdata/Globals.hh"
6 #include "artdaq-core/Core/SimpleMemoryReader.hh"
7 #include "artdaq-core/Utilities/ExceptionHandler.hh"
9 #include "artdaq/Application/DataReceiverCore.hh"
10 #include "artdaq/TransferPlugins/TransferInterface.hh"
15 : stop_requested_(false)
16 , pause_requested_(false)
17 , run_is_paused_(false)
19 TLOG_DEBUG(app_name) <<
"Constructor" << TLOG_ENDL;
25 TLOG_DEBUG(app_name) <<
"Destructor" << TLOG_ENDL;
31 verbose_ = pset.get<
bool>(
"verbose",
false);
33 if (metric_pset.is_empty())
35 TLOG_INFO(app_name) <<
"No metric plugins appear to be defined" << TLOG_ENDL;
39 metricMan_.initialize(metric_pset, app_name +
"." + std::to_string(my_rank));
43 ExceptionHandler(ExceptionHandlerRethrow::no,
44 "Error loading metrics in DataReceiverCore::initialize()");
47 fhicl::ParameterSet tmp = pset;
50 fhicl::ParameterSet data_tmp = data_pset;
51 if (data_pset.has_key(
"expected_events_per_bunch"))
53 data_tmp.put<
int>(
"expected_fragments_per_event", data_pset.get<
int>(
"expected_events_per_bunch"));
65 stop_requested_.store(
false);
66 pause_requested_.store(
false);
67 run_is_paused_.store(
false);
68 metricMan_.do_start();
69 event_store_ptr_->startRun(
id.run());
70 receiver_ptr_->start_threads();
72 logMessage_(
"Started run " + boost::lexical_cast<std::string>(event_store_ptr_->runID()));
78 logMessage_(
"Stopping run " + boost::lexical_cast<std::string>(event_store_ptr_->runID()) +
79 ", subrun " + boost::lexical_cast<std::string>(event_store_ptr_->subrunID()));
87 stop_requested_.store(
true);
89 if (!run_is_paused_.load())
93 endSucceeded = event_store_ptr_->endSubrun();
94 while (!endSucceeded && attemptsToEnd < 3)
97 TLOG_DEBUG(app_name) <<
"Retrying EventStore::endSubrun()" << TLOG_ENDL;
98 endSucceeded = event_store_ptr_->endSubrun();
103 <<
"EventStore::endSubrun in stop method failed after three tries." << TLOG_ENDL;
107 endSucceeded =
false;
109 endSucceeded = event_store_ptr_->endRun();
110 while (!endSucceeded && attemptsToEnd < 3)
113 TLOG_DEBUG(app_name) <<
"Retrying EventStore::endRun()" << TLOG_ENDL;
114 endSucceeded = event_store_ptr_->endRun();
119 <<
"EventStore::endRun in stop method failed after three tries." << TLOG_ENDL;
122 endSucceeded =
false;
124 TLOG_DEBUG(
"DataReceiverCore") <<
"stop: Calling EventStore::endOfData" << TLOG_ENDL;
125 endSucceeded = event_store_ptr_->endOfData();
126 while (!endSucceeded && attemptsToEnd < 3)
129 TLOG_DEBUG(app_name) <<
"Retrying EventStore::endOfData()" << TLOG_ENDL;
130 endSucceeded = event_store_ptr_->endOfData();
133 run_is_paused_.store(
false);
139 logMessage_(
"Pausing run " + boost::lexical_cast<std::string>(event_store_ptr_->runID()) +
140 ", subrun " + boost::lexical_cast<std::string>(event_store_ptr_->subrunID()));
141 pause_requested_.store(
true);
143 bool endSucceeded =
false;
144 int attemptsToEnd = 1;
145 endSucceeded = event_store_ptr_->endSubrun();
146 while (!endSucceeded && attemptsToEnd < 3)
149 TLOG_DEBUG(app_name) <<
"Retrying EventStore::endSubrun()" << TLOG_ENDL;
150 endSucceeded = event_store_ptr_->endSubrun();
155 <<
"EventStore::endSubrun in pause method failed after three tries." << TLOG_ENDL;
158 run_is_paused_.store(
true);
164 logMessage_(
"Resuming run " + boost::lexical_cast<std::string>(event_store_ptr_->runID()));
165 pause_requested_.store(
false);
166 metricMan_.do_start();
167 event_store_ptr_->startSubrun();
168 run_is_paused_.store(
false);
179 TLOG_DEBUG(
"DataReceiverCore") <<
"shutdown: Shutting down DataReceiverManager" << TLOG_ENDL;
180 receiver_ptr_.reset(
nullptr);
182 bool endSucceeded =
false;
183 int attemptsToEnd = 1;
184 TLOG_DEBUG(
"DataReceiverCore") <<
"shutdown: Calling EventStore::endOfData" << TLOG_ENDL;
185 endSucceeded = event_store_ptr_->endOfData();
186 while (!endSucceeded && attemptsToEnd < 3)
189 TLOG_DEBUG(app_name) <<
"Retrying EventStore::endOfData()" << TLOG_ENDL;
190 endSucceeded = event_store_ptr_->endOfData();
193 TLOG_DEBUG(
"DataReceiverCore") <<
"shutdown: Shutting down SharedMemoryEventManager" << TLOG_ENDL;
194 event_store_ptr_.reset();
196 TLOG_DEBUG(
"DataReceiverCore") <<
"shutdown: Shutting down MetricManager" << TLOG_ENDL;
197 metricMan_.shutdown();
199 TLOG_DEBUG(
"DataReceiverCore") <<
"shutdown: Complete" << TLOG_ENDL;
205 TLOG_DEBUG(app_name) <<
"soft_initialize method called with DAQ "
206 <<
"ParameterSet = \"" << pset.to_string()
207 <<
"\"." << TLOG_ENDL;
213 TLOG_DEBUG(app_name) <<
"reinitialize method called with DAQ "
214 <<
"ParameterSet = \"" << pset.to_string()
215 <<
"\"." << TLOG_ENDL;
216 event_store_ptr_ =
nullptr;
217 return initialize(pset);
222 if (which ==
"incomplete_event_count")
224 if (event_store_ptr_ !=
nullptr)
226 return boost::lexical_cast<std::string>(event_store_ptr_->GetIncompleteEventCount());
233 if (which ==
"event_count")
235 if (receiver_ptr_ !=
nullptr)
236 return boost::lexical_cast<std::string>(receiver_ptr_->GetReceivedFragmentCount()->count());
246 std::string tmpString;
247 if (event_store_ptr_ !=
nullptr) tmpString.append(app_name +
" run number = " + boost::lexical_cast<std::string>(event_store_ptr_->runID()) +
".\n");
248 tmpString.append(
"Command \"" + which +
"\" is not currently supported.");
256 TLOG_INFO(app_name) << text << TLOG_ENDL;
260 TLOG_DEBUG(app_name) << text << TLOG_ENDL;
MetricManager metricMan_
MetricManager concrete instance (for Globals.hh::metricMan)
DataReceiverCore()
DataReceiverCore Constructor.
bool soft_initialize(fhicl::ParameterSet const &pset)
Soft-Initializes the DataReceiverCore. No-Op.
The SharedMemoryEventManager is a SharedMemoryManger which tracks events as they are built...
virtual ~DataReceiverCore()
bool resume()
Resumes the DataReceiverCore.
bool shutdown()
Shuts Down the DataReceiverCore.
bool start(art::RunID id)
Start the DataReceiverCore.
void logMessage_(std::string const &text)
Log a message, setting severity based on verbosity flag.
bool stop()
Stops the DataReceiverCore.
std::string report(std::string const &which) const
Send a report on a given run-time quantity.
bool pause()
Pauses the DataReceiverCore.
Receives Fragment objects from one or more DataSenderManager instances using TransferInterface plugin...
bool initializeDataReceiver(fhicl::ParameterSet const &pset, fhicl::ParameterSet const &data_pset, fhicl::ParameterSet const &metric_pset)
Initialize the DataReceiverCore (should be called from initialize() overrides.
bool reinitialize(fhicl::ParameterSet const &pset)
Reinitializes the DataReceiverCore.