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