artdaq  v3_01_00
RoutingMasterApp.cc
1 #define TRACE_NAME "RoutingMasterApp"
2 
3 #include "artdaq/Application/RoutingMasterApp.hh"
4 
9 {
10 }
11 
12 // *******************************************************************
13 // *** The following methods implement the state machine operations.
14 // *******************************************************************
15 
16 bool artdaq::RoutingMasterApp::do_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
17 {
18  report_string_ = "";
19  external_request_status_ = true;
20 
21  // in the following block, we first destroy the existing RoutingMaster
22  // instance, then create a new one. Doing it in one step does not
23  // produce the desired result since that creates a new instance and
24  // then deletes the old one, and we need the opposite order.
25  routing_master_ptr_.reset(nullptr);
26  routing_master_ptr_.reset(new RoutingMasterCore());
27  external_request_status_ = routing_master_ptr_->initialize(pset, timeout, timestamp);
28  if (!external_request_status_)
29  {
30  report_string_ = "Error initializing ";
31  report_string_.append(app_name + " ");
32  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
33  }
34 
35  return external_request_status_;
36 }
37 
38 bool artdaq::RoutingMasterApp::do_start(art::RunID id, uint64_t timeout, uint64_t timestamp)
39 {
40  report_string_ = "";
41  external_request_status_ = routing_master_ptr_->start(id, timeout, timestamp);
42  if (!external_request_status_)
43  {
44  report_string_ = "Error starting ";
45  report_string_.append(app_name + " ");
46  report_string_.append("for run number ");
47  report_string_.append(boost::lexical_cast<std::string>(id.run()));
48  report_string_.append(", timeout ");
49  report_string_.append(boost::lexical_cast<std::string>(timeout));
50  report_string_.append(", timestamp ");
51  report_string_.append(boost::lexical_cast<std::string>(timestamp));
52  report_string_.append(".");
53  }
54 
55  routing_master_future_ =
56  std::async(std::launch::async, &RoutingMasterCore::process_event_table,
57  routing_master_ptr_.get());
58 
59  return external_request_status_;
60 }
61 
62 bool artdaq::RoutingMasterApp::do_stop(uint64_t timeout, uint64_t timestamp)
63 {
64  report_string_ = "";
65  external_request_status_ = routing_master_ptr_->stop(timeout, timestamp);
66  if (!external_request_status_)
67  {
68  report_string_ = "Error stopping ";
69  report_string_.append(app_name + ".");
70  return false;
71  }
72 
73  if (routing_master_future_.valid())
74  {
75  int number_of_table_entries_sent = routing_master_future_.get();
76  TLOG_DEBUG(app_name + "App") << "do_stop(uint64_t, uint64_t): "
77  << "Number of table entries sent = " << number_of_table_entries_sent
78  << "." ;
79  }
80 
81  return external_request_status_;
82 }
83 
84 bool artdaq::RoutingMasterApp::do_pause(uint64_t timeout, uint64_t timestamp)
85 {
86  report_string_ = "";
87  external_request_status_ = routing_master_ptr_->pause(timeout, timestamp);
88  if (!external_request_status_)
89  {
90  report_string_ = "Error pausing ";
91  report_string_.append(app_name + ".");
92  }
93 
94  if (routing_master_future_.valid())
95  {
96  int number_of_table_entries_sent = routing_master_future_.get();
97  TLOG_DEBUG(app_name + "App") << "do_pause(uint64_t, uint64_t): "
98  << "Number of table entries sent = " << number_of_table_entries_sent
99  << "." ;
100  }
101 
102  return external_request_status_;
103 }
104 
105 bool artdaq::RoutingMasterApp::do_resume(uint64_t timeout, uint64_t timestamp)
106 {
107  report_string_ = "";
108  external_request_status_ = routing_master_ptr_->resume(timeout, timestamp);
109  if (!external_request_status_)
110  {
111  report_string_ = "Error resuming ";
112  report_string_.append(app_name + ".");
113  }
114 
115  routing_master_future_ =
116  std::async(std::launch::async, &RoutingMasterCore::process_event_table,
117  routing_master_ptr_.get());
118 
119  return external_request_status_;
120 }
121 
123 {
124  report_string_ = "";
125  external_request_status_ = routing_master_ptr_->shutdown(timeout);
126  if (!external_request_status_)
127  {
128  report_string_ = "Error shutting down ";
129  report_string_.append(app_name + ".");
130  }
131  return external_request_status_;
132 }
133 
134 bool artdaq::RoutingMasterApp::do_soft_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
135 {
136  report_string_ = "";
137  external_request_status_ = routing_master_ptr_->soft_initialize(pset, timeout, timestamp);
138  if (!external_request_status_)
139  {
140  report_string_ = "Error soft-initializing ";
141  report_string_.append(app_name + " ");
142  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
143  }
144  return external_request_status_;
145 }
146 
147 bool artdaq::RoutingMasterApp::do_reinitialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
148 {
149  external_request_status_ = routing_master_ptr_->reinitialize(pset, timeout, timestamp);
150  if (!external_request_status_)
151  {
152  report_string_ = "Error reinitializing ";
153  report_string_.append(app_name + " ");
154  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
155  }
156  return external_request_status_;
157 }
158 
160 {
161  TLOG_DEBUG(app_name + "App") << "Booted state entry action called." ;
162 
163  // the destruction of any existing RoutingMasterCore has to happen in the
164  // Booted Entry action rather than the Initialized Exit action because the
165  // Initialized Exit action is only called after the "init" transition guard
166  // condition is executed.
167  routing_master_ptr_.reset(nullptr);
168 }
169 
170 std::string artdaq::RoutingMasterApp::report(std::string const& which) const
171 {
172  std::string resultString;
173 
174  // if all that is requested is the latest state change result, return it
175  if (which == "transition_status")
176  {
177  if (report_string_.length() > 0) { return report_string_; }
178  else { return "Success"; }
179  }
180 
183  //if (report_string_.length() > 0) {
184  // resultString.append("*** Overall status message:\r\n");
185  // resultString.append(report_string_ + "\r\n");
186  // resultString.append("*** Requested report response:\r\n");
187  //}
188 
189  // pass the request to the RoutingMasterCore instance, if it's available
190  if (routing_master_ptr_.get() != 0)
191  {
192  resultString.append(routing_master_ptr_->report(which));
193  }
194  else
195  {
196  resultString.append("This RoutingMaster has not yet been initialized and ");
197  resultString.append("therefore can not provide reporting.");
198  }
199 
200  return resultString;
201 }
bool do_initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp) override
Initialize the RoutingMasterCore.
bool do_pause(uint64_t timeout, uint64_t timestamp) override
Pause the RoutingMasterCore.
size_t process_event_table()
Main loop of the RoutingMasterCore. Determines when to send the next table update, asks the RoutingMasterPolicy for the table to send, and sends it.
RoutingMasterApp()
RoutingMasterApp Constructor.
bool do_resume(uint64_t timeout, uint64_t timestamp) override
Resume the RoutingMasterCore.
bool do_stop(uint64_t timeout, uint64_t timestamp) override
Stop the RoutingMasterCore.
std::string report(std::string const &) 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 timeout) override
Shutdown the RoutingMasterCore.
bool do_soft_initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp) override
Soft-Initialize the RoutingMasterCore.
bool do_reinitialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp) override
Reinitialize the RoutingMasterCore.
bool do_start(art::RunID id, uint64_t timeout, uint64_t timestamp) override
Start the RoutingMasterCore.
void BootedEnter() override
Action taken upon entering the &quot;Booted&quot; state.
RoutingMasterCore implements the state machine for the RoutingMaster artdaq application. RoutingMasterCore collects tokens from receivers, and at regular intervals uses these tokens to build Routing Tables that are sent to the senders.