1 #include "artdaq/Application/BoardReaderApp.hh"
2 #include "artdaq-core/Utilities/ExceptionHandler.hh"
4 #include "artdaq/DAQdata/Globals.hh"
5 #define TRACE_NAME (app_name + "_BoardReaderApp").c_str() // NOLINT
11 : fragment_receiver_ptr_(nullptr)
22 external_request_status_ =
true;
28 TLOG(TLVL_DEBUG) <<
"Initializing first deleting old instance " <<
static_cast<void*
>(fragment_receiver_ptr_.get());
29 fragment_receiver_ptr_.reset(
nullptr);
30 fragment_receiver_ptr_ = std::make_unique<BoardReaderCore>(*this);
31 TLOG(TLVL_DEBUG) <<
"Initializing new BoardReaderCore at " <<
static_cast<void*
>(fragment_receiver_ptr_.get()) <<
" with pset " << pset.to_string();
32 external_request_status_ = fragment_receiver_ptr_->initialize(pset, timeout, timestamp);
33 if (!external_request_status_)
35 report_string_ =
"Error initializing ";
36 report_string_.append(app_name +
" ");
37 report_string_.append(
"with ParameterSet = \"" + pset.to_string() +
"\".");
40 TLOG(TLVL_DEBUG) <<
"do_initialize(fhicl::ParameterSet, uint64_t, uint64_t): "
41 <<
"Done initializing.";
42 return external_request_status_;
48 external_request_status_ = fragment_receiver_ptr_->start(
id, timeout, timestamp);
49 if (!external_request_status_)
51 report_string_ =
"Error starting ";
52 report_string_.append(app_name +
" ");
53 report_string_.append(
"for run number ");
54 report_string_.append(boost::lexical_cast<std::string>(
id.run()));
55 report_string_.append(
", timeout ");
56 report_string_.append(boost::lexical_cast<std::string>(timeout));
57 report_string_.append(
", timestamp ");
58 report_string_.append(boost::lexical_cast<std::string>(timestamp));
59 report_string_.append(
".");
62 boost::thread::attributes attrs;
63 attrs.set_stack_size(4096 * 2000);
69 catch (
const boost::exception& e)
71 std::stringstream exception_string;
72 exception_string <<
"Caught boost::exception starting Fragment Processing threads: " << boost::diagnostic_information(e) <<
", errno=" << errno;
74 ExceptionHandler(ExceptionHandlerRethrow::yes, exception_string.str());
77 return external_request_status_;
83 external_request_status_ = fragment_receiver_ptr_->stop(timeout, timestamp);
84 if (!external_request_status_)
86 report_string_ =
"Error stopping ";
87 report_string_.append(app_name +
".");
90 if (fragment_input_thread_.joinable())
92 TLOG(TLVL_DEBUG) <<
"Joining fragment input (Generator) thread";
93 fragment_input_thread_.join();
95 if (fragment_output_thread_.joinable())
97 TLOG(TLVL_DEBUG) <<
"Joining fragment output (Sender) thread";
98 fragment_output_thread_.join();
102 TLOG(TLVL_DEBUG) <<
"BoardReader Stopped. Getting run statistics";
103 int number_of_fragments_sent = -1;
104 if (fragment_receiver_ptr_)
106 number_of_fragments_sent = fragment_receiver_ptr_->GetFragmentsProcessed();
108 TLOG(TLVL_DEBUG) <<
"do_stop(uint64_t, uint64_t): "
109 <<
"Number of fragments sent = " << number_of_fragments_sent
112 return external_request_status_;
118 external_request_status_ = fragment_receiver_ptr_->pause(timeout, timestamp);
119 if (!external_request_status_)
121 report_string_ =
"Error pausing ";
122 report_string_.append(app_name +
".");
125 if (fragment_input_thread_.joinable()) fragment_input_thread_.join();
126 if (fragment_output_thread_.joinable()) fragment_output_thread_.join();
127 int number_of_fragments_sent = fragment_receiver_ptr_->GetFragmentsProcessed();
128 TLOG(TLVL_DEBUG) <<
"do_pause(uint64_t, uint64_t): "
129 <<
"Number of fragments sent = " << number_of_fragments_sent
132 return external_request_status_;
138 external_request_status_ = fragment_receiver_ptr_->resume(timeout, timestamp);
139 if (!external_request_status_)
141 report_string_ =
"Error resuming ";
142 report_string_.append(app_name +
".");
145 boost::thread::attributes attrs;
146 attrs.set_stack_size(4096 * 2000);
150 return external_request_status_;
156 external_request_status_ = fragment_receiver_ptr_->shutdown(timeout);
159 if (fragment_input_thread_.joinable()) fragment_input_thread_.join();
160 if (fragment_output_thread_.joinable()) fragment_output_thread_.join();
161 if (!external_request_status_)
163 report_string_ =
"Error shutting down ";
164 report_string_.append(app_name +
".");
166 return external_request_status_;
172 external_request_status_ = fragment_receiver_ptr_->soft_initialize(pset, timeout, timestamp);
173 if (!external_request_status_)
175 report_string_ =
"Error soft-initializing ";
176 report_string_.append(app_name +
" ");
177 report_string_.append(
"with ParameterSet = \"" + pset.to_string() +
"\".");
179 return external_request_status_;
184 external_request_status_ = fragment_receiver_ptr_->reinitialize(pset, timeout, timestamp);
185 if (!external_request_status_)
187 report_string_ =
"Error reinitializing ";
188 report_string_.append(app_name +
" ");
189 report_string_.append(
"with ParameterSet = \"" + pset.to_string() +
"\".");
191 return external_request_status_;
196 TLOG(TLVL_DEBUG) <<
"Booted state entry action called.";
202 fragment_receiver_ptr_.reset(
nullptr);
207 external_request_status_ = fragment_receiver_ptr_->metaCommand(command, arg);
208 if (!external_request_status_)
210 report_string_ =
"Error running meta-command on ";
211 report_string_.append(app_name +
" ");
212 report_string_.append(
"with command = \"" + command +
"\", arg = \"" + arg +
"\".");
214 return external_request_status_;
219 std::string resultString;
222 if (which ==
"transition_status")
224 if (report_string_.length() > 0) {
return report_string_; }
238 if (fragment_receiver_ptr_ !=
nullptr)
240 resultString.append(fragment_receiver_ptr_->report(which));
244 resultString.append(
"This BoardReader has not yet been initialized and ");
245 resultString.append(
"therefore can not provide reporting.");
bool do_soft_initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp) override
Soft-Initialize the BoardReaderCore.
bool do_resume(uint64_t timeout, uint64_t timestamp) override
Resume the BoardReaderCore.
bool do_stop(uint64_t timeout, uint64_t timestamp) override
Stop the BoardReaderCore.
bool do_meta_command(std::string const &command, std::string const &arg) override
Perform a user-defined command (passed to CommandableFragmentGenerator)
bool do_shutdown(uint64_t timeout) override
Shutdown the BoardReaderCore.
bool do_reinitialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp) override
Reinitialize the BoardReaderCore.
std::string report(std::string const &which) const override
If which is "transition_status", report the status of the last transition. Otherwise pass through to ...
void send_fragments()
Main working loop of the BoardReaderCore, pt. 2.
BoardReaderApp()
BoardReaderApp Constructor.
void BootedEnter() override
Action taken upon entering the "Booted" state.
void receive_fragments()
Main working loop of the BoardReaderCore.
bool do_start(art::RunID id, uint64_t timeout, uint64_t timestamp) override
Start the BoardReaderCore.
bool do_initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp) override
Initialize the BoardReaderCore.
bool do_pause(uint64_t timeout, uint64_t timestamp) override
Pause the BoardReaderCore.