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/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)
21 TLOG(TLVL_DEBUG) <<
"Constructor";
26 TLOG(TLVL_DEBUG) <<
"Destructor";
32 verbose_ = data_pset.get<
bool>(
"verbose",
true);
35 TLOG(TLVL_INFO) <<
"Initializing Data Receiver";
37 if (metric_pset.is_empty())
39 TLOG(TLVL_INFO) <<
"No metric plugins appear to be defined";
43 metricMan->initialize(metric_pset, app_name);
47 ExceptionHandler(ExceptionHandlerRethrow::no,
48 "Error loading metrics in DataReceiverCore::initialize()");
51 fhicl::ParameterSet art_pset = pset;
52 if (art_pset.has_key(
"art"))
54 art_pset = art_pset.get<fhicl::ParameterSet>(
"art");
58 art_pset.erase(
"daq");
61 auto art_source_pset = art_pset.get<fhicl::ParameterSet>(
"source");
62 art_source_pset.put<fhicl::ParameterSet>(
"metrics", metric_pset);
63 art_pset.erase(
"source");
64 art_pset.put<fhicl::ParameterSet>(
"source", art_source_pset);
66 fhicl::ParameterSet data_tmp = data_pset;
67 if (data_pset.has_key(
"expected_events_per_bunch"))
69 data_tmp.put<
int>(
"expected_fragments_per_event", data_pset.get<
int>(
"expected_events_per_bunch"));
72 if (data_pset.has_key(
"rank"))
74 if (my_rank >= 0 && data_pset.get<
int>(
"rank") != my_rank)
76 TLOG(TLVL_WARNING) <<
"Rank specified at startup is different than rank specified at configure! Using rank received at configure!";
78 my_rank = data_pset.get<
int>(
"rank");
82 TLOG(TLVL_ERROR) <<
"Rank not specified at startup or in configuration! Aborting";
86 event_store_ptr_ = std::make_shared<SharedMemoryEventManager>(data_tmp, art_pset);
88 TLOG(TLVL_DEBUG) <<
"Resulting art_pset_: \"" << art_pset_.to_string() <<
"\".";
90 receiver_ptr_ = std::make_unique<artdaq::DataReceiverManager>(data_tmp, event_store_ptr_);
97 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG)) <<
"Starting run " <<
id.run();
106 fhicl::ParameterSet temp_pset = art_pset_;
107 if (!config_archive_entries_.empty())
109 fhicl::ParameterSet config_pset;
110 for (
auto& entry : config_archive_entries_)
112 config_pset.put(entry.first, entry.second);
114 temp_pset.put_or_replace(
"configuration_documents", config_pset);
116 event_store_ptr_->UpdateArtConfiguration(temp_pset);
118 stop_requested_.store(
false);
119 pause_requested_.store(
false);
120 run_is_paused_.store(
false);
121 metricMan->do_start();
122 event_store_ptr_->startRun(
id.run());
123 receiver_ptr_->start_threads();
125 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG)) <<
"Completed the Start transition for run " << event_store_ptr_->runID();
131 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG)) <<
"Stopping run " << event_store_ptr_->runID();
132 bool endSucceeded =
false;
134 receiver_ptr_->stop_threads();
140 stop_requested_.store(
true);
142 TLOG(TLVL_DEBUG) <<
"Ending run " << event_store_ptr_->runID();
144 endSucceeded = event_store_ptr_->endRun();
145 while (!endSucceeded && attemptsToEnd < 3)
148 TLOG(TLVL_DEBUG) <<
"Retrying EventStore::endRun()";
149 endSucceeded = event_store_ptr_->endRun();
154 <<
"EventStore::endRun in stop method failed after three tries.";
156 TLOG(TLVL_DEBUG) <<
"Done Ending run " << event_store_ptr_->runID();
159 TLOG(TLVL_DEBUG) <<
"stop: Calling EventStore::endOfData";
160 endSucceeded = event_store_ptr_->endOfData();
161 while (!endSucceeded && attemptsToEnd < 3)
164 TLOG(TLVL_DEBUG) <<
"Retrying EventStore::endOfData()";
165 endSucceeded = event_store_ptr_->endOfData();
168 run_is_paused_.store(
false);
169 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG)) <<
"Completed the Stop transition for run " << event_store_ptr_->runID();
175 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG)) <<
"Pausing run " << event_store_ptr_->runID();
176 pause_requested_.store(
true);
177 run_is_paused_.store(
true);
178 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG)) <<
"Completed the Pause transition for run " << event_store_ptr_->runID();
184 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG)) <<
"Resuming run " << event_store_ptr_->runID();
185 pause_requested_.store(
false);
186 metricMan->do_start();
187 event_store_ptr_->rolloverSubrun();
188 run_is_paused_.store(
false);
189 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG)) <<
"Completed the Resume transition for run " << event_store_ptr_->runID();
195 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG)) <<
"Starting Shutdown transition";
202 TLOG(TLVL_DEBUG) <<
"shutdown: Shutting down DataReceiverManager";
203 receiver_ptr_.reset(
nullptr);
205 bool endSucceeded =
false;
206 int attemptsToEnd = 1;
207 TLOG(TLVL_DEBUG) <<
"shutdown: Calling EventStore::endOfData";
208 endSucceeded = event_store_ptr_->endOfData();
209 while (!endSucceeded && attemptsToEnd < 3)
212 TLOG(TLVL_DEBUG) <<
"Retrying EventStore::endOfData()";
213 endSucceeded = event_store_ptr_->endOfData();
216 TLOG(TLVL_DEBUG) <<
"shutdown: Shutting down SharedMemoryEventManager";
217 event_store_ptr_.reset();
219 TLOG(TLVL_DEBUG) <<
"shutdown: Shutting down MetricManager";
220 metricMan->shutdown();
222 TLOG(TLVL_DEBUG) <<
"shutdown: Complete";
223 TLOG((verbose_ ? TLVL_INFO : TLVL_DEBUG)) <<
"Completed Shutdown transition";
229 TLOG(TLVL_DEBUG) <<
"soft_initialize method called with DAQ "
230 <<
"ParameterSet = \"" << pset.to_string()
237 TLOG(TLVL_DEBUG) <<
"reinitialize method called with DAQ "
238 <<
"ParameterSet = \"" << pset.to_string()
240 event_store_ptr_ =
nullptr;
241 return initialize(pset);
246 if (event_store_ptr_)
248 event_store_ptr_->rolloverSubrun(boundary, subrun);
256 if (which ==
"incomplete_event_count")
258 if (event_store_ptr_ !=
nullptr)
260 return std::to_string(event_store_ptr_->GetIncompleteEventCount());
265 if (which ==
"event_count")
267 if (receiver_ptr_ !=
nullptr)
269 return std::to_string(receiver_ptr_->GetReceivedFragmentCount()->count());
280 std::string tmpString;
281 if (event_store_ptr_ !=
nullptr)
283 tmpString.append(app_name +
" run number = " + std::to_string(event_store_ptr_->runID()) +
".\n");
285 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.