artdaq  v2_03_00
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
AggregatorApp.cc
1 #include "artdaq/Application/AggregatorApp.hh"
2 #include "artdaq/Application/AggregatorCore.hh"
3 #include "artdaq-core/Utilities/ExceptionHandler.hh"
4 
5 #include <iostream>
6 
7 artdaq::AggregatorApp::AggregatorApp(int rank, std::string name) :
8  rank_(rank)
9  , name_(name)
10 {}
11 
12 // *******************************************************************
13 // *** The following methods implement the state machine operations.
14 // *******************************************************************
15 
16 bool artdaq::AggregatorApp::do_initialize(fhicl::ParameterSet const& pset, uint64_t, uint64_t)
17 {
18  report_string_ = "";
19 
20  //aggregator_ptr_.reset(nullptr);
21  if (aggregator_ptr_.get() == 0)
22  {
23  aggregator_ptr_.reset(new AggregatorCore(rank_, name_));
24  }
25  external_request_status_ = aggregator_ptr_->initialize(pset);
26  if (!external_request_status_)
27  {
28  report_string_ = "Error initializing ";
29  report_string_.append(name_ + " ");
30  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
31  }
32 
33  return external_request_status_;
34 }
35 
36 bool artdaq::AggregatorApp::do_start(art::RunID id, uint64_t, uint64_t)
37 {
38  report_string_ = "";
39  external_request_status_ = aggregator_ptr_->start(id);
40  if (!external_request_status_)
41  {
42  report_string_ = "Error starting ";
43  report_string_.append(name_ + " ");
44  report_string_.append("for run number ");
45  report_string_.append(boost::lexical_cast<std::string>(id.run()));
46  report_string_.append(".");
47  }
48 
49  aggregator_future_ =
50  std::async(std::launch::async, &AggregatorCore::process_fragments,
51  aggregator_ptr_.get());
52 
53  return external_request_status_;
54 }
55 
56 bool artdaq::AggregatorApp::do_stop(uint64_t, uint64_t)
57 {
58  report_string_ = "";
59  external_request_status_ = aggregator_ptr_->stop();
60  if (!external_request_status_)
61  {
62  report_string_ = "Error stopping ";
63  report_string_.append(name_ + ".");
64  }
65 
66  if (aggregator_future_.valid())
67  {
68  aggregator_future_.get();
69  }
70  return external_request_status_;
71 }
72 
73 bool artdaq::AggregatorApp::do_pause(uint64_t, uint64_t)
74 {
75  report_string_ = "";
76  external_request_status_ = aggregator_ptr_->pause();
77  if (!external_request_status_)
78  {
79  report_string_ = "Error pausing ";
80  report_string_.append(name_ + ".");
81  }
82 
83  if (aggregator_future_.valid())
84  {
85  aggregator_future_.get();
86  }
87  return external_request_status_;
88 }
89 
90 bool artdaq::AggregatorApp::do_resume(uint64_t, uint64_t)
91 {
92  report_string_ = "";
93  external_request_status_ = aggregator_ptr_->resume();
94  if (!external_request_status_)
95  {
96  report_string_ = "Error resuming ";
97  report_string_.append(name_ + ".");
98  }
99 
100  aggregator_future_ =
101  std::async(std::launch::async, &AggregatorCore::process_fragments,
102  aggregator_ptr_.get());
103 
104  return external_request_status_;
105 }
106 
108 {
109  report_string_ = "";
110  external_request_status_ = aggregator_ptr_->shutdown();
111  if (!external_request_status_)
112  {
113  report_string_ = "Error shutting down ";
114  report_string_.append(name_ + ".");
115  }
116 
117  return external_request_status_;
118 }
119 
120 bool artdaq::AggregatorApp::do_soft_initialize(fhicl::ParameterSet const&, uint64_t, uint64_t)
121 {
122  return true;
123 }
124 
125 bool artdaq::AggregatorApp::do_reinitialize(fhicl::ParameterSet const&, uint64_t, uint64_t)
126 {
127  return true;
128 }
129 
130 std::string artdaq::AggregatorApp::report(std::string const& which) const
131 {
132  std::string resultString;
133 
134  // if all that is requested is the latest state change result, return it
135  if (which == "transition_status")
136  {
137  if (report_string_.length() > 0) { return report_string_; }
138  else { return "Success"; }
139  }
140 
143  //if (report_string_.length() > 0) {
144  // resultString.append("*** Overall status message:\r\n");
145  // resultString.append(report_string_ + "\r\n");
146  // resultString.append("*** Requested report response:\r\n");
147  //}
148 
149  // pass the request to the AggregatorCore instance, if it's available
150  if (aggregator_ptr_.get() != 0)
151  {
152  resultString.append(aggregator_ptr_->report(which));
153  }
154  else
155  {
156  resultString.append("This Aggregator has not yet been initialized and ");
157  resultString.append("therefore can not provide reporting.");
158  }
159 
160  return resultString;
161 }
162 
163 std::string artdaq::AggregatorApp::register_monitor(fhicl::ParameterSet const& info)
164 {
165  TLOG_DEBUG(name_) << "AggregatorApp::register_monitor called with argument \"" << info.to_string() << "\"" << TLOG_ENDL;
166 
167  if (aggregator_ptr_)
168  {
169  try
170  {
171  return aggregator_ptr_->register_monitor(info);
172  }
173  catch (...)
174  {
175  ExceptionHandler(ExceptionHandlerRethrow::no,
176  "Error in call to AggregatorCore's register_monitor function");
177 
178  return "Error in artdaq::AggregatorApp::register_monitor: an exception was thrown in the call to AggregatorCore::register_monitor, possibly due to a problem with the argument";
179  }
180  }
181  else
182  {
183  return "Error in artdaq::AggregatorApp::register_monitor: AggregatorCore object wasn't initialized";
184  }
185 }
186 
187 
188 std::string artdaq::AggregatorApp::unregister_monitor(std::string const& label)
189 {
190  TLOG_DEBUG(name_) << "AggregatorApp::unregister_monitor called with argument \"" << label << "\"" << TLOG_ENDL;
191 
192  if (aggregator_ptr_)
193  {
194  try
195  {
196  return aggregator_ptr_->unregister_monitor(label);
197  }
198  catch (...)
199  {
200  ExceptionHandler(ExceptionHandlerRethrow::no,
201  "Error in call to AggregatorCore's unregister_monitor function");
202 
203  return "Error in artdaq::AggregatorApp::unregister_monitor: an exception was thrown in the call to AggregatorCore::unregister_monitor, possibly due to a problem with the argument";
204  }
205  }
206  else
207  {
208  return "Error in artdaq::AggregatorApp::unregister_monitor: AggregatorCore object wasn't initialized";
209  }
210 }
bool do_reinitialize(fhicl::ParameterSet const &, uint64_t, uint64_t) override
Reinitialize the AggregatorCore. No-Op.
std::string register_monitor(fhicl::ParameterSet const &info) override
Register an art Online Monitor to the AggregatorCore.
bool do_pause(uint64_t, uint64_t) override
Pause the AggregatorCore.
bool do_resume(uint64_t, uint64_t) override
Resume the AggregatorCore.
bool do_initialize(fhicl::ParameterSet const &pset, uint64_t, uint64_t) override
Initialize the AggregatorCore.
AggregatorApp(int rank, std::string name)
AggregatorApp Constructor.
Definition: AggregatorApp.cc:7
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_stop(uint64_t, uint64_t) override
Stop the AggregatorCore.
bool do_shutdown(uint64_t) override
Shutdown the AggregatorCore.
std::string unregister_monitor(std::string const &label) override
Remove an art Online Monitor from the AggregatorCore.
AggregatorCore implements the state machine for the Aggregator artdaq application. AggregatorCore processes incoming events in one of three roles: Data Logger, Online Monitor, or Dispatcher.
bool do_start(art::RunID id, uint64_t, uint64_t) override
Start the AggregatorCore.
bool do_soft_initialize(fhicl::ParameterSet const &, uint64_t, uint64_t) override
Soft-initialize the AggregatorCore. No-Op.
size_t process_fragments()
The main working loop of the AggregatorCore. Receives events from DataReceiverManager and processes t...