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 run_is_paused_.store(
false);
128 logMessage_(
"Pausing run " + boost::lexical_cast<std::string>(event_store_ptr_->runID()) +
129 ", subrun " + boost::lexical_cast<std::string>(event_store_ptr_->subrunID()));
130 pause_requested_.store(
true);
132 bool endSucceeded =
false;
133 int attemptsToEnd = 1;
134 endSucceeded = event_store_ptr_->endSubrun();
135 while (!endSucceeded && attemptsToEnd < 3)
138 TLOG_DEBUG(app_name) <<
"Retrying EventStore::endSubrun()" << TLOG_ENDL;
139 endSucceeded = event_store_ptr_->endSubrun();
144 <<
"EventStore::endSubrun in pause method failed after three tries." << TLOG_ENDL;
147 run_is_paused_.store(
true);
153 logMessage_(
"Resuming run " + boost::lexical_cast<std::string>(event_store_ptr_->runID()));
154 pause_requested_.store(
false);
155 metricMan_.do_start();
156 event_store_ptr_->startSubrun();
157 run_is_paused_.store(
false);
168 TLOG_DEBUG(
"DataReceiverCore") <<
"shutdown: Shutting down DataReceiverManager" << TLOG_ENDL;
169 receiver_ptr_.reset(
nullptr);
171 bool endSucceeded =
false;
172 int attemptsToEnd = 1;
173 TLOG_DEBUG(
"DataReceiverCore") <<
"shutdown: Calling EventStore::endOfData" << TLOG_ENDL;
174 endSucceeded = event_store_ptr_->endOfData();
175 while (!endSucceeded && attemptsToEnd < 3)
178 TLOG_DEBUG(app_name) <<
"Retrying EventStore::endOfData()" << TLOG_ENDL;
179 endSucceeded = event_store_ptr_->endOfData();
182 TLOG_DEBUG(
"DataReceiverCore") <<
"shutdown: Shutting down SharedMemoryEventManager" << TLOG_ENDL;
183 event_store_ptr_.reset();
185 TLOG_DEBUG(
"DataReceiverCore") <<
"shutdown: Shutting down MetricManager" << TLOG_ENDL;
186 metricMan_.shutdown();
188 TLOG_DEBUG(
"DataReceiverCore") <<
"shutdown: Complete" << TLOG_ENDL;
194 TLOG_DEBUG(app_name) <<
"soft_initialize method called with DAQ "
195 <<
"ParameterSet = \"" << pset.to_string()
196 <<
"\"." << TLOG_ENDL;
202 TLOG_DEBUG(app_name) <<
"reinitialize method called with DAQ "
203 <<
"ParameterSet = \"" << pset.to_string()
204 <<
"\"." << TLOG_ENDL;
205 event_store_ptr_ =
nullptr;
206 return initialize(pset);
211 if (which ==
"incomplete_event_count")
213 if (event_store_ptr_ !=
nullptr)
215 return boost::lexical_cast<std::string>(event_store_ptr_->GetIncompleteEventCount());
222 if (which ==
"event_count")
224 if (receiver_ptr_ !=
nullptr)
225 return boost::lexical_cast<std::string>(receiver_ptr_->GetReceivedFragmentCount()->count());
235 std::string tmpString;
236 if (event_store_ptr_ !=
nullptr) tmpString.append(app_name +
" run number = " + boost::lexical_cast<std::string>(event_store_ptr_->runID()) +
".\n");
237 tmpString.append(
"Command \"" + which +
"\" is not currently supported.");
245 TLOG_INFO(app_name) << text << TLOG_ENDL;
249 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.