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