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"
16 , stop_requested_(false)
17 , pause_requested_(false)
18 , run_is_paused_(false)
20 TLOG_DEBUG(
name_) <<
"Constructor" << TLOG_ENDL;
27 TLOG_DEBUG(name_) <<
"Destructor" << TLOG_ENDL;
33 verbose_ = pset.get<
bool>(
"verbose",
false);
35 if (metric_pset.is_empty())
37 TLOG_INFO(name_) <<
"No metric plugins appear to be defined" << TLOG_ENDL;
41 metricMan_.initialize(metric_pset, name_ +
"." + std::to_string(my_rank));
45 ExceptionHandler(ExceptionHandlerRethrow::no,
46 "Error loading metrics in DataReceiverCore::initialize()");
49 fhicl::ParameterSet tmp = pset;
52 fhicl::ParameterSet data_tmp = data_pset;
53 if (data_pset.has_key(
"expected_events_per_bunch"))
55 data_tmp.put<
int>(
"expected_fragments_per_event", data_pset.get<
int>(
"expected_events_per_bunch"));
67 stop_requested_.store(
false);
68 pause_requested_.store(
false);
69 run_is_paused_.store(
false);
70 metricMan_.do_start();
71 event_store_ptr_->startRun(
id.run());
72 receiver_ptr_->start_threads();
74 logMessage_(
"Started run " + boost::lexical_cast<std::string>(event_store_ptr_->runID()));
80 logMessage_(
"Stopping run " + boost::lexical_cast<std::string>(event_store_ptr_->runID()) +
81 ", subrun " + boost::lexical_cast<std::string>(event_store_ptr_->subrunID()));
89 stop_requested_.store(
true);
91 if (!run_is_paused_.load())
95 endSucceeded = event_store_ptr_->endSubrun();
96 while (!endSucceeded && attemptsToEnd < 3)
99 TLOG_DEBUG(name_) <<
"Retrying EventStore::endSubrun()" << TLOG_ENDL;
100 endSucceeded = event_store_ptr_->endSubrun();
105 <<
"EventStore::endSubrun in stop method failed after three tries." << TLOG_ENDL;
109 endSucceeded =
false;
111 endSucceeded = event_store_ptr_->endRun();
112 while (!endSucceeded && attemptsToEnd < 3)
115 TLOG_DEBUG(name_) <<
"Retrying EventStore::endRun()" << TLOG_ENDL;
116 endSucceeded = event_store_ptr_->endRun();
121 <<
"EventStore::endRun in stop method failed after three tries." << TLOG_ENDL;
124 run_is_paused_.store(
false);
130 logMessage_(
"Pausing run " + boost::lexical_cast<std::string>(event_store_ptr_->runID()) +
131 ", subrun " + boost::lexical_cast<std::string>(event_store_ptr_->subrunID()));
132 pause_requested_.store(
true);
134 bool endSucceeded =
false;
135 int attemptsToEnd = 1;
136 endSucceeded = event_store_ptr_->endSubrun();
137 while (!endSucceeded && attemptsToEnd < 3)
140 TLOG_DEBUG(name_) <<
"Retrying EventStore::endSubrun()" << TLOG_ENDL;
141 endSucceeded = event_store_ptr_->endSubrun();
146 <<
"EventStore::endSubrun in pause method failed after three tries." << TLOG_ENDL;
149 run_is_paused_.store(
true);
155 logMessage_(
"Resuming run " + boost::lexical_cast<std::string>(event_store_ptr_->runID()));
156 pause_requested_.store(
false);
157 metricMan_.do_start();
158 event_store_ptr_->startSubrun();
159 run_is_paused_.store(
false);
170 TLOG_DEBUG(
"DataReceiverCore") <<
"shutdown: Shutting down DataReceiverManager" << TLOG_ENDL;
171 receiver_ptr_.reset(
nullptr);
173 bool endSucceeded =
false;
174 int attemptsToEnd = 1;
175 TLOG_DEBUG(
"DataReceiverCore") <<
"shutdown: Calling EventStore::endOfData" << TLOG_ENDL;
176 endSucceeded = event_store_ptr_->endOfData();
177 while (!endSucceeded && attemptsToEnd < 3)
180 TLOG_DEBUG(name_) <<
"Retrying EventStore::endOfData()" << TLOG_ENDL;
181 endSucceeded = event_store_ptr_->endOfData();
184 TLOG_DEBUG(
"DataReceiverCore") <<
"shutdown: Shutting down SharedMemoryEventManager" << TLOG_ENDL;
185 event_store_ptr_.reset();
187 TLOG_DEBUG(
"DataReceiverCore") <<
"shutdown: Shutting down MetricManager" << TLOG_ENDL;
188 metricMan_.shutdown();
190 TLOG_DEBUG(
"DataReceiverCore") <<
"shutdown: Complete" << TLOG_ENDL;
196 TLOG_DEBUG(name_) <<
"soft_initialize method called with DAQ "
197 <<
"ParameterSet = \"" << pset.to_string()
198 <<
"\"." << TLOG_ENDL;
204 TLOG_DEBUG(name_) <<
"reinitialize method called with DAQ "
205 <<
"ParameterSet = \"" << pset.to_string()
206 <<
"\"." << TLOG_ENDL;
207 event_store_ptr_ =
nullptr;
208 return initialize(pset);
213 if (which ==
"incomplete_event_count")
215 if (event_store_ptr_ !=
nullptr)
217 return boost::lexical_cast<std::string>(event_store_ptr_->GetIncompleteEventCount());
224 if (which ==
"event_count")
226 if (receiver_ptr_ !=
nullptr)
227 return boost::lexical_cast<std::string>(receiver_ptr_->GetReceivedFragmentCount()->count());
237 std::string tmpString;
238 if (event_store_ptr_ !=
nullptr) tmpString.append(name_ +
" run number = " + boost::lexical_cast<std::string>(event_store_ptr_->runID()) +
".\n");
239 tmpString.append(
"Command \"" + which +
"\" is not currently supported.");
247 TLOG_INFO(name_) << text << TLOG_ENDL;
251 TLOG_DEBUG(name_) << text << TLOG_ENDL;
MetricManager metricMan_
MetricManager concrete instance (for Globals.hh::metricMan)
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.
std::string name_
Name of this DataReceiverCore instance.
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.
DataReceiverCore(int rank, std::string name)
DataReceiverCore Constructor.
bool reinitialize(fhicl::ParameterSet const &pset)
Reinitializes the DataReceiverCore.