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