artdaq_demo  3.12.07
ToySimulator.hh
1 #ifndef artdaq_demo_Generators_ToySimulator_hh
2 #define artdaq_demo_Generators_ToySimulator_hh
3 
4 // Some C++ conventions used:
5 
6 // -Append a "_" to every private member function and variable
7 
8 #include "artdaq-core-demo/Overlays/FragmentType.hh"
9 #include "artdaq-core-demo/Overlays/ToyFragment.hh"
10 #include "artdaq-core/Data/Fragment.hh"
11 #include "artdaq/Generators/CommandableFragmentGenerator.hh"
12 #include "fhiclcpp/fwd.h"
13 
14 #include "ToyHardwareInterface/ToyHardwareInterface.hh"
15 
16 #include <atomic>
17 #include <random>
18 #include <vector>
19 
20 namespace demo {
35 class ToySimulator : public artdaq::CommandableFragmentGenerator
36 {
37 public:
48  explicit ToySimulator(fhicl::ParameterSet const& ps);
49 
53  virtual ~ToySimulator();
54 
55 private:
56  ToySimulator(ToySimulator const&) = delete;
57  ToySimulator(ToySimulator&&) = delete;
58  ToySimulator& operator=(ToySimulator const&) = delete;
59  ToySimulator& operator=(ToySimulator&&) = delete;
60 
68  bool getNext_(artdaq::FragmentPtrs& frags) override;
69 
70  // The start, stop and stopNoMutex methods are declared pure
71  // virtual in CommandableFragmentGenerator and therefore MUST be
72  // overridden; note that stopNoMutex() doesn't do anything here
73 
79  void start() override;
80 
86  void stop() override;
87 
92  void stopNoMutex() override {}
93 
94  std::unique_ptr<ToyHardwareInterface> hardware_interface_;
95  artdaq::Fragment::timestamp_t timestamp_;
96  artdaq::Fragment::timestamp_t starting_timestamp_;
97  int timestampScale_;
98  size_t sequence_id_scale_;
99  size_t initial_sequence_id_;
100 
101  int rollover_subrun_interval_;
102 
103  ToyFragment::Metadata metadata_;
104 
105  // buffer_ points to the buffer which the hardware interface will
106  // fill. Notice that it's a raw pointer rather than a smart
107  // pointer as the API to ToyHardwareInterface was chosen to be a
108  // C++03-style API for greater realism
109 
110  char* readout_buffer_;
111 
112  FragmentType fragment_type_;
113  ToyHardwareInterface::DistributionType distribution_type_;
114  int generated_fragments_per_event_;
115  bool exception_on_config_;
116  bool dies_on_config_;
117 
118  bool lazy_mode_; // See Issue #22810
119  std::set<artdaq::Fragment::sequence_id_t> lazily_handled_requests_;
120 };
121 } // namespace demo
122 
123 #endif /* artdaq_demo_Generators_ToySimulator_hh */
DistributionType
Allow for the selection of output distribution.
ToySimulator(fhicl::ParameterSet const &ps)
ToySimulator Constructor.
virtual ~ToySimulator()
Shutdown the ToySimulator.
ToySimulator is a simple type of fragment generator intended to be studied by new users of artdaq as ...
Definition: ToySimulator.hh:35