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