00001 #define TRACE_NAME "BoardReaderApp"
00002 #include "tracemf.h"
00003 #include "artdaq/Application/BoardReaderApp.hh"
00004
00005 artdaq::BoardReaderApp::BoardReaderApp(int rank, std::string name)
00006 : fragment_receiver_ptr_(nullptr)
00007 , rank_(rank)
00008 , name_(name)
00009 {}
00010
00011
00012
00013
00014
00015 bool artdaq::BoardReaderApp::do_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
00016 {
00017 report_string_ = "";
00018 external_request_status_ = true;
00019
00020
00021
00022
00023
00024 TLOG_DEBUG(name_ + "App") << "Initializing first deleting old instance " << (void*)fragment_receiver_ptr_.get() << TLOG_ENDL;
00025 fragment_receiver_ptr_.reset(nullptr);
00026 fragment_receiver_ptr_.reset(new BoardReaderCore(*this, rank_, name_));
00027 TLOG_DEBUG(name_ + "App") << "Initializing new BoardReaderCore at " << (void*)fragment_receiver_ptr_.get() << " with pset " << pset.to_string() << TLOG_ENDL;
00028 external_request_status_ = fragment_receiver_ptr_->initialize(pset, timeout, timestamp);
00029 if (! external_request_status_)
00030 {
00031 report_string_ = "Error initializing ";
00032 report_string_.append(name_ + " ");
00033 report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
00034 }
00035
00036 TLOG_DEBUG(name_ + "App") << "do_initialize(fhicl::ParameterSet, uint64_t, uint64_t): "
00037 << "Done initializing." << TLOG_ENDL;
00038 return external_request_status_;
00039 }
00040
00041 bool artdaq::BoardReaderApp::do_start(art::RunID id, uint64_t timeout, uint64_t timestamp)
00042 {
00043 report_string_ = "";
00044 external_request_status_ = fragment_receiver_ptr_->start(id, timeout, timestamp);
00045 if (! external_request_status_)
00046 {
00047 report_string_ = "Error starting ";
00048 report_string_.append(name_ + " ");
00049 report_string_.append("for run number ");
00050 report_string_.append(boost::lexical_cast<std::string>(id.run()));
00051 report_string_.append(", timeout ");
00052 report_string_.append(boost::lexical_cast<std::string>(timeout));
00053 report_string_.append(", timestamp ");
00054 report_string_.append(boost::lexical_cast<std::string>(timestamp));
00055 report_string_.append(".");
00056 }
00057
00058 boost::thread::attributes attrs;
00059 attrs.set_stack_size(4096 * 2000);
00060 fragment_processing_thread_ = boost::thread(attrs, boost::bind(&BoardReaderCore::process_fragments, fragment_receiver_ptr_.get()));
00061
00062
00063
00064
00065
00066 return external_request_status_;
00067 }
00068
00069 bool artdaq::BoardReaderApp::do_stop(uint64_t timeout, uint64_t timestamp)
00070 {
00071 report_string_ = "";
00072 external_request_status_ = fragment_receiver_ptr_->stop(timeout, timestamp);
00073 if (! external_request_status_)
00074 {
00075 report_string_ = "Error stopping ";
00076 report_string_.append(name_ + ".");
00077 return false;
00078 }
00079
00080 int number_of_fragments_sent = fragment_receiver_ptr_->GetFragmentsProcessed();
00081 TLOG_DEBUG(name_ + "App") << "do_stop(uint64_t, uint64_t): "
00082 << "Number of fragments sent = " << number_of_fragments_sent
00083 << "." << TLOG_ENDL;
00084
00085 return external_request_status_;
00086 }
00087
00088 bool artdaq::BoardReaderApp::do_pause(uint64_t timeout, uint64_t timestamp)
00089 {
00090 report_string_ = "";
00091 external_request_status_ = fragment_receiver_ptr_->pause(timeout, timestamp);
00092 if (! external_request_status_)
00093 {
00094 report_string_ = "Error pausing ";
00095 report_string_.append(name_ + ".");
00096 }
00097
00098 int number_of_fragments_sent = fragment_receiver_ptr_->GetFragmentsProcessed();
00099 TLOG_DEBUG(name_ + "App") << "do_pause(uint64_t, uint64_t): "
00100 << "Number of fragments sent = " << number_of_fragments_sent
00101 << "." << TLOG_ENDL;
00102
00103 return external_request_status_;
00104 }
00105
00106 bool artdaq::BoardReaderApp::do_resume(uint64_t timeout, uint64_t timestamp)
00107 {
00108 report_string_ = "";
00109 external_request_status_ = fragment_receiver_ptr_->resume(timeout, timestamp);
00110 if (! external_request_status_)
00111 {
00112 report_string_ = "Error resuming ";
00113 report_string_.append(name_ + ".");
00114 }
00115
00116 boost::thread::attributes attrs;
00117 attrs.set_stack_size(4096 * 2000);
00118 fragment_processing_thread_ = boost::thread(attrs, boost::bind(&BoardReaderCore::process_fragments, fragment_receiver_ptr_.get()));
00119
00120
00121
00122
00123
00124 return external_request_status_;
00125 }
00126
00127 bool artdaq::BoardReaderApp::do_shutdown(uint64_t timeout)
00128 {
00129 report_string_ = "";
00130 external_request_status_ = fragment_receiver_ptr_->shutdown(timeout);
00131 if (! external_request_status_)
00132 {
00133 report_string_ = "Error shutting down ";
00134 report_string_.append(name_ + ".");
00135 }
00136 return external_request_status_;
00137 }
00138
00139 bool artdaq::BoardReaderApp::do_soft_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
00140 {
00141 report_string_ = "";
00142 external_request_status_ = fragment_receiver_ptr_->soft_initialize(pset, timeout, timestamp);
00143 if (! external_request_status_)
00144 {
00145 report_string_ = "Error soft-initializing ";
00146 report_string_.append(name_ + " ");
00147 report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
00148 }
00149 return external_request_status_;
00150 }
00151
00152 bool artdaq::BoardReaderApp::do_reinitialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
00153 {
00154 external_request_status_ = fragment_receiver_ptr_->reinitialize(pset, timeout, timestamp);
00155 if (! external_request_status_)
00156 {
00157 report_string_ = "Error reinitializing ";
00158 report_string_.append(name_ + " ");
00159 report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
00160 }
00161 return external_request_status_;
00162 }
00163
00164 void artdaq::BoardReaderApp::BootedEnter()
00165 {
00166 TLOG_DEBUG(name_ + "App") << "Booted state entry action called." << TLOG_ENDL;
00167
00168
00169
00170
00171
00172 fragment_receiver_ptr_.reset(nullptr);
00173 }
00174
00175 std::string artdaq::BoardReaderApp::report(std::string const& which) const
00176 {
00177 std::string resultString;
00178
00179
00180 if (which == "transition_status")
00181 {
00182 if (report_string_.length() > 0) { return report_string_; }
00183 else { return "Success"; }
00184 }
00185
00188
00189
00190
00191
00192
00193
00194
00195 if (fragment_receiver_ptr_.get() != 0)
00196 {
00197 resultString.append(fragment_receiver_ptr_->report(which));
00198 }
00199 else
00200 {
00201 resultString.append("This BoardReader has not yet been initialized and ");
00202 resultString.append("therefore can not provide reporting.");
00203 }
00204
00205 return resultString;
00206 }