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 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
00054 using Parameters = fhicl::WrappedTable<Config>;
00055 #endif
00056
00061 explicit GenericFragmentSimulator(fhicl::ParameterSet const& ps);
00062
00066 enum class content_selector_t : uint8_t
00067 {
00068 EMPTY = 0,
00069 FRAG_ID = 1,
00070 RANDOM = 2,
00071 DEAD_BEEF
00072 };
00073
00074
00075 using FragmentGenerator::getNext;
00076
00084 bool getNext(Fragment::sequence_id_t sequence_id,
00085 Fragment::fragment_id_t fragment_id,
00086 FragmentPtr& frag_ptr);
00087
00093 bool getNext(FragmentPtrs& output) override
00094 {
00095 return getNext_(output);
00096 }
00097
00102 std::vector<Fragment::fragment_id_t> fragmentIDs() override
00103 {
00104 return fragmentIDs_();
00105 }
00106
00107 private:
00108 bool getNext_(FragmentPtrs& output);
00109
00110 std::vector<Fragment::fragment_id_t> fragmentIDs_();
00111
00112 std::size_t generateFragmentSize_();
00113
00114
00115 content_selector_t const content_selection_;
00116 std::size_t const payload_size_spec_;
00117 std::vector<Fragment::fragment_id_t> fragment_ids_;
00118
00119 bool const want_random_payload_size_;
00120
00121
00122 std::size_t current_event_num_;
00123 std::mt19937 engine_;
00124 std::poisson_distribution<size_t> payload_size_generator_;
00125 std::uniform_int_distribution<uint64_t> fragment_content_generator_;
00126 };
00127
00128 #endif