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