00001 #ifndef artdaq_DAQdata_GenericFragmentSimulator_hh
00002 #define artdaq_DAQdata_GenericFragmentSimulator_hh
00003
00004 #include "artdaq/DAQdata/Globals.hh"
00005 #include "artdaq-core/Data/Fragment.hh"
00006 #include "artdaq-core/Generators/FragmentGenerator.hh"
00007 #include "fhiclcpp/fwd.h"
00008
00009 #include <random>
00010
00011 namespace artdaq
00012 {
00013 class GenericFragmentSimulator;
00014 }
00015
00027 class artdaq::GenericFragmentSimulator : public artdaq::FragmentGenerator
00028 {
00029 public:
00033 struct Config
00034 {
00040 fhicl::Atom<size_t> content_selection{ fhicl::Name{"content_selection"}, fhicl::Comment{"What type of data to fill in generated Fragment payloads"}, 0 };
00042 fhicl::Atom<size_t> payload_size{ fhicl::Name{"payload_size"}, fhicl::Comment{"The size (in words) of the Fragment payload"}, 10240 };
00044 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 };
00046 fhicl::Atom<int64_t> random_seed{ fhicl::Name{"random_seed"}, fhicl::Comment{"Random seed for random number distributions"}, 314159 };
00048 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 };
00051 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 };
00052 };
00053 using Parameters = fhicl::WrappedTable<Config>;
00054
00059 explicit GenericFragmentSimulator(fhicl::ParameterSet const& ps);
00060
00064 enum class content_selector_t : uint8_t
00065 {
00066 EMPTY = 0,
00067 FRAG_ID = 1,
00068 RANDOM = 2,
00069 DEAD_BEEF
00070 };
00071
00072
00073 using FragmentGenerator::getNext;
00074
00082 bool getNext(Fragment::sequence_id_t sequence_id,
00083 Fragment::fragment_id_t fragment_id,
00084 FragmentPtr& frag_ptr);
00085
00091 bool getNext(FragmentPtrs& output) override
00092 {
00093 return getNext_(output);
00094 }
00095
00100 std::vector<Fragment::fragment_id_t> fragmentIDs() override
00101 {
00102 return fragmentIDs_();
00103 }
00104
00105 private:
00106 bool getNext_(FragmentPtrs& output);
00107
00108 std::vector<Fragment::fragment_id_t> fragmentIDs_();
00109
00110 std::size_t generateFragmentSize_();
00111
00112
00113 content_selector_t const content_selection_;
00114 std::size_t const payload_size_spec_;
00115 std::vector<Fragment::fragment_id_t> fragment_ids_;
00116
00117 bool const want_random_payload_size_;
00118
00119
00120 std::size_t current_event_num_;
00121 std::mt19937 engine_;
00122 std::poisson_distribution<size_t> payload_size_generator_;
00123 std::uniform_int_distribution<uint64_t> fragment_content_generator_;
00124 };
00125
00126 #endif