artdaq  v3_00_01
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  return external_request_status_;
50 }
51 
52 bool artdaq::EventBuilderApp::do_stop(uint64_t, uint64_t)
53 {
54  report_string_ = "";
55  external_request_status_ = event_builder_ptr_->stop();
56  if (! external_request_status_)
57  {
58  report_string_ = "Error stopping ";
59  report_string_.append(name_ + ".");
60  }
61  return external_request_status_;
62 }
63 
64 bool artdaq::EventBuilderApp::do_pause(uint64_t, uint64_t)
65 {
66  report_string_ = "";
67  external_request_status_ = event_builder_ptr_->pause();
68  if (! external_request_status_)
69  {
70  report_string_ = "Error pausing ";
71  report_string_.append(name_ + ".");
72  }
73 
74  return external_request_status_;
75 }
76 
77 bool artdaq::EventBuilderApp::do_resume(uint64_t, uint64_t)
78 {
79  report_string_ = "";
80  external_request_status_ = event_builder_ptr_->resume();
81  if (! external_request_status_)
82  {
83  report_string_ = "Error resuming ";
84  report_string_.append(name_ + ".");
85  }
86 
87  return external_request_status_;
88 }
89 
91 {
92  report_string_ = "";
93  external_request_status_ = event_builder_ptr_->shutdown();
94  if (! external_request_status_)
95  {
96  report_string_ = "Error shutting down ";
97  report_string_.append(name_ + ".");
98  }
99  return external_request_status_;
100 }
101 
102 bool artdaq::EventBuilderApp::do_soft_initialize(fhicl::ParameterSet const& pset, uint64_t, uint64_t)
103 {
104  report_string_ = "";
105  external_request_status_ = event_builder_ptr_->soft_initialize(pset);
106  if (! external_request_status_)
107  {
108  report_string_ = "Error soft-initializing ";
109  report_string_.append(name_ + " with ");
110  report_string_.append("ParameterSet = \"" + pset.to_string() + "\".");
111  }
112  return external_request_status_;
113 }
114 
115 bool artdaq::EventBuilderApp::do_reinitialize(fhicl::ParameterSet const& pset, uint64_t, uint64_t)
116 {
117  report_string_ = "";
118  external_request_status_ = event_builder_ptr_->reinitialize(pset);
119  if (! external_request_status_)
120  {
121  report_string_ = "Error reinitializing ";
122  report_string_.append(name_ + " with ");
123  report_string_.append("ParameterSet = \"" + pset.to_string() + "\".");
124  }
125  return external_request_status_;
126 }
127 
129 {
130  TLOG_DEBUG(name_ + "App") << "Booted state entry action called." << TLOG_ENDL;
131 
132  // the destruction of any existing EventBuilderCore has to happen in the
133  // Booted Entry action rather than the Initialized Exit action because the
134  // Initialized Exit action is only called after the "init" transition guard
135  // condition is executed.
136  //event_builder_ptr_.reset(nullptr);
137 }
138 
139 std::string artdaq::EventBuilderApp::report(std::string const& which) const
140 {
141  std::string resultString;
142 
143  // if all that is requested is the latest state change result, return it
144  if (which == "transition_status")
145  {
146  if (report_string_.length() > 0) { return report_string_; }
147  else { return "Success"; }
148  }
149 
152  //if (report_string_.length() > 0) {
153  // resultString.append("*** Overall status message:\r\n");
154  // resultString.append(report_string_ + "\r\n");
155  // resultString.append("*** Requested report response:\r\n");
156  //}
157 
158  // pass the request to the EventBuilderCore instance, if it's available
159  if (event_builder_ptr_.get() != nullptr)
160  {
161  resultString.append(event_builder_ptr_->report(which));
162  }
163  else
164  {
165  resultString.append("This EventBuilder has not yet been initialized and ");
166  resultString.append("therefore can not provide reporting.");
167  }
168 
169  return resultString;
170 }
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.