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