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