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 <string>
35#include <utility>
36#include <vector>
37
40
41namespace dunedaq {
42namespace datahandlinglibs {
43
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
49public:
53
54 void generate(int, int);
55
57 if (m_index == m_channel.size()) m_index = 0;
58 return m_channel[m_index++];
59 }
60
61private:
62 std::vector<int> m_channel;
63 int m_index = 0;
64};
65
66
67template<class ReadoutType>
69{
70public:
71 explicit SourceEmulatorModel(std::string name,
72 std::atomic<bool>& run_marker,
73 uint64_t time_tick_diff, // NOLINT(build/unsigned)
74 double dropout_rate,
75 double frame_error_rate,
76 double rate_khz,
77 uint16_t frames_per_tick=1)
79 , m_time_tick_diff(time_tick_diff)
80 , m_dropout_rate(dropout_rate)
81 , m_frame_error_rate(frame_error_rate)
82 , m_packet_count{ 0 }
84 , m_name(name)
85 , m_rate_khz(rate_khz)
86 ,m_frames_per_tick(frames_per_tick)
87 {}
88
89 //void init(const appfwk::DAQModule::CommandData_t& /*args*/) {}
91
92 void conf(const confmodel::DetectorStream* stream_conf, const appmodel::StreamEmulationParameters* emu_conf);
93 void scrap(const appfwk::DAQModule::CommandData_t& /*args*/)
94 {
95 m_file_source.reset();
96 m_is_configured = false;
97 }
98 bool is_configured() override { return m_is_configured; }
99
100 void start(const appfwk::DAQModule::CommandData_t& /*args*/);
101 void stop(const appfwk::DAQModule::CommandData_t& /*args*/);
102 // void get_info(opmonlib::InfoCollector& ci, int /*level*/);
103
104protected:
105 // The data emulator function that the worker thread runs
106 void run_produce();
107 virtual void generate_opmon_data() override;
108
109private:
110 // Constuctor params
111 std::atomic<bool>& m_run_marker;
112
113 // CONFIGURATION
114 uint32_t m_this_apa_number; // NOLINT(build/unsigned)
115 uint32_t m_this_link_number; // NOLINT(build/unsigned)
116
117 uint64_t m_time_tick_diff; // NOLINT(build/unsigned)
120
121 // STATS
122 std::atomic<int> m_packet_count{ 0 };
123 std::atomic<int> m_packet_count_tot{ 0 };
124
125 //sourceemulatorconfig::Conf m_cfg;
126
127 bool m_sender_is_set = false;
128 std::shared_ptr<std::function<void(ReadoutType&&)>> m_raw_data_callback;
129 //using module_conf_t = dunedaq::datahandlinglibs::sourceemulatorconfig::Conf;
130 //module_conf_t m_conf;
131 //using link_conf_t = dunedaq::datahandlinglibs::sourceemulatorconfig::LinkConfiguration;
132 //link_conf_t m_link_conf;
133
134 std::unique_ptr<RateLimiter> m_rate_limiter;
135 std::unique_ptr<FileSourceBuffer> m_file_source;
137
139
140 std::string m_name;
141 bool m_is_configured = false;
144
145 std::vector<bool> m_dropouts; // Random population
146 std::vector<bool> m_frame_errors;
147
148 uint m_dropouts_length; // NOLINT(build/unsigned) Random population size
154
156 // Pattern generator configs
160 // Adding a hit every 9768 gives a TP rate of approx 100 Hz/wire using WIBEthernet
161 uint32_t m_time_to_wait = 9768;
162};
163
164} // namespace datahandlinglibs
165} // namespace dunedaq
166
167// Declarations
169
170#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 &)
void set_sender(const appmodel::DataMoveCallbackConf *conf)
std::unique_ptr< FileSourceBuffer > m_file_source
std::atomic< bool > run_marker
Global atomic for process lifetime.
Including Qt Headers.
SourceID is a generalized representation of the source of a piece of data in the DAQ....
Definition SourceID.hpp:32