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 try {
00060 fragment_processing_thread_ = boost::thread(attrs, boost::bind(&BoardReaderCore::process_fragments, fragment_receiver_ptr_.get()));
00061 }
00062 catch (const boost::exception& e)
00063 {
00064 TLOG(TLVL_ERROR) << "Caught boost::exception starting Fragment Processing thread: " << boost::diagnostic_information(e) << ", errno=" << errno;
00065 std::cerr << "Caught boost::exception starting Fragment Processing thread: " << boost::diagnostic_information(e) << ", errno=" << errno << std::endl;
00066 exit(5);
00067 }
00068
00069
00070
00071
00072
00073 return external_request_status_;
00074 }
00075
00076 bool artdaq::BoardReaderApp::do_stop(uint64_t timeout, uint64_t timestamp)
00077 {
00078 report_string_ = "";
00079 external_request_status_ = fragment_receiver_ptr_->stop(timeout, timestamp);
00080 if (!external_request_status_)
00081 {
00082 report_string_ = "Error stopping ";
00083 report_string_.append(app_name + ".");
00084 return false;
00085 }
00086 if (fragment_processing_thread_.joinable())
00087 {
00088 TLOG(TLVL_DEBUG) << "Joining fragment processing thread";
00089 fragment_processing_thread_.join();
00090 }
00091
00092 TLOG(TLVL_DEBUG) << "BoardReader Stopped. Getting run statistics";
00093 int number_of_fragments_sent = -1;
00094 if(fragment_receiver_ptr_) number_of_fragments_sent = fragment_receiver_ptr_->GetFragmentsProcessed();
00095 TLOG(TLVL_DEBUG) << "do_stop(uint64_t, uint64_t): "
00096 << "Number of fragments sent = " << number_of_fragments_sent
00097 << ".";
00098
00099 return external_request_status_;
00100 }
00101
00102 bool artdaq::BoardReaderApp::do_pause(uint64_t timeout, uint64_t timestamp)
00103 {
00104 report_string_ = "";
00105 external_request_status_ = fragment_receiver_ptr_->pause(timeout, timestamp);
00106 if (!external_request_status_)
00107 {
00108 report_string_ = "Error pausing ";
00109 report_string_.append(app_name + ".");
00110 }
00111
00112 if(fragment_processing_thread_.joinable()) fragment_processing_thread_.join();
00113 int number_of_fragments_sent = fragment_receiver_ptr_->GetFragmentsProcessed();
00114 TLOG(TLVL_DEBUG) << "do_pause(uint64_t, uint64_t): "
00115 << "Number of fragments sent = " << number_of_fragments_sent
00116 << ".";
00117
00118 return external_request_status_;
00119 }
00120
00121 bool artdaq::BoardReaderApp::do_resume(uint64_t timeout, uint64_t timestamp)
00122 {
00123 report_string_ = "";
00124 external_request_status_ = fragment_receiver_ptr_->resume(timeout, timestamp);
00125 if (!external_request_status_)
00126 {
00127 report_string_ = "Error resuming ";
00128 report_string_.append(app_name + ".");
00129 }
00130
00131 boost::thread::attributes attrs;
00132 attrs.set_stack_size(4096 * 2000);
00133 fragment_processing_thread_ = boost::thread(attrs, boost::bind(&BoardReaderCore::process_fragments, fragment_receiver_ptr_.get()));
00134
00135
00136
00137
00138
00139 return external_request_status_;
00140 }
00141
00142 bool artdaq::BoardReaderApp::do_shutdown(uint64_t timeout)
00143 {
00144 report_string_ = "";
00145 external_request_status_ = fragment_receiver_ptr_->shutdown(timeout);
00146
00147
00148 if (fragment_processing_thread_.joinable()) fragment_processing_thread_.join();
00149 if (!external_request_status_)
00150 {
00151 report_string_ = "Error shutting down ";
00152 report_string_.append(app_name + ".");
00153 }
00154 return external_request_status_;
00155 }
00156
00157 bool artdaq::BoardReaderApp::do_soft_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
00158 {
00159 report_string_ = "";
00160 external_request_status_ = fragment_receiver_ptr_->soft_initialize(pset, timeout, timestamp);
00161 if (!external_request_status_)
00162 {
00163 report_string_ = "Error soft-initializing ";
00164 report_string_.append(app_name + " ");
00165 report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
00166 }
00167 return external_request_status_;
00168 }
00169
00170 bool artdaq::BoardReaderApp::do_reinitialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
00171 {
00172 external_request_status_ = fragment_receiver_ptr_->reinitialize(pset, timeout, timestamp);
00173 if (!external_request_status_)
00174 {
00175 report_string_ = "Error reinitializing ";
00176 report_string_.append(app_name + " ");
00177 report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
00178 }
00179 return external_request_status_;
00180 }
00181
00182 void artdaq::BoardReaderApp::BootedEnter()
00183 {
00184 TLOG(TLVL_DEBUG) << "Booted state entry action called.";
00185
00186
00187
00188
00189
00190 fragment_receiver_ptr_.reset(nullptr);
00191 }
00192
00193 bool artdaq::BoardReaderApp::do_meta_command(std::string const& command, std::string const& arg)
00194 {
00195 external_request_status_ = fragment_receiver_ptr_->metaCommand(command, arg);
00196 if (!external_request_status_)
00197 {
00198 report_string_ = "Error running meta-command on ";
00199 report_string_.append(app_name + " ");
00200 report_string_.append("with command = \"" + command + "\", arg = \"" + arg + "\".");
00201 }
00202 return external_request_status_;
00203 }
00204
00205 std::string artdaq::BoardReaderApp::report(std::string const& which) const
00206 {
00207 std::string resultString;
00208
00209
00210 if (which == "transition_status")
00211 {
00212 if (report_string_.length() > 0) { return report_string_; }
00213 else { return "Success"; }
00214 }
00215
00218
00219
00220
00221
00222
00223
00224
00225 if (fragment_receiver_ptr_.get() != 0)
00226 {
00227 resultString.append(fragment_receiver_ptr_->report(which));
00228 }
00229 else
00230 {
00231 resultString.append("This BoardReader has not yet been initialized and ");
00232 resultString.append("therefore can not provide reporting.");
00233 }
00234
00235 return resultString;
00236 }