artdaq  v3_00_03
EventBuilderApp.cc
1 #include "artdaq/Application/EventBuilderApp.hh"
2 
3 artdaq::EventBuilderApp::EventBuilderApp(int rank, std::string name)
4 {
5  my_rank = rank;
6  app_name = name;
7 }
8 
9 // *******************************************************************
10 // *** The following methods implement the state machine operations.
11 // *******************************************************************
12 
13 bool artdaq::EventBuilderApp::do_initialize(fhicl::ParameterSet const& pset, uint64_t, uint64_t)
14 {
15  report_string_ = "";
16  external_request_status_ = true;
17 
18  // in the following block, we first destroy the existing EventBuilder
19  // instance, then create a new one. Doing it in one step does not
20  // produce the desired result since that creates a new instance and
21  // then deletes the old one, and we need the opposite order.
22  //event_builder_ptr_.reset(nullptr);
23  if (event_builder_ptr_.get() == 0)
24  {
25  event_builder_ptr_.reset(new EventBuilderCore());
26  external_request_status_ = event_builder_ptr_->initialize(pset);
27  }
28  if (! external_request_status_)
29  {
30  report_string_ = "Error initializing an EventBuilderCore named";
31  report_string_.append(app_name + " with ");
32  report_string_.append("ParameterSet = \"" + pset.to_string() + "\".");
33  }
34 
35  return external_request_status_;
36 }
37 
38 bool artdaq::EventBuilderApp::do_start(art::RunID id, uint64_t, uint64_t)
39 {
40  report_string_ = "";
41  external_request_status_ = event_builder_ptr_->start(id);
42  if (! external_request_status_)
43  {
44  report_string_ = "Error starting ";
45  report_string_.append(app_name + " for run ");
46  report_string_.append("number ");
47  report_string_.append(boost::lexical_cast<std::string>(id.run()));
48  report_string_.append(".");
49  }
50 
51  return external_request_status_;
52 }
53 
54 bool artdaq::EventBuilderApp::do_stop(uint64_t, uint64_t)
55 {
56  report_string_ = "";
57  external_request_status_ = event_builder_ptr_->stop();
58  if (! external_request_status_)
59  {
60  report_string_ = "Error stopping ";
61  report_string_.append(app_name + ".");
62  }
63  return external_request_status_;
64 }
65 
66 bool artdaq::EventBuilderApp::do_pause(uint64_t, uint64_t)
67 {
68  report_string_ = "";
69  external_request_status_ = event_builder_ptr_->pause();
70  if (! external_request_status_)
71  {
72  report_string_ = "Error pausing ";
73  report_string_.append(app_name + ".");
74  }
75 
76  return external_request_status_;
77 }
78 
79 bool artdaq::EventBuilderApp::do_resume(uint64_t, uint64_t)
80 {
81  report_string_ = "";
82  external_request_status_ = event_builder_ptr_->resume();
83  if (! external_request_status_)
84  {
85  report_string_ = "Error resuming ";
86  report_string_.append(app_name + ".");
87  }
88 
89  return external_request_status_;
90 }
91 
93 {
94  report_string_ = "";
95  external_request_status_ = event_builder_ptr_->shutdown();
96  if (! external_request_status_)
97  {
98  report_string_ = "Error shutting down ";
99  report_string_.append(app_name + ".");
100  }
101  return external_request_status_;
102 }
103 
104 bool artdaq::EventBuilderApp::do_soft_initialize(fhicl::ParameterSet const& pset, uint64_t, uint64_t)
105 {
106  report_string_ = "";
107  external_request_status_ = event_builder_ptr_->soft_initialize(pset);
108  if (! external_request_status_)
109  {
110  report_string_ = "Error soft-initializing ";
111  report_string_.append(app_name + " with ");
112  report_string_.append("ParameterSet = \"" + pset.to_string() + "\".");
113  }
114  return external_request_status_;
115 }
116 
117 bool artdaq::EventBuilderApp::do_reinitialize(fhicl::ParameterSet const& pset, uint64_t, uint64_t)
118 {
119  report_string_ = "";
120  external_request_status_ = event_builder_ptr_->reinitialize(pset);
121  if (! external_request_status_)
122  {
123  report_string_ = "Error reinitializing ";
124  report_string_.append(app_name + " with ");
125  report_string_.append("ParameterSet = \"" + pset.to_string() + "\".");
126  }
127  return external_request_status_;
128 }
129 
131 {
132  TLOG_DEBUG(app_name + "App") << "Booted state entry action called." << TLOG_ENDL;
133 
134  // the destruction of any existing EventBuilderCore has to happen in the
135  // Booted Entry action rather than the Initialized Exit action because the
136  // Initialized Exit action is only called after the "init" transition guard
137  // condition is executed.
138  //event_builder_ptr_.reset(nullptr);
139 }
140 
141 std::string artdaq::EventBuilderApp::report(std::string const& which) const
142 {
143  std::string resultString;
144 
145  // if all that is requested is the latest state change result, return it
146  if (which == "transition_status")
147  {
148  if (report_string_.length() > 0) { return report_string_; }
149  else { return "Success"; }
150  }
151 
154  //if (report_string_.length() > 0) {
155  // resultString.append("*** Overall status message:\r\n");
156  // resultString.append(report_string_ + "\r\n");
157  // resultString.append("*** Requested report response:\r\n");
158  //}
159 
160  // pass the request to the EventBuilderCore instance, if it's available
161  if (event_builder_ptr_.get() != nullptr)
162  {
163  resultString.append(event_builder_ptr_->report(which));
164  }
165  else
166  {
167  resultString.append("This EventBuilder has not yet been initialized and ");
168  resultString.append("therefore can not provide reporting.");
169  }
170 
171  return resultString;
172 }
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 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.
EventBuilderApp(int rank, std::string name)
EventBuilderApp Constructor.
bool do_initialize(fhicl::ParameterSet const &pset, uint64_t, uint64_t) override
Initialize the EventBuilderCore.
bool do_start(art::RunID id, uint64_t, uint64_t) override
Start the EventBuilderCore.
EventBuilderCore implements the state machine for the EventBuilder artdaq application. EventBuilderCore receives Fragment objects from the DataReceiverManager, and sends them to the EventStore.
bool do_stop(uint64_t, uint64_t) override
Stop the EventBuilderCore.