artdaq  v3_12_02
BoardReaderCore.hh
1 #ifndef ARTDAQ_ARTDAQ_APPLICATION_BOARDREADERCORE_HH_
2 #define ARTDAQ_ARTDAQ_APPLICATION_BOARDREADERCORE_HH_
3 
4 #include "artdaq/Application/Commandable.hh"
5 #include "artdaq/DAQrate/DataSenderManager.hh"
6 #include "artdaq/DAQrate/StatisticsHelper.hh"
7 #include "artdaq/DAQrate/detail/RequestReceiver.hh"
8 #include "artdaq/Generators/CommandableFragmentGenerator.hh"
9 
10 #include "canvas/Persistency/Provenance/RunID.h"
11 #include "fhiclcpp/ParameterSet.h"
12 
13 #include <atomic>
14 #include <string>
15 
16 namespace artdaq {
17 class BoardReaderCore;
18 }
19 
25 {
26 public:
27  static const std::string FRAGMENTS_PROCESSED_STAT_KEY;
28  static const std::string INPUT_WAIT_STAT_KEY;
29  static const std::string BUFFER_WAIT_STAT_KEY;
30  static const std::string REQUEST_WAIT_STAT_KEY;
31  static const std::string BRSYNC_WAIT_STAT_KEY;
32  static const std::string OUTPUT_WAIT_STAT_KEY;
33  static const std::string FRAGMENTS_PER_READ_STAT_KEY;
34 
39  BoardReaderCore(Commandable& parent_application);
40 
44  BoardReaderCore(BoardReaderCore const&) = delete;
45 
49  virtual ~BoardReaderCore();
50 
55  BoardReaderCore& operator=(BoardReaderCore const&) = delete;
56  BoardReaderCore(BoardReaderCore&&) = delete;
58 
79  bool initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
80 
88  bool start(art::RunID id, uint64_t timeout, uint64_t timestamp);
89 
96  bool stop(uint64_t timeout, uint64_t timestamp);
97 
104  bool pause(uint64_t timeout, uint64_t timestamp);
105 
112  bool resume(uint64_t timeout, uint64_t timestamp);
113 
119  bool shutdown(uint64_t timeout);
120 
128  bool soft_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
129 
137  bool reinitialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
138 
144  void receive_fragments();
145 
151  void send_fragments();
152 
161  std::string report(std::string const& which) const;
162 
169  bool metaCommand(std::string const& command, std::string const& arg);
170 
175  static DataSenderManager* GetDataSenderManagerPtr() { return sender_ptr_.get(); }
176 
181  size_t GetFragmentsProcessed() { return fragment_count_; }
182 
183  CommandableFragmentGenerator const* GetGeneratorPointer()
184  {
185  if (generator_ptr_)
186  return generator_ptr_.get();
187  else
188  return nullptr;
189  }
190 
195  bool GetSenderThreadActive() { return sender_thread_active_.load(); }
200  bool GetReceiverThreadActive() { return receiver_thread_active_.load(); }
207  void SetStartTransitionTimeout(double timeout) { start_transition_timeout_ = timeout; }
208 
209 private:
210  Commandable& parent_application_;
211  std::unique_ptr<CommandableFragmentGenerator> generator_ptr_;
212  std::unique_ptr<RequestReceiver> request_receiver_ptr_;
213  std::shared_ptr<FragmentBuffer> fragment_buffer_ptr_;
214  art::RunID run_id_;
215 
216  fhicl::ParameterSet data_pset_;
217  int rt_priority_;
218  bool skip_seqId_test_;
219 
220  static std::unique_ptr<artdaq::DataSenderManager> sender_ptr_;
221 
222  std::atomic<size_t> fragment_count_;
223  artdaq::Fragment::sequence_id_t prev_seq_id_;
224  std::atomic<bool> stop_requested_;
225  std::atomic<bool> pause_requested_;
226 
227  // State orchestration
228  std::atomic<bool> running_{false};
229  std::atomic<bool> sender_thread_active_{false};
230  std::atomic<bool> receiver_thread_active_{false};
231  double start_transition_timeout_{10.0};
232 
233  // attributes and methods for statistics gathering & reporting
234  artdaq::StatisticsHelper statsHelper_;
235 
236  std::string buildStatisticsString_();
237 
238  void sendMetrics_();
239 
240  bool verbose_;
241 };
242 
243 #endif // ARTDAQ_ARTDAQ_APPLICATION_BOARDREADERCORE_HH_
This class manages MonitoredQuantity instances for the *Core classes.
size_t GetFragmentsProcessed()
Get the number of Fragments processed this run
static const std::string BUFFER_WAIT_STAT_KEY
Key for the Fragment Buffer Wait MonitoredQuantity.
Commandable is the base class for all artdaq components which implement the artdaq state machine...
Definition: Commandable.hh:22
bool GetReceiverThreadActive()
Get whether the receiver thread is still running.
Sends Fragment objects using TransferInterface plugins. Uses Routing Tables if confgiured, otherwise will Round-Robin Fragments to the destinations.
bool initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Initialize the BoardReaderCore.
static DataSenderManager * GetDataSenderManagerPtr()
Gets a handle to the DataSenderManager.
static const std::string FRAGMENTS_PROCESSED_STAT_KEY
Key for the Fragments Processed MonitoredQuantity.
bool reinitialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Reinitialize the BoardReader. No-Op.
static const std::string INPUT_WAIT_STAT_KEY
Key for the Input Wait MonitoredQuantity.
bool GetSenderThreadActive()
Get whether the sender thread is still running.
bool stop(uint64_t timeout, uint64_t timestamp)
Stop the BoardReader, and the CommandableFragmentGenerator.
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.
virtual ~BoardReaderCore()
BoardReaderCore Destructor.
BoardReaderCore(Commandable &parent_application)
BoardReaderCore Constructor.
static const std::string BRSYNC_WAIT_STAT_KEY
Key for the Sync Wait MonitoredQuantity.
CommandableFragmentGenerator is a FragmentGenerator-derived abstract class that defines the interface...
static const std::string FRAGMENTS_PER_READ_STAT_KEY
Key for the Fragments Per Read MonitoredQuantity.
static const std::string REQUEST_WAIT_STAT_KEY
Key for the Request Buffer Wait MonitoredQuantity.
static const std::string OUTPUT_WAIT_STAT_KEY
Key for the Output Wait MonitoredQuantity.
void send_fragments()
Main working loop of the BoardReaderCore, pt. 2.
bool soft_initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Soft-Initialize the BoardReader. No-Op.
std::string report(std::string const &which) const
Send a report on a given run-time quantity.
bool shutdown(uint64_t timeout)
Shutdown the BoardReader, and the CommandableFragmentGenerator.
bool start(art::RunID id, uint64_t timeout, uint64_t timestamp)
Start the BoardReader, and the CommandableFragmentGenerator.
bool resume(uint64_t timeout, uint64_t timestamp)
Resume the BoardReader, and the CommandableFragmentGenerator.
void receive_fragments()
Main working loop of the BoardReaderCore.
bool pause(uint64_t timeout, uint64_t timestamp)
Pause the BoardReader, and the CommandableFragmentGenerator.
void SetStartTransitionTimeout(double timeout)
Set the timeout for starting the sender and receiver threads.
bool metaCommand(std::string const &command, std::string const &arg)
Run a user-defined command on the CommandableFragmentGenerator.
BoardReaderCore & operator=(BoardReaderCore const &)=delete
Copy Assignment Operator is deleted.