artdaq  v3_02_00
GenericFragmentSimulator.hh
1 #ifndef artdaq_DAQdata_GenericFragmentSimulator_hh
2 #define artdaq_DAQdata_GenericFragmentSimulator_hh
3 
4 #include "artdaq/DAQdata/Globals.hh"
5 #include "artdaq-core/Data/Fragment.hh"
6 #include "artdaq-core/Generators/FragmentGenerator.hh"
7 #include "fhiclcpp/fwd.h"
8 
9 #include <random>
10 
11 namespace artdaq
12 {
13  class GenericFragmentSimulator;
14 }
15 
27 class artdaq::GenericFragmentSimulator : public artdaq::FragmentGenerator
28 {
29 public:
30  struct Config
31  {
32  fhicl::Atom<size_t> content_selection{ fhicl::Name{"content_selection"}, fhicl::Comment{"What type of data to fill in generated Fragment payloads"}, 0 };
33  fhicl::Atom<size_t> payload_size{ fhicl::Name{"payload_size"}, fhicl::Comment{"The size (in words) of the Fragment payload"}, 10240 };
34  fhicl::Atom<bool> want_random_payload_size{ fhicl::Name{"want_random_payload_size"}, fhicl::Comment{"Whether payload size should be sampled from a random distribution"}, false };
35  fhicl::Atom<int64_t> random_seed{ fhicl::Name{"random_seed"}, fhicl::Comment{"Random seed for random number distributions"}, 314159 };
36  fhicl::Atom<size_t> fragments_per_event{ fhicl::Name{"fragments_per_event"}, fhicl::Comment{"The number of Fragment objects to generate for each sequence ID"}, 5 };
37  fhicl::Atom<Fragment::fragment_id_t> starting_fragment_id{ fhicl::Name{"starting_fragment_id"}, fhicl::Comment{"The first Fragment ID handled by this GenericFragmentSimulator."}, 0 };
38  };
39 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
40  using Parameters = fhicl::WrappedTable<Config>;
41 #endif
42 
62  explicit GenericFragmentSimulator(fhicl::ParameterSet const& ps);
63 
67  enum class content_selector_t : uint8_t
68  {
69  EMPTY = 0,
70  FRAG_ID = 1,
71  RANDOM = 2,
72  DEAD_BEEF
73  };
74 
75  // Not part of virtual interface: generate a specific fragment.
76  using FragmentGenerator::getNext;
77 
85  bool getNext(Fragment::sequence_id_t sequence_id,
86  Fragment::fragment_id_t fragment_id,
87  FragmentPtr& frag_ptr);
88 
94  bool getNext(FragmentPtrs& output) override
95  {
96  return getNext_(output);
97  }
98 
103  std::vector<Fragment::fragment_id_t> fragmentIDs() override
104  {
105  return fragmentIDs_();
106  }
107 
108 private:
109  bool getNext_(FragmentPtrs& output);
110 
111  std::vector<Fragment::fragment_id_t> fragmentIDs_();
112 
113  std::size_t generateFragmentSize_();
114 
115  // Configuration
116  content_selector_t const content_selection_;
117  std::size_t const payload_size_spec_; // Poisson mean if random size wanted.
118  std::vector<Fragment::fragment_id_t> fragment_ids_;
119 
120  bool const want_random_payload_size_;
121 
122  // State
123  std::size_t current_event_num_;
124  std::mt19937 engine_;
125  std::poisson_distribution<size_t> payload_size_generator_;
126  std::uniform_int_distribution<uint64_t> fragment_content_generator_;
127 };
128 
129 #endif /* artdaq_DAQdata_GenericFragmentSimulator_hh */
bool getNext(FragmentPtrs &output) override
Get the next Fragment from the generator.
GenericFragmentSimulator(fhicl::ParameterSet const &ps)
GenericFragmentSimulator Constructor.
std::vector< Fragment::fragment_id_t > fragmentIDs() override
Get the Fragment IDs generated by this instance.
GenericFragmentSimulator creates simulated Generic events, with data distributed according to a &quot;hist...
content_selector_t
What type of content should the GenericFragmentSimulator put in Fragment objects? ...
Use a random distribution to fill the payload.
bool getNext(Fragment::sequence_id_t sequence_id, Fragment::fragment_id_t fragment_id, FragmentPtr &frag_ptr)
Generate a Fragment according to the value of the content_selectior_t enum.
Fill the payload with 0xDEADBEEFDEADBEEF.