artdaq  v3_12_02
EventBuilderApp.cc
1 #include "TRACE/tracemf.h"
2 #include "artdaq/DAQdata/Globals.hh" // include these 2 first -
3 #define TRACE_NAME (app_name + "_DataLoggerApp").c_str()
4 
5 #include "artdaq/Application/EventBuilderApp.hh"
6 
7 #include "fhiclcpp/ParameterSet.h"
8 
9 #include <boost/lexical_cast.hpp>
10 
11 #include <iomanip>
12 #include <memory>
13 
15 
16 // *******************************************************************
17 // *** The following methods implement the state machine operations.
18 // *******************************************************************
19 
20 bool artdaq::EventBuilderApp::do_initialize(fhicl::ParameterSet const& pset, uint64_t /*unused*/, uint64_t /*unused*/)
21 {
22  report_string_ = "";
24 
25  // in the following block, we first destroy the existing EventBuilder
26  // instance, then create a new one. Doing it in one step does not
27  // produce the desired result since that creates a new instance and
28  // then deletes the old one, and we need the opposite order.
29  // event_builder_ptr_.reset(nullptr);
30  if (event_builder_ptr_ == nullptr)
31  {
32  event_builder_ptr_ = std::make_unique<EventBuilderCore>();
33  external_request_status_ = event_builder_ptr_->initialize(pset);
34  }
36  {
37  report_string_ = "Error initializing an EventBuilderCore named";
38  report_string_.append(app_name + " with ");
39  report_string_.append("ParameterSet = \"" + pset.to_string() + "\".");
40  }
41 
43 }
44 
45 bool artdaq::EventBuilderApp::do_start(art::RunID id, uint64_t /*unused*/, uint64_t /*unused*/)
46 {
47  report_string_ = "";
48  external_request_status_ = event_builder_ptr_->start(id);
49  if (!external_request_status_)
50  {
51  report_string_ = "Error starting ";
52  report_string_.append(app_name + " for run ");
53  report_string_.append("number ");
54  report_string_.append(boost::lexical_cast<std::string>(id.run()));
55  report_string_.append(".");
56  }
57 
58  return external_request_status_;
59 }
60 
61 bool artdaq::EventBuilderApp::do_stop(uint64_t /*unused*/, uint64_t /*unused*/)
62 {
63  report_string_ = "";
64  external_request_status_ = event_builder_ptr_->stop();
65  if (!external_request_status_)
66  {
67  report_string_ = "Error stopping ";
68  report_string_.append(app_name + ".");
69  }
70  return external_request_status_;
71 }
72 
73 bool artdaq::EventBuilderApp::do_pause(uint64_t /*unused*/, uint64_t /*unused*/)
74 {
75  report_string_ = "";
76  external_request_status_ = event_builder_ptr_->pause();
77  if (!external_request_status_)
78  {
79  report_string_ = "Error pausing ";
80  report_string_.append(app_name + ".");
81  }
82 
83  return external_request_status_;
84 }
85 
86 bool artdaq::EventBuilderApp::do_resume(uint64_t /*unused*/, uint64_t /*unused*/)
87 {
88  report_string_ = "";
89  external_request_status_ = event_builder_ptr_->resume();
90  if (!external_request_status_)
91  {
92  report_string_ = "Error resuming ";
93  report_string_.append(app_name + ".");
94  }
95 
96  return external_request_status_;
97 }
98 
99 bool artdaq::EventBuilderApp::do_shutdown(uint64_t /*unused*/)
100 {
101  report_string_ = "";
102  external_request_status_ = event_builder_ptr_->shutdown();
103  if (!external_request_status_)
104  {
105  report_string_ = "Error shutting down ";
106  report_string_.append(app_name + ".");
107  }
108  return external_request_status_;
109 }
110 
111 bool artdaq::EventBuilderApp::do_soft_initialize(fhicl::ParameterSet const& pset, uint64_t /*unused*/, uint64_t /*unused*/)
112 {
113  report_string_ = "";
114  external_request_status_ = event_builder_ptr_->soft_initialize(pset);
115  if (!external_request_status_)
116  {
117  report_string_ = "Error soft-initializing ";
118  report_string_.append(app_name + " with ");
119  report_string_.append("ParameterSet = \"" + pset.to_string() + "\".");
120  }
121  return external_request_status_;
122 }
123 
124 bool artdaq::EventBuilderApp::do_reinitialize(fhicl::ParameterSet const& pset, uint64_t /*unused*/, uint64_t /*unused*/)
125 {
126  report_string_ = "";
127  external_request_status_ = event_builder_ptr_->reinitialize(pset);
128  if (!external_request_status_)
129  {
130  report_string_ = "Error reinitializing ";
131  report_string_.append(app_name + " with ");
132  report_string_.append("ParameterSet = \"" + pset.to_string() + "\".");
133  }
134  return external_request_status_;
135 }
136 
137 bool artdaq::EventBuilderApp::do_rollover_subrun(uint64_t boundary, uint32_t subrun)
138 {
139  TLOG(TLVL_DEBUG + 32) << "do_rollover_subrun BEGIN boundary=" << boundary << ", subrun=" << subrun;
140  report_string_ = "";
141  external_request_status_ = event_builder_ptr_->rollover_subrun(boundary, subrun);
142  if (!external_request_status_)
143  {
144  report_string_ = "Error rolling over subrun in ";
145  report_string_.append(app_name + "!");
146  }
147  TLOG(TLVL_DEBUG + 32) << "do_rollover_subrun END sts=" << std::boolalpha << external_request_status_;
148  return external_request_status_;
149 }
150 
152 {
153  TLOG(TLVL_DEBUG + 32, app_name + "App") << "Booted state entry action called.";
154 
155  // the destruction of any existing EventBuilderCore has to happen in the
156  // Booted Entry action rather than the Initialized Exit action because the
157  // Initialized Exit action is only called after the "init" transition guard
158  // condition is executed.
159  // event_builder_ptr_.reset(nullptr);
160 }
161 
162 std::string artdaq::EventBuilderApp::report(std::string const& which) const
163 {
164  std::string resultString;
165 
166  // if all that is requested is the latest state change result, return it
167  if (which == "transition_status")
168  {
169  if (report_string_.length() > 0) { return report_string_; }
170 
171  return "Success";
172  }
173 
176  // if (report_string_.length() > 0) {
177  // resultString.append("*** Overall status message:\r\n");
178  // resultString.append(report_string_ + "\r\n");
179  // resultString.append("*** Requested report response:\r\n");
180  // }
181 
182  // pass the request to the EventBuilderCore instance, if it's available
183  if (event_builder_ptr_ != nullptr)
184  {
185  resultString.append(event_builder_ptr_->report(which));
186  }
187  else
188  {
189  resultString.append("This EventBuilder has not yet been initialized and ");
190  resultString.append("therefore can not provide reporting.");
191  }
192 
193  return resultString;
194 }
195 
196 bool artdaq::EventBuilderApp::do_add_config_archive_entry(std::string const& key, std::string const& value)
197 {
198  report_string_ = "";
199  external_request_status_ = event_builder_ptr_->add_config_archive_entry(key, value);
200  if (!external_request_status_)
201  {
202  report_string_ = "Error adding config entry with key ";
203  report_string_.append(key + " and value \"");
204  report_string_.append(value + "\" in");
205  report_string_.append(app_name + ".");
206  }
207 
208  return external_request_status_;
209 }
210 
212 {
213  report_string_ = "";
214  external_request_status_ = event_builder_ptr_->clear_config_archive();
215  if (!external_request_status_)
216  {
217  report_string_ = "Error clearing the configuration archive in ";
218  report_string_.append(app_name + ".");
219  }
220 
221  return external_request_status_;
222 }
bool do_resume(uint64_t, uint64_t) override
Resume the EventBuilderCore.
void BootedEnter() override
Action taken upon entering the &quot;Booted&quot; state.
std::string report(std::string const &which) const override
If which is &quot;transition_status&quot;, report the status of the last transition. Otherwise pass through to ...
bool do_reinitialize(fhicl::ParameterSet const &pset, uint64_t, uint64_t) override
Reinitialize the EventBuilderCore.
bool do_shutdown(uint64_t) override
Shutdown the EventBuilderCore.
bool external_request_status_
Whether the last command succeeded.
Definition: Commandable.hh:314
bool do_pause(uint64_t, uint64_t) override
Pause the EventBuilderCore.
bool do_soft_initialize(fhicl::ParameterSet const &pset, uint64_t, uint64_t) override
Soft-Initialize the EventBuilderCore.
bool do_add_config_archive_entry(std::string const &, std::string const &) override
Add the specified configuration archive entry to the EventBuilderCore.
EventBuilderApp()
EventBuilderApp Constructor.
bool do_initialize(fhicl::ParameterSet const &pset, uint64_t, uint64_t) override
Initialize the EventBuilderCore.
std::string report_string_
Status information about the last command.
Definition: Commandable.hh:315
bool do_clear_config_archive() override
Clear the configuration archive list in the EventBuilderCore.
bool do_start(art::RunID id, uint64_t, uint64_t) override
Start the EventBuilderCore.
bool do_rollover_subrun(uint64_t boundary, uint32_t subrunNum) override
Rollover the subrun after the given event.
bool do_stop(uint64_t, uint64_t) override
Stop the EventBuilderCore.