1 #include "artdaq/DAQdata/Globals.hh"
2 #define TRACE_NAME (app_name + "_BoardReaderApp").c_str()
3 #include "artdaq/Application/BoardReaderApp.hh"
6 : fragment_receiver_ptr_(nullptr)
17 external_request_status_ =
true;
23 TLOG(TLVL_DEBUG) <<
"Initializing first deleting old instance " << (
void*)fragment_receiver_ptr_.get();
24 fragment_receiver_ptr_.reset(
nullptr);
26 TLOG(TLVL_DEBUG) <<
"Initializing new BoardReaderCore at " << (
void*)fragment_receiver_ptr_.get() <<
" with pset " << pset.to_string();
27 external_request_status_ = fragment_receiver_ptr_->initialize(pset, timeout, timestamp);
28 if (!external_request_status_)
30 report_string_ =
"Error initializing ";
31 report_string_.append(app_name +
" ");
32 report_string_.append(
"with ParameterSet = \"" + pset.to_string() +
"\".");
35 TLOG(TLVL_DEBUG) <<
"do_initialize(fhicl::ParameterSet, uint64_t, uint64_t): "
36 <<
"Done initializing.";
37 return external_request_status_;
43 external_request_status_ = fragment_receiver_ptr_->start(
id, timeout, timestamp);
44 if (!external_request_status_)
46 report_string_ =
"Error starting ";
47 report_string_.append(app_name +
" ");
48 report_string_.append(
"for run number ");
49 report_string_.append(boost::lexical_cast<std::string>(
id.run()));
50 report_string_.append(
", timeout ");
51 report_string_.append(boost::lexical_cast<std::string>(timeout));
52 report_string_.append(
", timestamp ");
53 report_string_.append(boost::lexical_cast<std::string>(timestamp));
54 report_string_.append(
".");
57 boost::thread::attributes attrs;
58 attrs.set_stack_size(4096 * 2000);
62 catch (
const boost::exception& e)
64 TLOG(TLVL_ERROR) <<
"Caught boost::exception starting Fragment Processing thread: " << boost::diagnostic_information(e) <<
", errno=" << errno;
65 std::cerr <<
"Caught boost::exception starting Fragment Processing thread: " << boost::diagnostic_information(e) <<
", errno=" << errno << std::endl;
73 return external_request_status_;
79 external_request_status_ = fragment_receiver_ptr_->stop(timeout, timestamp);
80 if (!external_request_status_)
82 report_string_ =
"Error stopping ";
83 report_string_.append(app_name +
".");
86 if (fragment_processing_thread_.joinable())
88 TLOG(TLVL_DEBUG) <<
"Joining fragment processing thread";
89 fragment_processing_thread_.join();
92 TLOG(TLVL_DEBUG) <<
"BoardReader Stopped. Getting run statistics";
93 int number_of_fragments_sent = -1;
94 if(fragment_receiver_ptr_) number_of_fragments_sent = fragment_receiver_ptr_->GetFragmentsProcessed();
95 TLOG(TLVL_DEBUG) <<
"do_stop(uint64_t, uint64_t): "
96 <<
"Number of fragments sent = " << number_of_fragments_sent
99 return external_request_status_;
105 external_request_status_ = fragment_receiver_ptr_->pause(timeout, timestamp);
106 if (!external_request_status_)
108 report_string_ =
"Error pausing ";
109 report_string_.append(app_name +
".");
112 if(fragment_processing_thread_.joinable()) fragment_processing_thread_.join();
113 int number_of_fragments_sent = fragment_receiver_ptr_->GetFragmentsProcessed();
114 TLOG(TLVL_DEBUG) <<
"do_pause(uint64_t, uint64_t): "
115 <<
"Number of fragments sent = " << number_of_fragments_sent
118 return external_request_status_;
124 external_request_status_ = fragment_receiver_ptr_->resume(timeout, timestamp);
125 if (!external_request_status_)
127 report_string_ =
"Error resuming ";
128 report_string_.append(app_name +
".");
131 boost::thread::attributes attrs;
132 attrs.set_stack_size(4096 * 2000);
139 return external_request_status_;
145 external_request_status_ = fragment_receiver_ptr_->shutdown(timeout);
148 if (fragment_processing_thread_.joinable()) fragment_processing_thread_.join();
149 if (!external_request_status_)
151 report_string_ =
"Error shutting down ";
152 report_string_.append(app_name +
".");
154 return external_request_status_;
160 external_request_status_ = fragment_receiver_ptr_->soft_initialize(pset, timeout, timestamp);
161 if (!external_request_status_)
163 report_string_ =
"Error soft-initializing ";
164 report_string_.append(app_name +
" ");
165 report_string_.append(
"with ParameterSet = \"" + pset.to_string() +
"\".");
167 return external_request_status_;
172 external_request_status_ = fragment_receiver_ptr_->reinitialize(pset, timeout, timestamp);
173 if (!external_request_status_)
175 report_string_ =
"Error reinitializing ";
176 report_string_.append(app_name +
" ");
177 report_string_.append(
"with ParameterSet = \"" + pset.to_string() +
"\".");
179 return external_request_status_;
184 TLOG(TLVL_DEBUG) <<
"Booted state entry action called.";
190 fragment_receiver_ptr_.reset(
nullptr);
195 external_request_status_ = fragment_receiver_ptr_->metaCommand(command, arg);
196 if (!external_request_status_)
198 report_string_ =
"Error running meta-command on ";
199 report_string_.append(app_name +
" ");
200 report_string_.append(
"with command = \"" + command +
"\", arg = \"" + arg +
"\".");
202 return external_request_status_;
207 std::string resultString;
210 if (which ==
"transition_status")
212 if (report_string_.length() > 0) {
return report_string_; }
213 else {
return "Success"; }
225 if (fragment_receiver_ptr_.get() != 0)
227 resultString.append(fragment_receiver_ptr_->report(which));
231 resultString.append(
"This BoardReader has not yet been initialized and ");
232 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.
BoardReaderCore implements the state machine for the BoardReader artdaq application. It contains a CommandableFragmentGenerator, which generates Fragments which are then sent to a DataSenderManager by 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 ...
BoardReaderApp()
BoardReaderApp Constructor.
void BootedEnter() override
Action taken upon entering the "Booted" state.
void process_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.