artdaq  v3_12_02
GenericFragmentSimulator.hh
1 #ifndef artdaq_DAQdata_GenericFragmentSimulator_hh
2 #define artdaq_DAQdata_GenericFragmentSimulator_hh
3 
4 #include "TRACE/tracemf.h" // Pre-empt TRACE/trace.h from Fragment.hh.
5 #include "artdaq-core/Data/Fragment.hh"
6 
7 #include "artdaq-core/Plugins/FragmentGenerator.hh"
8 
9 namespace fhicl {
10 class ParameterSet;
11 }
12 
13 #include "fhiclcpp/types/Atom.h"
14 #include "fhiclcpp/types/Comment.h"
15 #include "fhiclcpp/types/ConfigurationTable.h"
16 #include "fhiclcpp/types/Name.h"
17 
18 #include <random>
19 #include <vector>
20 
21 namespace artdaq {
22 class GenericFragmentSimulator;
23 }
24 
36 class artdaq::GenericFragmentSimulator : public artdaq::FragmentGenerator
37 {
38 public:
42  struct Config
43  {
49  fhicl::Atom<size_t> content_selection{fhicl::Name{"content_selection"}, fhicl::Comment{"What type of data to fill in generated Fragment payloads"}, 0};
51  fhicl::Atom<size_t> payload_size{fhicl::Name{"payload_size"}, fhicl::Comment{"The size (in words) of the Fragment payload"}, 10240};
53  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};
55  fhicl::Atom<int64_t> random_seed{fhicl::Name{"random_seed"}, fhicl::Comment{"Random seed for random number distributions"}, 314159};
57  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};
60  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};
61  };
63  using Parameters = fhicl::WrappedTable<Config>;
64 
69  explicit GenericFragmentSimulator(fhicl::ParameterSet const& ps);
70 
74  enum class content_selector_t : uint8_t
75  {
76  EMPTY = 0,
77  FRAG_ID = 1,
78  RANDOM = 2,
79  DEAD_BEEF
80  };
81 
82  // Not part of virtual interface: generate a specific fragment.
83  using FragmentGenerator::getNext;
84 
92  bool getNext(Fragment::sequence_id_t sequence_id,
93  Fragment::fragment_id_t fragment_id,
94  FragmentPtr& frag_ptr);
95 
101  bool getNext(FragmentPtrs& output) override
102  {
103  return getNext_(output);
104  }
105 
110  std::vector<Fragment::fragment_id_t> fragmentIDs() override
111  {
112  return fragmentIDs_();
113  }
114 
115 private:
116  bool getNext_(FragmentPtrs& frags);
117 
118  std::vector<Fragment::fragment_id_t> fragmentIDs_();
119 
120  std::size_t generateFragmentSize_();
121 
122  // Configuration
123  content_selector_t const content_selection_;
124  std::size_t const payload_size_spec_; // Poisson mean if random size wanted.
125  std::vector<Fragment::fragment_id_t> fragment_ids_;
126 
127  bool const want_random_payload_size_;
128 
129  // State
130  std::size_t current_event_num_;
131  std::mt19937 engine_;
132  std::poisson_distribution<size_t> payload_size_generator_;
133  std::uniform_int_distribution<uint64_t> fragment_content_generator_;
134 };
135 
136 #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.