artdaq  v3_02_01
BoardReaderApp.cc
1 #define TRACE_NAME (app_name + "_BoardReaderApp").c_str()
2 #include "artdaq/DAQdata/Globals.hh"
3 #include "artdaq/Application/BoardReaderApp.hh"
4 
6  : fragment_receiver_ptr_(nullptr)
7 {
8 }
9 
10 // *******************************************************************
11 // *** The following methods implement the state machine operations.
12 // *******************************************************************
13 
14 bool artdaq::BoardReaderApp::do_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
15 {
16  report_string_ = "";
17  external_request_status_ = true;
18 
19  // in the following block, we first destroy the existing BoardReader
20  // instance, then create a new one. Doing it in one step does not
21  // produce the desired result since that creates a new instance and
22  // then deletes the old one, and we need the opposite order.
23  TLOG(TLVL_DEBUG) << "Initializing first deleting old instance " << (void*)fragment_receiver_ptr_.get() ;
24  fragment_receiver_ptr_.reset(nullptr);
25  fragment_receiver_ptr_.reset(new BoardReaderCore(*this));
26  TLOG(TLVL_DEBUG) << "Initializing new BoardReaderCore at " << (void*)fragment_receiver_ptr_.get() << " with pset " << pset.to_string() ;
27  external_request_status_ = fragment_receiver_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  TLOG(TLVL_DEBUG) << "do_initialize(fhicl::ParameterSet, uint64_t, uint64_t): "
36  << "Done initializing." ;
37  return external_request_status_;
38 }
39 
40 bool artdaq::BoardReaderApp::do_start(art::RunID id, uint64_t timeout, uint64_t timestamp)
41 {
42  report_string_ = "";
43  external_request_status_ = fragment_receiver_ptr_->start(id, timeout, timestamp);
44  if (! external_request_status_)
45  {
46  report_string_ = "Error starting ";
47  report_string_.append(app_name + " ");
48  report_string_.append("for run number ");
49  report_string_.append(boost::lexical_cast<std::string>(id.run()));
50  report_string_.append(", timeout ");
51  report_string_.append(boost::lexical_cast<std::string>(timeout));
52  report_string_.append(", timestamp ");
53  report_string_.append(boost::lexical_cast<std::string>(timestamp));
54  report_string_.append(".");
55  }
56 
57  boost::thread::attributes attrs;
58  attrs.set_stack_size(4096 * 2000); // 8 MB
59  fragment_processing_thread_ = boost::thread(attrs, boost::bind(&BoardReaderCore::process_fragments, fragment_receiver_ptr_.get()));
60  /*
61  fragment_processing_future_ =
62  std::async(std::launch::async, &BoardReaderCore::process_fragments,
63  fragment_receiver_ptr_.get());*/
64 
65  return external_request_status_;
66 }
67 
68 bool artdaq::BoardReaderApp::do_stop(uint64_t timeout, uint64_t timestamp)
69 {
70  report_string_ = "";
71  external_request_status_ = fragment_receiver_ptr_->stop(timeout, timestamp);
72  if (! external_request_status_)
73  {
74  report_string_ = "Error stopping ";
75  report_string_.append(app_name + ".");
76  return false;
77  }
78 
79  int number_of_fragments_sent = fragment_receiver_ptr_->GetFragmentsProcessed();
80  TLOG(TLVL_DEBUG) << "do_stop(uint64_t, uint64_t): "
81  << "Number of fragments sent = " << number_of_fragments_sent
82  << "." ;
83 
84  return external_request_status_;
85 }
86 
87 bool artdaq::BoardReaderApp::do_pause(uint64_t timeout, uint64_t timestamp)
88 {
89  report_string_ = "";
90  external_request_status_ = fragment_receiver_ptr_->pause(timeout, timestamp);
91  if (! external_request_status_)
92  {
93  report_string_ = "Error pausing ";
94  report_string_.append(app_name + ".");
95  }
96 
97  int number_of_fragments_sent = fragment_receiver_ptr_->GetFragmentsProcessed();
98  TLOG(TLVL_DEBUG) << "do_pause(uint64_t, uint64_t): "
99  << "Number of fragments sent = " << number_of_fragments_sent
100  << "." ;
101 
102  return external_request_status_;
103 }
104 
105 bool artdaq::BoardReaderApp::do_resume(uint64_t timeout, uint64_t timestamp)
106 {
107  report_string_ = "";
108  external_request_status_ = fragment_receiver_ptr_->resume(timeout, timestamp);
109  if (! external_request_status_)
110  {
111  report_string_ = "Error resuming ";
112  report_string_.append(app_name + ".");
113  }
114 
115  boost::thread::attributes attrs;
116  attrs.set_stack_size(4096 * 2000); // 8 MB
117  fragment_processing_thread_ = boost::thread(attrs, boost::bind(&BoardReaderCore::process_fragments, fragment_receiver_ptr_.get()));
118 /*
119  fragment_processing_future_ =
120  std::async(std::launch::async, &BoardReaderCore::process_fragments,
121  fragment_receiver_ptr_.get());*/
122 
123  return external_request_status_;
124 }
125 
127 {
128  report_string_ = "";
129  external_request_status_ = fragment_receiver_ptr_->shutdown(timeout);
130  if (! external_request_status_)
131  {
132  report_string_ = "Error shutting down ";
133  report_string_.append(app_name + ".");
134  }
135  return external_request_status_;
136 }
137 
138 bool artdaq::BoardReaderApp::do_soft_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
139 {
140  report_string_ = "";
141  external_request_status_ = fragment_receiver_ptr_->soft_initialize(pset, timeout, timestamp);
142  if (! external_request_status_)
143  {
144  report_string_ = "Error soft-initializing ";
145  report_string_.append(app_name + " ");
146  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
147  }
148  return external_request_status_;
149 }
150 
151 bool artdaq::BoardReaderApp::do_reinitialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
152 {
153  external_request_status_ = fragment_receiver_ptr_->reinitialize(pset, timeout, timestamp);
154  if (! external_request_status_)
155  {
156  report_string_ = "Error reinitializing ";
157  report_string_.append(app_name + " ");
158  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
159  }
160  return external_request_status_;
161 }
162 
164 {
165  TLOG(TLVL_DEBUG) << "Booted state entry action called." ;
166 
167  // the destruction of any existing BoardReaderCore has to happen in the
168  // Booted Entry action rather than the Initialized Exit action because the
169  // Initialized Exit action is only called after the "init" transition guard
170  // condition is executed.
171  fragment_receiver_ptr_.reset(nullptr);
172 }
173 
174 bool artdaq::BoardReaderApp::do_meta_command(std::string const& command, std::string const& arg)
175 {
176  external_request_status_ = fragment_receiver_ptr_->metaCommand(command, arg);
177  if (!external_request_status_)
178  {
179  report_string_ = "Error running meta-command on ";
180  report_string_.append(app_name + " ");
181  report_string_.append("with command = \"" + command + "\", arg = \"" + arg + "\".");
182  }
183  return external_request_status_;
184 }
185 
186 std::string artdaq::BoardReaderApp::report(std::string const& which) const
187 {
188  std::string resultString;
189 
190  // if all that is requested is the latest state change result, return it
191  if (which == "transition_status")
192  {
193  if (report_string_.length() > 0) { return report_string_; }
194  else { return "Success"; }
195  }
196 
199  //if (report_string_.length() > 0) {
200  // resultString.append("*** Overall status message:\r\n");
201  // resultString.append(report_string_ + "\r\n");
202  // resultString.append("*** Requested report response:\r\n");
203  //}
204 
205  // pass the request to the BoardReaderCore instance, if it's available
206  if (fragment_receiver_ptr_.get() != 0)
207  {
208  resultString.append(fragment_receiver_ptr_->report(which));
209  }
210  else
211  {
212  resultString.append("This BoardReader has not yet been initialized and ");
213  resultString.append("therefore can not provide reporting.");
214  }
215 
216  return resultString;
217 }
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_meta_command(std::string const &command, std::string const &arg) override
Perform a user-defined command (passed to CommandableFragmentGenerator)
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 ...
BoardReaderApp()
BoardReaderApp Constructor.
void BootedEnter() override
Action taken upon entering the &quot;Booted&quot; state.
void process_fragments()
Main working loop of the BoardReaderCore.
bool do_start(art::RunID id, uint64_t timeout, uint64_t timestamp) override
Start 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.