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