artdaq_demo  v3_12_00
ToyHardwareInterface.hh
1 #ifndef artdaq_demo_Generators_ToyHardwareInterface_ToyHardwareInterface_hh
2 #define artdaq_demo_Generators_ToyHardwareInterface_ToyHardwareInterface_hh
3 
4 #include "artdaq-core-demo/Overlays/FragmentType.hh"
5 
6 #include "fhiclcpp/fwd.h"
7 
8 #include <chrono>
9 #include <random>
10 
22 {
23 public:
24  typedef uint16_t data_t;
25 
30  explicit ToyHardwareInterface(fhicl::ParameterSet const& ps);
31 
37  void StartDatataking();
38 
42  void StopDatataking();
43 
49  void FillBuffer(char* buffer, size_t* bytes_read);
50 
55  void AllocateReadoutBuffer(char** buffer);
56 
61  void FreeReadoutBuffer(const char* buffer);
62 
67  int SerialNumber() const;
68 
73  int NumADCBits() const;
74 
79  int BoardType() const;
80 
84  enum class DistributionType
85  {
86  uniform,
87  gaussian,
88  monotonic,
90  uninit2 // like uninitialized, but do memcpy
91  };
92 
93 private:
94  bool taking_data_;
95 
96  std::size_t nADCcounts_;
97  std::size_t maxADCcounts_;
98  std::size_t change_after_N_seconds_;
99  std::size_t pause_after_N_seconds_; // sleep this many seconds every change_after_N_seconds_
100  std::size_t nADCcounts_after_N_seconds_;
101  bool exception_after_N_seconds_;
102  bool exit_after_N_seconds_;
103  bool abort_after_N_seconds_;
104  bool hang_after_N_seconds_;
105  demo::FragmentType fragment_type_;
106  std::size_t maxADCvalue_;
107  std::size_t throttle_usecs_;
108  std::size_t usecs_between_sends_;
109  DistributionType distribution_type_;
110 
111  using time_type = decltype(std::chrono::steady_clock::now());
112 
113  const time_type fake_time_ = std::numeric_limits<time_type>::max();
114 
115  // Members needed to generate the simulated data
116 
117  std::mt19937 engine_;
118  std::unique_ptr<std::uniform_int_distribution<data_t>> uniform_distn_;
119  std::unique_ptr<std::normal_distribution<double>> gaussian_distn_;
120 
121  time_type start_time_;
122  int send_calls_;
123  int serial_number_;
124 };
125 
126 #endif
int NumADCBits() const
Get the number of ADC bits used in generating data.
void StartDatataking()
&quot;StartDatataking&quot; is meant to mimic actions one would take when telling the hardware to start sending...
uint16_t data_t
The type used to represent ADC counts (which are 12 or 14 bits, for TOY1 or TOY2) ...
void StopDatataking()
Performs shutdown actions.
void FillBuffer(char *buffer, size_t *bytes_read)
Use configured generator to fill a buffer with data.
DistributionType
Allow for the selection of output distribution.
void FreeReadoutBuffer(const char *buffer)
Release the given buffer to the hardware.
A monotonically-increasing distribution.
ToyHardwareInterface(fhicl::ParameterSet const &ps)
Construct and configure ToyHardwareInterface.
A use-after-free expliot distribution.
void AllocateReadoutBuffer(char **buffer)
Request a buffer from the hardware.
int SerialNumber() const
Gets the serial number of the simulated hardware.
JCF, Mar-17-2016: ToyHardwareInterface is meant to mimic a vendor-provided hardware API...
int BoardType() const
Return the &quot;board type&quot; of the simulated hardware.