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