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