artdaq_demo  3.13.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 #include "artdaq-core-demo/Overlays/ToyFragment.hh"
6 
7 #include "fhiclcpp/fwd.h"
8 
9 #include <chrono>
10 #include <random>
11 
23 {
24 public:
29  explicit ToyHardwareInterface(fhicl::ParameterSet const& ps);
30 
36  void StartDatataking();
37 
41  void StopDatataking();
42 
48  void FillBuffer(char* buffer, size_t* bytes_read);
49 
54  void AllocateReadoutBuffer(char** buffer);
55 
60  void FreeReadoutBuffer(const char* buffer);
61 
66  int SerialNumber() const;
67 
72  int NumADCBits() const;
73 
78  int BoardType() const;
79 
83  enum class DistributionType
84  {
85  uniform,
86  gaussian,
87  monotonic,
89  uninit2 // like uninitialized, but do memcpy
90  };
91 
92 private:
93  bool taking_data_;
94 
95  struct RateInfo {
96  std::size_t size_bytes;
97  std::size_t rate_hz;
98  std::chrono::microseconds duration;
99  };
100 
101  std::size_t change_after_N_seconds_;
102  std::size_t pause_after_N_seconds_; // sleep this many seconds every change_after_N_seconds_
103  bool exception_after_N_seconds_;
104  bool exit_after_N_seconds_;
105  bool abort_after_N_seconds_;
106  bool hang_after_N_seconds_;
107  demo::FragmentType fragment_type_;
108  std::size_t maxADCvalue_;
109  DistributionType distribution_type_;
110  std::vector<RateInfo> configured_rates_;
111  std::vector<RateInfo>::iterator current_rate_;
112 
113  using time_type = decltype(std::chrono::steady_clock::now());
114 
115  const time_type fake_time_ = std::numeric_limits<time_type>::max();
116 
117  // Members needed to generate the simulated data
118 
119  std::mt19937 engine_;
120  std::unique_ptr<std::uniform_int_distribution<demo::ToyFragment::adc_t>> uniform_distn_;
121  std::unique_ptr<std::normal_distribution<double>> gaussian_distn_;
122 
123  time_type start_time_;
124  time_type rate_start_time_;
125  int rate_send_calls_;
126  int serial_number_;
127 
128 
129  std::chrono::microseconds rate_to_delay_(std::size_t hz);
130  std::chrono::steady_clock::time_point next_trigger_time_();
131  size_t bytes_to_nWords_(size_t bytes);
132  size_t bytes_to_nADCs_(size_t bytes);
133  size_t maxADCcounts_();
134 };
135 
136 #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...
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.