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:
00030 struct Config
00031 {
00032 fhicl::Atom<size_t> content_selection{ fhicl::Name{"content_selection"}, fhicl::Comment{"What type of data to fill in generated Fragment payloads"}, 0 };
00033 fhicl::Atom<size_t> payload_size{ fhicl::Name{"payload_size"}, fhicl::Comment{"The size (in words) of the Fragment payload"}, 10240 };
00034 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 };
00035 fhicl::Atom<int64_t> random_seed{ fhicl::Name{"random_seed"}, fhicl::Comment{"Random seed for random number distributions"}, 314159 };
00036 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 };
00037 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 };
00038 };
00039 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
00040 using Parameters = fhicl::WrappedTable<Config>;
00041 #endif
00042
00062 explicit GenericFragmentSimulator(fhicl::ParameterSet const& ps);
00063
00067 enum class content_selector_t : uint8_t
00068 {
00069 EMPTY = 0,
00070 FRAG_ID = 1,
00071 RANDOM = 2,
00072 DEAD_BEEF
00073 };
00074
00075
00076 using FragmentGenerator::getNext;
00077
00085 bool getNext(Fragment::sequence_id_t sequence_id,
00086 Fragment::fragment_id_t fragment_id,
00087 FragmentPtr& frag_ptr);
00088
00094 bool getNext(FragmentPtrs& output) override
00095 {
00096 return getNext_(output);
00097 }
00098
00103 std::vector<Fragment::fragment_id_t> fragmentIDs() override
00104 {
00105 return fragmentIDs_();
00106 }
00107
00108 private:
00109 bool getNext_(FragmentPtrs& output);
00110
00111 std::vector<Fragment::fragment_id_t> fragmentIDs_();
00112
00113 std::size_t generateFragmentSize_();
00114
00115
00116 content_selector_t const content_selection_;
00117 std::size_t const payload_size_spec_;
00118 std::vector<Fragment::fragment_id_t> fragment_ids_;
00119
00120 bool const want_random_payload_size_;
00121
00122
00123 std::size_t current_event_num_;
00124 std::mt19937 engine_;
00125 std::poisson_distribution<size_t> payload_size_generator_;
00126 std::uniform_int_distribution<uint64_t> fragment_content_generator_;
00127 };
00128
00129 #endif