DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DAPHNEFrame.hpp
Go to the documentation of this file.
1
14
15#ifndef FDDETDATAFORMATS_INCLUDE_FDDETDATAFORMATS_DAPHNEFRAME_HPP_
16#define FDDETDATAFORMATS_INCLUDE_FDDETDATAFORMATS_DAPHNEFRAME_HPP_
17
20
22#include <algorithm> // For std::min
23#include <cassert> // For assert()
24#include <cstdint> // For uint32_t etc
25#include <cstdio>
26#include <cstdlib>
27#include <stdexcept> // For std::out_of_range
28
30
31// NOLINTBEGIN(build/unsigned)
32
34{
35 // The definition of the format is in terms of 32-bit words
36 using word_t = uint32_t;
37
38 // Dataframe format version
39 static constexpr uint8_t version = 2;
40
41 static constexpr int s_bits_per_adc = 14;
42 static constexpr int s_bits_per_word = 8 * sizeof(word_t);
43 static constexpr int s_num_adcs = 1024;
45
46 struct Header
47 {
51 };
52 static_assert(sizeof(Header) == 8);
53
55 {
56 static constexpr std::size_t s_expected_bytes { 13 * sizeof(uint32_t) };
57
58 // Word 1: peak 0 odd
59 // Declared in reverse order (LSB first) so that:
60 // - num_subpeaks_0 occupies bits [3:0]
61 // - reserved_0 occupies bits [7:4]
62 // - adc_integral_0 occupies bits [30:8]
63 // - found_0 occupies bit [31]
64 word_t num_subpeaks_0 : 4; // Num_SubPeaks [3:0]
65 word_t reserved_0 : 4; // Reserved [7:4]
66 word_t adc_integral_0 : 23; // ADC_Integral [30:8]
67 word_t found_0 : 1; // Found [31]
68
69 // Word 2: peak 0 even
70 // Declared (LSB first) so that:
71 // - adc_max_0 occupies bits [13:0]
72 // - sample_max_0 occupies bits [22:14]
73 // - samples_over_baseline_0 occupies bits [31:23]
74 word_t adc_max_0 : 14; // ADC Max [13:0]
75 word_t sample_max_0 : 9; // Time_Peak [22:14]
76 word_t samples_over_baseline_0 : 9; // Time_Over_Baseline [31:23]
77
78 // Word 3: peak 1 odd
79 word_t num_subpeaks_1 : 4; // Num_SubPeaks [3:0]
80 word_t reserved_1 : 4; // Reserved [7:4]
81 word_t adc_integral_1 : 23; // ADC_Integral [30:8]
82 word_t found_1 : 1; // Found [31]
83
84 // Word 4: peak 1 even
85 word_t adc_max_1 : 14; // ADC Max [13:0]
86 word_t sample_max_1 : 9; // Time_Peak [22:14]
87 word_t samples_over_baseline_1 : 9; // Time_Over_Baseline [31:23]
88
89 // Word 5: peak 2 odd
90 word_t num_subpeaks_2 : 4; // Num_SubPeaks [3:0]
91 word_t reserved_2 : 4; // Reserved [7:4]
92 word_t adc_integral_2 : 23; // ADC_Integral [30:8]
93 word_t found_2 : 1; // Found [31]
94
95 // Word 6: peak 2 even
96 word_t adc_max_2 : 14; // ADC Max [13:0]
97 word_t sample_max_2 : 9; // Time_Peak [22:14]
98 word_t samples_over_baseline_2 : 9; // Time_Over_Baseline [31:23]
99
100 // Word 7: peak 3 odd
101 word_t num_subpeaks_3 : 4; // Num_SubPeaks [3:0]
102 word_t reserved_3 : 4; // Reserved [7:4]
103 word_t adc_integral_3 : 23; // ADC_Integral [30:8]
104 word_t found_3 : 1; // Found [31]
105
106 // Word 8: peak 3 even
107 word_t adc_max_3 : 14; // ADC Max [13:0]
108 word_t sample_max_3 : 9; // Time_Peak [22:14]
109 word_t samples_over_baseline_3 : 9; // Time_Over_Baseline [31:23]
110
111 // Word 9: peak 4 odd
112 word_t num_subpeaks_4 : 4; // Num_SubPeaks [3:0]
113 word_t reserved_4 : 4; // Reserved [7:4]
114 word_t adc_integral_4 : 23; // ADC_Integral [30:8]
115 word_t found_4 : 1; // Found [31]
116
117 // Word 10: peak 4 even
118 word_t adc_max_4 : 14; // ADC Max [13:0]
119 word_t sample_max_4 : 9; // Time_Peak [22:14]
120 word_t samples_over_baseline_4 : 9; // Time_Over_Baseline [31:23]
121
122 // Word 11: Time_Start fields for indices 0,1,2 and Reserved
123 // Declared in LSB-first order:
124 // - samples_start_2 occupies bits [11:2]
125 // - samples_start_1 occupies bits [21:12]
126 // - samples_start_0 occupies bits [31:22]
127 // - reserved_5 occupies bits [1:0]
128 word_t samples_start_2 : 10; // Time_Start(2) [11:2]
129 word_t samples_start_1 : 10; // Time_Start(1) [21:12]
130 word_t samples_start_0 : 10; // Time_Start(0) [31:22]
131 word_t reserved_5 : 2; // Reserved [1:0]
132
133 // Word 12: Time_Start fields for indices 3,4 and Reserved
134 // Declared in LSB-first order:
135 // - reserved_6 occupies bits [11:0]
136 // - samples_start_4 occupies bits [21:12]
137 // - samples_start_3 occupies bits [31:22]
138 word_t reserved_6 : 12; // Reserved [11:0]
139 word_t samples_start_4 : 10; // Time_Start(4) [21:12]
140 word_t samples_start_3 : 10; // Time_Start(3) [31:22]
141
142 // Word 13: Trailer word (all 32 bits), typically 0xFFFFFFFF.
144
145 static const uint8_t max_peaks = 5;
146
151 bool is_found(int idx) const;
152
154 void set_found(uint8_t val, int idx);
155
160 uint32_t get_adc_integral(int idx) const;
161
163 void set_adc_integral(uint32_t val, int idx);
164
169 uint8_t get_num_subpeaks(int idx) const;
170
172 void set_num_subpeaks(uint8_t val, int idx);
173
178 uint16_t get_samples_over_baseline(int idx) const;
179
180 // @brief Set the Time_Over_Baseline value for a specific peak.
181 void set_samples_over_baseline(uint16_t val, int idx);
182
187 uint16_t get_sample_max(int idx) const;
188
190 void set_sample_max(uint16_t val, int idx);
191
196 uint16_t get_adc_max(int idx) const;
197
199 void set_adc_max(uint16_t val, int idx);
200
213
214 uint16_t get_sample_start(int idx) const;
215
227 void set_sample_start(uint16_t val, int idx);
228
229 // ===============================================================
230 // Helper: Reinterpret Trailer as an array of word_t
231 // ===============================================================
232 const word_t* as_words() const
233 {
234 return reinterpret_cast<const word_t*>(this); // NOLINT
235 }
237 {
238 return reinterpret_cast<word_t*>(this); // NOLINT
239 }
240 };
241 static_assert(sizeof(PeakDescriptorData) == PeakDescriptorData::s_expected_bytes);
242
243 static constexpr std::size_t s_expected_bytes { sizeof(detdataformats::DAQHeader) + sizeof(Header) +
245
253 uint16_t get_adc(int i) const;
254
256 void set_adc(int i, uint16_t val);
257
258 uint8_t get_channel() const { return header.channel; }
259 void set_channel(uint8_t val) { header.channel = val & 0x3Fu; }
260
262 uint64_t get_timestamp() const { return daq_header.get_timestamp(); }
263
264 void set_timestamp(uint64_t ts) {
265 daq_header.timestamp_1 = ts;
266 daq_header.timestamp_2 = ts >> 32;
267 }
268
269 bool operator<(const DAPHNEFrame& other) const {
270
271 if (this->get_timestamp() != other.get_timestamp()) {
272 return this->get_timestamp() < other.get_timestamp();
273 } else {
274 return this->get_channel() < other.get_channel();
275 }
276 }
277
282};
283
284static_assert(std::endian::native == std::endian::little,
285 "The DAPHNEFrame bitfield layout assumes little-endian architecture");
286
287 static_assert(AdaptableFrameConcept<DAPHNEFrame>, "DAPHNEFrame does not satisfy the AdaptableFrameConcept");
288
289} // namespace dunedaq::fddetdataformats
290
291#include "detail/DAPHNEFrame.hxx"
292
293// NOLINTEND(build/unsigned)
294
295#endif // FDDETDATAFORMATS_INCLUDE_FDDETDATAFORMATS_DAPHNEFRAME_HPP_
DAQHeader is a versioned and unified structure for every FE electronics.
Definition DAQHeader.hpp:23
bool is_found(int idx) const
Get the Found value for a specific peak (channel) from the trailer. (Word 2*idx, bit 31).
void set_adc_integral(uint32_t val, int idx)
Set the ADC_Integral value for a specific peak.
uint16_t get_adc_max(int idx) const
Get the ADC Max value for a specific peak. (Word 2*idx+1, bits [31:18]).
void set_num_subpeaks(uint8_t val, int idx)
Set the Num_SubPeaks value for a specific peak.
uint16_t get_sample_start(int idx) const
Get the Time_Start value for a given index (0-4).
uint16_t get_sample_max(int idx) const
Get the Time_Peak value for a specific peak. (Word 2*idx+1, bits [17:9]).
void set_sample_max(uint16_t val, int idx)
Set the Time_Peak value for a specific peak.
void set_found(uint8_t val, int idx)
Set the Found value for a specific peak (channel) in the trailer.
uint32_t get_adc_integral(int idx) const
Get the ADC_Integral value for a specific peak. (Word 2*idx, bits [30:8]).
void set_sample_start(uint16_t val, int idx)
Set the time_start field for Peak index 0–4 using bit shifts.
void set_adc_max(uint16_t val, int idx)
Set the ADC Max value for a specific peak.
uint8_t get_num_subpeaks(int idx) const
Get the Num_SubPeaks value for a specific peak. (Word 2*idx, bits [3:0]).
uint16_t get_samples_over_baseline(int idx) const
Get the Time_Over_Baseline value for a specific peak. (Word 2*idx+1, bits [8:0]).
detdataformats::DAQHeader daq_header
void set_adc(int i, uint16_t val)
Set the ith ADC value in the frame to val.
uint64_t get_timestamp() const
Get the 64-bit timestamp of the frame.
static constexpr std::size_t s_expected_bytes
uint16_t get_adc(int i) const
Get the ith ADC value in the frame.
bool operator<(const DAPHNEFrame &other) const