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