1 #include "canvas/Utilities/Exception.h"
2 #include "art/Framework/Art/artapp.h"
4 #define TRACE_NAME (app_name + "_DataReceiverCore").c_str() // include these 2 first -
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)
18 , config_archive_entries_()
20 TLOG(TLVL_DEBUG) <<
"Constructor" ;
25 TLOG(TLVL_DEBUG) <<
"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");
60 fhicl::ParameterSet art_source_pset = art_pset.get<fhicl::ParameterSet>(
"source");
61 art_source_pset.put<fhicl::ParameterSet>(
"metrics", metric_pset);
62 art_pset.erase(
"source");
63 art_pset.put<fhicl::ParameterSet>(
"source", art_source_pset);
65 fhicl::ParameterSet data_tmp = data_pset;
66 if (data_pset.has_key(
"expected_events_per_bunch"))
68 data_tmp.put<
int>(
"expected_fragments_per_event", data_pset.get<
int>(
"expected_events_per_bunch"));
71 if (data_pset.has_key(
"rank"))
73 if (my_rank >= 0 && data_pset.get<
int>(
"rank") != my_rank) {
74 TLOG(TLVL_WARNING) <<
"Rank specified at startup is different than rank specified at configure! Using rank received at configure!";
76 my_rank = data_pset.get<
int>(
"rank");
80 TLOG(TLVL_ERROR) <<
"Rank not specified at startup or in configuration! Aborting";
86 TLOG(TLVL_DEBUG) <<
"Resulting art_pset_: \"" << art_pset_.to_string() <<
"\"." ;
95 logMessage_(
"Starting run " + boost::lexical_cast<std::string>(
id.run()));
104 fhicl::ParameterSet temp_pset = art_pset_;
105 if (! config_archive_entries_.empty())
107 fhicl::ParameterSet config_pset;
108 for (
auto& entry : config_archive_entries_)
110 config_pset.put(entry.first, entry.second);
112 temp_pset.put_or_replace(
"configuration_documents", config_pset);
114 event_store_ptr_->UpdateArtConfiguration(temp_pset);
116 stop_requested_.store(
false);
117 pause_requested_.store(
false);
118 run_is_paused_.store(
false);
119 metricMan->do_start();
120 event_store_ptr_->startRun(
id.run());
121 receiver_ptr_->start_threads();
123 logMessage_(
"Completed the Start transition for run " + boost::lexical_cast<std::string>(event_store_ptr_->runID()));
129 logMessage_(
"Stopping run " + boost::lexical_cast<std::string>(event_store_ptr_->runID()));
130 bool endSucceeded =
false;
132 receiver_ptr_->stop_threads();
138 stop_requested_.store(
true);
140 TLOG(TLVL_DEBUG) <<
"Ending run " << event_store_ptr_->runID();
142 endSucceeded = event_store_ptr_->endRun();
143 while (!endSucceeded && attemptsToEnd < 3)
146 TLOG(TLVL_DEBUG) <<
"Retrying EventStore::endRun()" ;
147 endSucceeded = event_store_ptr_->endRun();
152 <<
"EventStore::endRun in stop method failed after three tries." ;
154 TLOG(TLVL_DEBUG) <<
"Done Ending run " << event_store_ptr_->runID();
157 TLOG(TLVL_DEBUG) <<
"stop: Calling EventStore::endOfData" ;
158 endSucceeded = event_store_ptr_->endOfData();
159 while (!endSucceeded && attemptsToEnd < 3)
162 TLOG(TLVL_DEBUG) <<
"Retrying EventStore::endOfData()" ;
163 endSucceeded = event_store_ptr_->endOfData();
166 run_is_paused_.store(
false);
167 logMessage_(
"Completed the Stop transition for run " + boost::lexical_cast<std::string>(event_store_ptr_->runID()));
173 logMessage_(
"Pausing run " + boost::lexical_cast<std::string>(event_store_ptr_->runID()));
174 pause_requested_.store(
true);
175 run_is_paused_.store(
true);
176 logMessage_(
"Completed the Pause transition for run " + boost::lexical_cast<std::string>(event_store_ptr_->runID()));
182 logMessage_(
"Resuming run " + boost::lexical_cast<std::string>(event_store_ptr_->runID()));
183 pause_requested_.store(
false);
184 metricMan->do_start();
185 event_store_ptr_->rolloverSubrun();
186 run_is_paused_.store(
false);
187 logMessage_(
"Completed the Resume transition for run " + boost::lexical_cast<std::string>(event_store_ptr_->runID()));
193 logMessage_(
"Starting Shutdown transition");
200 TLOG(TLVL_DEBUG) <<
"shutdown: Shutting down DataReceiverManager" ;
201 receiver_ptr_.reset(
nullptr);
203 bool endSucceeded =
false;
204 int attemptsToEnd = 1;
205 TLOG(TLVL_DEBUG) <<
"shutdown: Calling EventStore::endOfData" ;
206 endSucceeded = event_store_ptr_->endOfData();
207 while (!endSucceeded && attemptsToEnd < 3)
210 TLOG(TLVL_DEBUG) <<
"Retrying EventStore::endOfData()" ;
211 endSucceeded = event_store_ptr_->endOfData();
214 TLOG(TLVL_DEBUG) <<
"shutdown: Shutting down SharedMemoryEventManager" ;
215 event_store_ptr_.reset();
217 TLOG(TLVL_DEBUG) <<
"shutdown: Shutting down MetricManager" ;
218 metricMan->shutdown();
220 TLOG(TLVL_DEBUG) <<
"shutdown: Complete" ;
221 logMessage_(
"Completed Shutdown transition");
227 TLOG(TLVL_DEBUG) <<
"soft_initialize method called with DAQ "
228 <<
"ParameterSet = \"" << pset.to_string()
235 TLOG(TLVL_DEBUG) <<
"reinitialize method called with DAQ "
236 <<
"ParameterSet = \"" << pset.to_string()
238 event_store_ptr_ =
nullptr;
239 return initialize(pset);
244 if (event_store_ptr_)
246 event_store_ptr_->rolloverSubrun(boundary, subrun);
254 if (which ==
"incomplete_event_count")
256 if (event_store_ptr_ !=
nullptr)
258 return boost::lexical_cast<std::string>(event_store_ptr_->GetIncompleteEventCount());
265 if (which ==
"event_count")
267 if (receiver_ptr_ !=
nullptr)
268 return boost::lexical_cast<std::string>(receiver_ptr_->GetReceivedFragmentCount()->count());
278 std::string tmpString;
279 if (event_store_ptr_ !=
nullptr) tmpString.append(app_name +
" run number = " + boost::lexical_cast<std::string>(event_store_ptr_->runID()) +
".\n");
280 tmpString.append(
"Command \"" + which +
"\" is not currently supported.");
288 TLOG(TLVL_INFO) << text ;
292 TLOG(TLVL_DEBUG) << text ;
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.
bool rollover_subrun(uint64_t eventNum, uint32_t subrun)
Rollover the subrun after the given event.
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.