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 boost::thread::attributes attrs;
00056 attrs.set_stack_size(4096 * 2000);
00057 try {
00058 routing_master_thread_ = boost::thread(attrs, boost::bind(&RoutingMasterCore::process_event_table, routing_master_ptr_.get()));
00059 }
00060 catch (const boost::exception& e)
00061 {
00062 TLOG(TLVL_ERROR) << "Caught boost::exception starting RoutingMasterCore thread: " << boost::diagnostic_information(e) << ", errno=" << errno;
00063 std::cerr << "Caught boost::exception starting RoutingMasterCore thread: " << boost::diagnostic_information(e) << ", errno=" << errno << std::endl;
00064 exit(5);
00065 }
00066
00067 return external_request_status_;
00068 }
00069
00070 bool artdaq::RoutingMasterApp::do_stop(uint64_t timeout, uint64_t timestamp)
00071 {
00072 report_string_ = "";
00073 external_request_status_ = routing_master_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 if (routing_master_thread_.joinable()) routing_master_thread_.join();
00082
00083 TLOG_DEBUG(app_name + "App") << "do_stop(uint64_t, uint64_t): "
00084 << "Number of table entries sent = " << routing_master_ptr_->get_update_count()
00085 << ".";
00086
00087 return external_request_status_;
00088 }
00089
00090 bool artdaq::RoutingMasterApp::do_pause(uint64_t timeout, uint64_t timestamp)
00091 {
00092 report_string_ = "";
00093 external_request_status_ = routing_master_ptr_->pause(timeout, timestamp);
00094 if (!external_request_status_)
00095 {
00096 report_string_ = "Error pausing ";
00097 report_string_.append(app_name + ".");
00098 }
00099 if (routing_master_thread_.joinable()) routing_master_thread_.join();
00100
00101 TLOG_DEBUG(app_name + "App") << "do_pause(uint64_t, uint64_t): "
00102 << "Number of table entries sent = " << routing_master_ptr_->get_update_count()
00103 << ".";
00104
00105
00106 return external_request_status_;
00107 }
00108
00109 bool artdaq::RoutingMasterApp::do_resume(uint64_t timeout, uint64_t timestamp)
00110 {
00111 report_string_ = "";
00112 external_request_status_ = routing_master_ptr_->resume(timeout, timestamp);
00113 if (!external_request_status_)
00114 {
00115 report_string_ = "Error resuming ";
00116 report_string_.append(app_name + ".");
00117 }
00118
00119 boost::thread::attributes attrs;
00120 attrs.set_stack_size(4096 * 2000);
00121
00122 TLOG(TLVL_INFO) << "Starting Routing Master thread";
00123 try {
00124 routing_master_thread_ = boost::thread(attrs, boost::bind(&RoutingMasterCore::process_event_table, routing_master_ptr_.get()));
00125 }
00126 catch (boost::exception const& e)
00127 {
00128 std::cerr << "Exception encountered starting Routing Master thread: " << boost::diagnostic_information(e) << ", errno=" << errno << std::endl;
00129 exit(3);
00130 }
00131 TLOG(TLVL_INFO) << "Started Routing Master thread";
00132
00133 return external_request_status_;
00134 }
00135
00136 bool artdaq::RoutingMasterApp::do_shutdown(uint64_t timeout)
00137 {
00138 report_string_ = "";
00139 external_request_status_ = routing_master_ptr_->shutdown(timeout);
00140 if (!external_request_status_)
00141 {
00142 report_string_ = "Error shutting down ";
00143 report_string_.append(app_name + ".");
00144 }
00145 return external_request_status_;
00146 }
00147
00148 bool artdaq::RoutingMasterApp::do_soft_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
00149 {
00150 report_string_ = "";
00151 external_request_status_ = routing_master_ptr_->soft_initialize(pset, timeout, timestamp);
00152 if (!external_request_status_)
00153 {
00154 report_string_ = "Error soft-initializing ";
00155 report_string_.append(app_name + " ");
00156 report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
00157 }
00158 return external_request_status_;
00159 }
00160
00161 bool artdaq::RoutingMasterApp::do_reinitialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
00162 {
00163 external_request_status_ = routing_master_ptr_->reinitialize(pset, timeout, timestamp);
00164 if (!external_request_status_)
00165 {
00166 report_string_ = "Error reinitializing ";
00167 report_string_.append(app_name + " ");
00168 report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
00169 }
00170 return external_request_status_;
00171 }
00172
00173 void artdaq::RoutingMasterApp::BootedEnter()
00174 {
00175 TLOG_DEBUG(app_name + "App") << "Booted state entry action called.";
00176
00177
00178
00179
00180
00181 routing_master_ptr_.reset(nullptr);
00182 }
00183
00184 std::string artdaq::RoutingMasterApp::report(std::string const& which) const
00185 {
00186 std::string resultString;
00187
00188
00189 if (which == "transition_status")
00190 {
00191 if (report_string_.length() > 0) { return report_string_; }
00192 else { return "Success"; }
00193 }
00194
00197
00198
00199
00200
00201
00202
00203
00204 if (routing_master_ptr_.get() != 0)
00205 {
00206 resultString.append(routing_master_ptr_->report(which));
00207 }
00208 else
00209 {
00210 resultString.append("This RoutingMaster has not yet been initialized and ");
00211 resultString.append("therefore can not provide reporting.");
00212 }
00213
00214 return resultString;
00215 }