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
25
27
28#include "unistd.h"
29#include <chrono>
30#include <functional>
31#include <memory>
32#include <random>
33#include <string>
34#include <utility>
35#include <vector>
36
39
40namespace dunedaq {
41namespace datahandlinglibs {
42
43
44// Pattern generator class for creating different types of TP patterns
45// AAA: at the moment the pattern generator is very simple: random source id and random channel
47
48public:
52
53 void generate(int, int);
54
56 if (m_index == m_channel.size()) m_index = 0;
57 return m_channel[m_index++];
58 }
59
60private:
61 std::vector<int> m_channel;
62 int m_index = 0;
63};
64
65
66template<class ReadoutType>
68{
69public:
70 explicit SourceEmulatorModel(std::string name,
71 std::atomic<bool>& run_marker,
72 uint64_t time_tick_diff, // NOLINT(build/unsigned)
73 double dropout_rate,
74 double frame_error_rate,
75 double rate_khz,
76 uint16_t frames_per_tick=1)
78 , m_time_tick_diff(time_tick_diff)
79 , m_dropout_rate(dropout_rate)
80 , m_frame_error_rate(frame_error_rate)
81 , m_packet_count{ 0 }
83 , m_raw_data_sender(nullptr)
85 , m_name(name)
86 , m_rate_khz(rate_khz)
87 ,m_frames_per_tick(frames_per_tick)
88 {}
89
90 //void init(const nlohmann::json& /*args*/) {}
91 void set_sender(const std::string& conn_name);
92
93 void conf(const confmodel::DetectorStream* stream_conf, const appmodel::StreamEmulationParameters* emu_conf);
94 void scrap(const nlohmann::json& /*args*/)
95 {
96 m_file_source.reset();
97 m_is_configured = false;
98 }
99 bool is_configured() override { return m_is_configured; }
100
101 void start(const nlohmann::json& /*args*/);
102 void stop(const nlohmann::json& /*args*/);
103 // void get_info(opmonlib::InfoCollector& ci, int /*level*/);
104
105protected:
106 // The data emulator function that the worker thread runs
107 void run_produce();
108 virtual void generate_opmon_data() override;
109
110private:
111 // Constuctor params
112 std::atomic<bool>& m_run_marker;
113
114 // CONFIGURATION
115 uint32_t m_this_apa_number; // NOLINT(build/unsigned)
116 uint32_t m_this_link_number; // NOLINT(build/unsigned)
117
118 uint64_t m_time_tick_diff; // NOLINT(build/unsigned)
121
122 // STATS
123 std::atomic<int> m_packet_count{ 0 };
124 std::atomic<int> m_packet_count_tot{ 0 };
125
126 //sourceemulatorconfig::Conf m_cfg;
127
128 // RAW SENDER
129 std::chrono::milliseconds m_raw_sender_timeout_ms;
131 std::shared_ptr<raw_sender_ct> m_raw_data_sender;
132
133 bool m_sender_is_set = false;
134 //using module_conf_t = dunedaq::datahandlinglibs::sourceemulatorconfig::Conf;
135 //module_conf_t m_conf;
136 //using link_conf_t = dunedaq::datahandlinglibs::sourceemulatorconfig::LinkConfiguration;
137 //link_conf_t m_link_conf;
138
139 std::unique_ptr<RateLimiter> m_rate_limiter;
140 std::unique_ptr<FileSourceBuffer> m_file_source;
142
144
145 std::string m_name;
146 bool m_is_configured = false;
149
150 std::vector<bool> m_dropouts; // Random population
151 std::vector<bool> m_frame_errors;
152
153 uint m_dropouts_length; // NOLINT(build/unsigned) Random population size
159
161 // Pattern generator configs
165 // Adding a hit every 9768 gives a TP rate of approx 100 Hz/wire using WIBEthernet
166 uint32_t m_time_to_wait = 9768;
167};
168
169} // namespace datahandlinglibs
170} // namespace dunedaq
171
172// Declarations
174
175#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 conf(const confmodel::DetectorStream *stream_conf, const appmodel::StreamEmulationParameters *emu_conf)
void set_sender(const std::string &conn_name)
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