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