DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
SourceEmulatorModel.hpp
Go to the documentation of this file.
1
8#ifndef DATAHANDLINGLIBS_INCLUDE_DATAHANDLINGLIBS_MODELS_SOURCEEMULATORMODEL_HPP_
9#define DATAHANDLINGLIBS_INCLUDE_DATAHANDLINGLIBS_MODELS_SOURCEEMULATORMODEL_HPP_
10
12#include "iomanager/Sender.hpp"
13
14#include "logging/Logging.hpp"
15
17#include "confmodel/GeoId.hpp"
18
26
28
29#include "unistd.h"
30#include <chrono>
31#include <functional>
32#include <memory>
33#include <random>
34#include <stdexcept>
35#include <string>
36#include <utility>
37#include <vector>
38
41
42namespace dunedaq {
43namespace datahandlinglibs {
44
45// Pattern generator class for creating different types of TP patterns
46// AAA: at the moment the pattern generator is very simple: random source id and random channel
48{
49
50public:
53
54 void generate(int, int);
55
57 {
58 if (m_index == m_channel.size())
59 m_index = 0;
60 return m_channel[m_index++];
61 }
62
63private:
64 std::vector<int> m_channel;
65 int m_index = 0;
66};
67
68template<class ReadoutType>
70{
71public:
72 explicit SourceEmulatorModel(std::string name,
73 std::atomic<bool>& run_marker,
74 uint64_t time_tick_diff, // NOLINT(build/unsigned)
75 double dropout_rate,
76 double frame_error_rate,
77 double rate_khz,
78 uint16_t frames_per_tick = 1)
80 , m_time_tick_diff(time_tick_diff)
81 , m_dropout_rate(dropout_rate)
82 , m_frame_error_rate(frame_error_rate)
83 , m_packet_count{ 0 }
85 , m_name(name)
86 , m_rate_khz(rate_khz)
87 , m_frames_per_tick(frames_per_tick)
88 {
89 }
90
91 // void init(const appfwk::DAQModule::CommandData_t& /*args*/) {}
92 void acquire_callback() override;
93
94 void conf(const confmodel::DetectorStream* stream_conf, const appmodel::StreamEmulationParameters* emu_conf);
95 void scrap(const appfwk::DAQModule::CommandData_t& /*args*/)
96 {
97 m_file_source.reset();
98 m_is_configured = false;
99 }
100 bool is_configured() override { return m_is_configured; }
101
102 void start(const appfwk::DAQModule::CommandData_t& /*args*/);
103 void stop(const appfwk::DAQModule::CommandData_t& /*args*/);
104 // void get_info(opmonlib::InfoCollector& ci, int /*level*/);
105
106protected:
107 // The data emulator function that the worker thread runs
108 void run_produce();
109 virtual void generate_opmon_data() override;
110
111private:
112 // Constuctor params
113 std::atomic<bool>& m_run_marker;
114
115 // CONFIGURATION
116 uint32_t m_this_apa_number; // NOLINT(build/unsigned)
117 uint32_t m_this_link_number; // NOLINT(build/unsigned)
118
119 uint64_t m_time_tick_diff; // NOLINT(build/unsigned)
122
123 // STATS
124 std::atomic<int> m_packet_count{ 0 };
125 std::atomic<int> m_packet_count_tot{ 0 };
126
127 // sourceemulatorconfig::Conf m_cfg;
128
129 bool m_sender_is_set = false;
130 std::shared_ptr<std::function<void(ReadoutType&&)>> m_raw_data_callback;
131 // using module_conf_t = dunedaq::datahandlinglibs::sourceemulatorconfig::Conf;
132 // module_conf_t m_conf;
133 // using link_conf_t = dunedaq::datahandlinglibs::sourceemulatorconfig::LinkConfiguration;
134 // link_conf_t m_link_conf;
135
136 std::unique_ptr<RateLimiter> m_rate_limiter;
137 std::unique_ptr<FileSourceBuffer> m_file_source;
139
141
142 std::string m_name;
143 bool m_is_configured = false;
146
147 std::vector<bool> m_dropouts; // Random population
148 std::vector<bool> m_frame_errors;
149
150 uint m_dropouts_length; // NOLINT(build/unsigned) Random population size
156
158 // Pattern generator configs
161 // Adding a hit every 9768 gives a TP rate of approx 100 Hz/wire using WIBEthernet
162 uint32_t m_time_to_wait = 9768;
163};
164
165} // namespace datahandlinglibs
166} // namespace dunedaq
167
168// Declarations
170
171#endif // DATAHANDLINGLIBS_INCLUDE_DATAHANDLINGLIBS_MODELS_SOURCEEMULATORMODEL_HPP_
SourceEmulatorModel(std::string name, std::atomic< bool > &run_marker, uint64_t time_tick_diff, double dropout_rate, double frame_error_rate, double rate_khz, uint16_t frames_per_tick=1)
void stop(const appfwk::DAQModule::CommandData_t &)
void conf(const confmodel::DetectorStream *stream_conf, const appmodel::StreamEmulationParameters *emu_conf)
void start(const appfwk::DAQModule::CommandData_t &)
std::shared_ptr< std::function< void(ReadoutType &&)> > m_raw_data_callback
void scrap(const appfwk::DAQModule::CommandData_t &)
std::unique_ptr< FileSourceBuffer > m_file_source
std::atomic< bool > run_marker
Global atomic for process lifetime.
The DUNE-DAQ namespace.
SourceID is a generalized representation of the source of a piece of data in the DAQ....
Definition SourceID.hpp:32