00001 #include "artdaq/Application/DispatcherApp.hh"
00002 #include "artdaq/Application/DispatcherCore.hh"
00003 #include "artdaq-core/Utilities/ExceptionHandler.hh"
00004
00005 #include <iostream>
00006
00007 artdaq::DispatcherApp::DispatcherApp(int rank, std::string name) :
00008 rank_(rank)
00009 , name_(name)
00010 {}
00011
00012
00013
00014
00015
00016 bool artdaq::DispatcherApp::do_initialize(fhicl::ParameterSet const& pset, uint64_t, uint64_t)
00017 {
00018 report_string_ = "";
00019
00020
00021 if (Dispatcher_ptr_.get() == 0)
00022 {
00023 Dispatcher_ptr_.reset(new DispatcherCore(rank_, name_));
00024 }
00025 external_request_status_ = Dispatcher_ptr_->initialize(pset);
00026 if (!external_request_status_)
00027 {
00028 report_string_ = "Error initializing ";
00029 report_string_.append(name_ + " ");
00030 report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
00031 }
00032
00033 return external_request_status_;
00034 }
00035
00036 bool artdaq::DispatcherApp::do_start(art::RunID id, uint64_t, uint64_t)
00037 {
00038 report_string_ = "";
00039 external_request_status_ = Dispatcher_ptr_->start(id);
00040 if (!external_request_status_)
00041 {
00042 report_string_ = "Error starting ";
00043 report_string_.append(name_ + " ");
00044 report_string_.append("for run number ");
00045 report_string_.append(boost::lexical_cast<std::string>(id.run()));
00046 report_string_.append(".");
00047 }
00048
00049 return external_request_status_;
00050 }
00051
00052 bool artdaq::DispatcherApp::do_stop(uint64_t, uint64_t)
00053 {
00054 report_string_ = "";
00055 external_request_status_ = Dispatcher_ptr_->stop();
00056 if (!external_request_status_)
00057 {
00058 report_string_ = "Error stopping ";
00059 report_string_.append(name_ + ".");
00060 }
00061
00062 return external_request_status_;
00063 }
00064
00065 bool artdaq::DispatcherApp::do_pause(uint64_t, uint64_t)
00066 {
00067 report_string_ = "";
00068 external_request_status_ = Dispatcher_ptr_->pause();
00069 if (!external_request_status_)
00070 {
00071 report_string_ = "Error pausing ";
00072 report_string_.append(name_ + ".");
00073 }
00074 return external_request_status_;
00075 }
00076
00077 bool artdaq::DispatcherApp::do_resume(uint64_t, uint64_t)
00078 {
00079 report_string_ = "";
00080 external_request_status_ = Dispatcher_ptr_->resume();
00081 if (!external_request_status_)
00082 {
00083 report_string_ = "Error resuming ";
00084 report_string_.append(name_ + ".");
00085 }
00086
00087 return external_request_status_;
00088 }
00089
00090 bool artdaq::DispatcherApp::do_shutdown(uint64_t)
00091 {
00092 report_string_ = "";
00093 external_request_status_ = Dispatcher_ptr_->shutdown();
00094 if (!external_request_status_)
00095 {
00096 report_string_ = "Error shutting down ";
00097 report_string_.append(name_ + ".");
00098 }
00099
00100 return external_request_status_;
00101 }
00102
00103 bool artdaq::DispatcherApp::do_soft_initialize(fhicl::ParameterSet const&, uint64_t, uint64_t)
00104 {
00105 return true;
00106 }
00107
00108 bool artdaq::DispatcherApp::do_reinitialize(fhicl::ParameterSet const&, uint64_t, uint64_t)
00109 {
00110 return true;
00111 }
00112
00113 std::string artdaq::DispatcherApp::report(std::string const& which) const
00114 {
00115 std::string resultString;
00116
00117
00118 if (which == "transition_status")
00119 {
00120 if (report_string_.length() > 0) { return report_string_; }
00121 else { return "Success"; }
00122 }
00123
00126
00127
00128
00129
00130
00131
00132
00133 if (Dispatcher_ptr_.get() != 0)
00134 {
00135 resultString.append(Dispatcher_ptr_->report(which));
00136 }
00137 else
00138 {
00139 resultString.append("This Dispatcher has not yet been initialized and ");
00140 resultString.append("therefore can not provide reporting.");
00141 }
00142
00143 return resultString;
00144 }
00145
00146 std::string artdaq::DispatcherApp::register_monitor(fhicl::ParameterSet const& info)
00147 {
00148 TLOG_DEBUG(name_) << "DispatcherApp::register_monitor called with argument \"" << info.to_string() << "\"" << TLOG_ENDL;
00149
00150 if (Dispatcher_ptr_)
00151 {
00152 try
00153 {
00154 return Dispatcher_ptr_->register_monitor(info);
00155 }
00156 catch (...)
00157 {
00158 ExceptionHandler(ExceptionHandlerRethrow::no,
00159 "Error in call to DispatcherCore's register_monitor function");
00160
00161 return "Error in artdaq::DispatcherApp::register_monitor: an exception was thrown in the call to DispatcherCore::register_monitor, possibly due to a problem with the argument";
00162 }
00163 }
00164 else
00165 {
00166 return "Error in artdaq::DispatcherApp::register_monitor: DispatcherCore object wasn't initialized";
00167 }
00168 }
00169
00170
00171 std::string artdaq::DispatcherApp::unregister_monitor(std::string const& label)
00172 {
00173 TLOG_DEBUG(name_) << "DispatcherApp::unregister_monitor called with argument \"" << label << "\"" << TLOG_ENDL;
00174
00175 if (Dispatcher_ptr_)
00176 {
00177 try
00178 {
00179 return Dispatcher_ptr_->unregister_monitor(label);
00180 }
00181 catch (...)
00182 {
00183 ExceptionHandler(ExceptionHandlerRethrow::no,
00184 "Error in call to DispatcherCore's unregister_monitor function");
00185
00186 return "Error in artdaq::DispatcherApp::unregister_monitor: an exception was thrown in the call to DispatcherCore::unregister_monitor, possibly due to a problem with the argument";
00187 }
00188 }
00189 else
00190 {
00191 return "Error in artdaq::DispatcherApp::unregister_monitor: DispatcherCore object wasn't initialized";
00192 }
00193 }