artdaq  v3_07_02
GenericFragmentSimulator.hh
1 #ifndef artdaq_DAQdata_GenericFragmentSimulator_hh
2 #define artdaq_DAQdata_GenericFragmentSimulator_hh
3 
4 #include "artdaq-core/Data/Fragment.hh"
5 #include "artdaq-core/Generators/FragmentGenerator.hh"
6 #include "artdaq/DAQdata/Globals.hh"
7 #include "fhiclcpp/fwd.h"
8 
9 #include <random>
10 
11 namespace artdaq {
12 class GenericFragmentSimulator;
13 }
14 
26 class artdaq::GenericFragmentSimulator : public artdaq::FragmentGenerator
27 {
28 public:
32  struct Config
33  {
39  fhicl::Atom<size_t> content_selection{fhicl::Name{"content_selection"}, fhicl::Comment{"What type of data to fill in generated Fragment payloads"}, 0};
41  fhicl::Atom<size_t> payload_size{fhicl::Name{"payload_size"}, fhicl::Comment{"The size (in words) of the Fragment payload"}, 10240};
43  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};
45  fhicl::Atom<int64_t> random_seed{fhicl::Name{"random_seed"}, fhicl::Comment{"Random seed for random number distributions"}, 314159};
47  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};
50  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};
51  };
53  using Parameters = fhicl::WrappedTable<Config>;
54 
59  explicit GenericFragmentSimulator(fhicl::ParameterSet const& ps);
60 
64  enum class content_selector_t : uint8_t
65  {
66  EMPTY = 0,
67  FRAG_ID = 1,
68  RANDOM = 2,
69  DEAD_BEEF
70  };
71 
72  // Not part of virtual interface: generate a specific fragment.
73  using FragmentGenerator::getNext;
74 
82  bool getNext(Fragment::sequence_id_t sequence_id,
83  Fragment::fragment_id_t fragment_id,
84  FragmentPtr& frag_ptr);
85 
91  bool getNext(FragmentPtrs& output) override
92  {
93  return getNext_(output);
94  }
95 
100  std::vector<Fragment::fragment_id_t> fragmentIDs() override
101  {
102  return fragmentIDs_();
103  }
104 
105 private:
106  bool getNext_(FragmentPtrs& output);
107 
108  std::vector<Fragment::fragment_id_t> fragmentIDs_();
109 
110  std::size_t generateFragmentSize_();
111 
112  // Configuration
113  content_selector_t const content_selection_;
114  std::size_t const payload_size_spec_; // Poisson mean if random size wanted.
115  std::vector<Fragment::fragment_id_t> fragment_ids_;
116 
117  bool const want_random_payload_size_;
118 
119  // State
120  std::size_t current_event_num_;
121  std::mt19937 engine_;
122  std::poisson_distribution<size_t> payload_size_generator_;
123  std::uniform_int_distribution<uint64_t> fragment_content_generator_;
124 };
125 
126 #endif /* artdaq_DAQdata_GenericFragmentSimulator_hh */
fhicl::WrappedTable< Config > Parameters
Used for ParameterSet validation (if desired)
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.
fhicl::Atom< int64_t > random_seed
&quot;random_seed&quot; (Default: 314159) : Random seed for random number distributions
GenericFragmentSimulator creates simulated Generic events, with data distributed according to a &quot;hist...
fhicl::Atom< bool > want_random_payload_size
&quot;want_random_payload_size&quot; (Default: false) : Whether payload size should be sampled from a random di...
fhicl::Atom< Fragment::fragment_id_t > starting_fragment_id
fhicl::Atom< size_t > fragments_per_event
&quot;fragments_per_event&quot; (Default: 5) : The number of Fragment objects to generate for each sequence ID ...
Configuration of the GenericFragmentSimulator. May be used for parameter validation ...
content_selector_t
What type of content should the GenericFragmentSimulator put in Fragment objects? ...
fhicl::Atom< size_t > payload_size
&quot;payload_size&quot; (Default: 10240) : The size(in words) of the Fragment payload
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.