1 #include "art/Framework/Art/artapp.h"
2 #include "canvas/Utilities/Exception.h"
4 #include "artdaq/DAQdata/Globals.hh"
5 #define TRACE_NAME (app_name + "_DataReceiverCore").c_str()
6 #include "artdaq-core/Utilities/ExceptionHandler.hh"
8 #include "artdaq/Application/DataReceiverCore.hh"
9 #include "artdaq/TransferPlugins/TransferInterface.hh"
15 : stop_requested_(false)
16 , pause_requested_(false)
17 , run_is_paused_(false)
20 TLOG(TLVL_DEBUG + 32) <<
"Constructor";
25 TLOG(TLVL_DEBUG + 32) <<
"Destructor";
31 verbose_ = data_pset.get<
bool>(
"verbose",
true);
34 TLOG(TLVL_INFO) <<
"Initializing Data Receiver";
36 if (metric_pset.is_empty())
38 TLOG(TLVL_INFO) <<
"No metric plugins appear to be defined";
42 metricMan->initialize(metric_pset, app_name);
46 ExceptionHandler(ExceptionHandlerRethrow::no,
47 "Error loading metrics in DataReceiverCore::initialize()");
50 fhicl::ParameterSet art_pset = pset;
51 if (art_pset.has_key(
"art"))
53 art_pset = art_pset.get<fhicl::ParameterSet>(
"art");
57 art_pset.erase(
"daq");
61 auto art_services_pset = art_pset.get<fhicl::ParameterSet>(
"services");
62 auto art_services_ArtdaqSharedMemoryServiceInterface_pset = art_services_pset.get<fhicl::ParameterSet>(
"ArtdaqSharedMemoryServiceInterface");
63 art_services_ArtdaqSharedMemoryServiceInterface_pset.put<fhicl::ParameterSet>(
"metrics", metric_pset);
64 art_services_pset.erase(
"ArtdaqSharedMemoryServiceInterface");
65 art_services_pset.put<fhicl::ParameterSet>(
"ArtdaqSharedMemoryServiceInterface", art_services_ArtdaqSharedMemoryServiceInterface_pset);
66 art_pset.erase(
"services");
67 art_pset.put<fhicl::ParameterSet>(
"services", art_services_pset);
69 fhicl::ParameterSet data_tmp = data_pset;
70 if (data_pset.has_key(
"expected_events_per_bunch"))
72 data_tmp.put<
int>(
"expected_fragments_per_event", data_pset.get<
int>(
"expected_events_per_bunch"));
75 if (data_pset.has_key(
"rank"))
77 if (my_rank >= 0 && data_pset.get<
int>(
"rank") != my_rank)
79 TLOG(TLVL_WARNING) <<
"Rank specified at startup is different than rank specified at configure! Using rank received at configure!";
81 my_rank = data_pset.get<
int>(
"rank");
85 TLOG(TLVL_ERROR) <<
"Rank not specified at startup or in configuration! Aborting";
89 event_store_ptr_ = std::make_shared<SharedMemoryEventManager>(data_tmp, art_pset);
91 TLOG(TLVL_DEBUG + 32) <<
"Resulting art_pset_: \"" << art_pset_.to_string() <<
"\".";
93 receiver_ptr_ = std::make_unique<artdaq::DataReceiverManager>(data_tmp, event_store_ptr_);
100 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG + 32)) <<
"Starting run " <<
id.run();
109 fhicl::ParameterSet temp_pset = art_pset_;
110 if (!config_archive_entries_.empty())
112 fhicl::ParameterSet config_pset;
113 for (
auto& entry : config_archive_entries_)
115 config_pset.put(entry.first, entry.second);
117 temp_pset.put_or_replace(
"configuration_documents", config_pset);
119 event_store_ptr_->UpdateArtConfiguration(temp_pset);
121 stop_requested_.store(
false);
122 pause_requested_.store(
false);
123 run_is_paused_.store(
false);
124 metricMan->do_start();
125 event_store_ptr_->startRun(
id.run());
126 receiver_ptr_->start_threads();
128 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG + 32)) <<
"Completed the Start transition for run " << event_store_ptr_->runID();
134 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG + 32)) <<
"Stopping run " << event_store_ptr_->runID();
135 bool endSucceeded =
false;
137 receiver_ptr_->stop_threads();
143 stop_requested_.store(
true);
145 TLOG(TLVL_DEBUG + 32) <<
"Ending run " << event_store_ptr_->runID();
147 endSucceeded = event_store_ptr_->endRun();
148 while (!endSucceeded && attemptsToEnd < 3)
151 TLOG(TLVL_DEBUG + 32) <<
"Retrying EventStore::endRun()";
152 endSucceeded = event_store_ptr_->endRun();
157 <<
"EventStore::endRun in stop method failed after three tries.";
159 TLOG(TLVL_DEBUG + 32) <<
"Done Ending run " << event_store_ptr_->runID();
162 TLOG(TLVL_DEBUG + 32) <<
"stop: Calling EventStore::endOfData";
163 endSucceeded = event_store_ptr_->endOfData();
164 while (!endSucceeded && attemptsToEnd < 3)
167 TLOG(TLVL_DEBUG + 32) <<
"Retrying EventStore::endOfData()";
168 endSucceeded = event_store_ptr_->endOfData();
171 run_is_paused_.store(
false);
172 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG + 32)) <<
"Completed the Stop transition for run " << event_store_ptr_->runID();
178 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG + 32)) <<
"Pausing run " << event_store_ptr_->runID();
179 pause_requested_.store(
true);
180 run_is_paused_.store(
true);
181 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG + 32)) <<
"Completed the Pause transition for run " << event_store_ptr_->runID();
187 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG + 32)) <<
"Resuming run " << event_store_ptr_->runID();
188 pause_requested_.store(
false);
189 metricMan->do_start();
190 event_store_ptr_->rolloverSubrun();
191 run_is_paused_.store(
false);
192 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG + 32)) <<
"Completed the Resume transition for run " << event_store_ptr_->runID();
198 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG + 32)) <<
"Starting Shutdown transition";
205 TLOG(TLVL_DEBUG + 32) <<
"shutdown: Shutting down DataReceiverManager";
206 receiver_ptr_.reset(
nullptr);
208 bool endSucceeded =
false;
209 int attemptsToEnd = 1;
210 TLOG(TLVL_DEBUG + 32) <<
"shutdown: Calling EventStore::endOfData";
211 endSucceeded = event_store_ptr_->endOfData();
212 while (!endSucceeded && attemptsToEnd < 3)
215 TLOG(TLVL_DEBUG + 32) <<
"Retrying EventStore::endOfData()";
216 endSucceeded = event_store_ptr_->endOfData();
219 TLOG(TLVL_DEBUG + 32) <<
"shutdown: Shutting down SharedMemoryEventManager";
220 event_store_ptr_.reset();
222 TLOG(TLVL_DEBUG + 32) <<
"shutdown: Shutting down MetricManager";
223 metricMan->shutdown();
225 TLOG(TLVL_DEBUG + 32) <<
"shutdown: Complete";
226 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG + 32)) <<
"Completed Shutdown transition";
232 TLOG(TLVL_DEBUG + 32) <<
"soft_initialize method called with DAQ "
233 <<
"ParameterSet = \"" << pset.to_string()
240 TLOG(TLVL_DEBUG + 32) <<
"reinitialize method called with DAQ "
241 <<
"ParameterSet = \"" << pset.to_string()
243 event_store_ptr_ =
nullptr;
244 return initialize(pset);
249 if (event_store_ptr_)
251 event_store_ptr_->rolloverSubrun(boundary, subrun);
259 if (which ==
"open_event_count")
261 if (event_store_ptr_ !=
nullptr)
263 return std::to_string(event_store_ptr_->GetOpenEventCount());
268 if (which ==
"event_count")
270 if (receiver_ptr_ !=
nullptr)
272 return std::to_string(receiver_ptr_->GetReceivedFragmentCount()->count());
283 std::string tmpString;
284 if (event_store_ptr_ !=
nullptr)
286 tmpString.append(app_name +
" run number = " + std::to_string(event_store_ptr_->runID()) +
".\n");
288 tmpString.append(
"Command \"" + which +
"\" is not currently supported.");
DataReceiverCore()
DataReceiverCore Constructor.
bool soft_initialize(fhicl::ParameterSet const &pset)
Soft-Initializes the DataReceiverCore. No-Op.
bool rollover_subrun(uint64_t boundary, uint32_t subrun)
Rollover the subrun after the given event.
virtual ~DataReceiverCore()
bool resume()
Resumes the DataReceiverCore.
bool shutdown()
Shuts Down the DataReceiverCore.
bool start(art::RunID id)
Start the DataReceiverCore.
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.
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.