DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DAPHNEFrame.hxx
Go to the documentation of this file.
1
3
4inline uint16_t
5DAPHNEFrame::get_adc(int i) const // NOLINT
6{
7 // We can safely case from word_t to uint16_t as the ADC value can always be represented in 16 bits
8 return static_cast<uint16_t>(
10}
11
12inline void
17
18// --- Trailer Accessors (Manual Shift–Mask Extraction) ---
19
20inline bool
21DAPHNEFrame::PeakDescriptorData::is_found(int idx) const // idx index 0 to 4
22{
23 if (idx < 0 || idx > 4)
24 throw std::out_of_range("Peak index out of range (must be 0-4)");
25 const word_t* tw = as_words();
26 // In odd word, Found is in bit 31.
27 return static_cast<uint8_t>((tw[2 * idx] >> 31) & 0x1); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
28}
29
30inline void
32{
33 if (idx < 0 || idx > 4)
34 throw std::out_of_range("peak index out of range (must be 0-4)");
35 if (val > 1)
36 throw std::out_of_range("Found value out of range (must be 0-1)");
37 word_t* tw = as_words();
38 tw[2 * idx] = // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
39 (tw[2 * idx] & ~(1u << 31)) | ((val & 0x1) << 31); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
40}
41
42inline uint32_t
44{
45 if (idx < 0 || idx > 4)
46 throw std::out_of_range("Peak index out of range (must be 0-4)");
47 const word_t* tw = as_words();
48 return (tw[2 * idx] >> 8) & 0x7FFFFF; // Mask 23 bits // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
49}
50
51inline void
53{
54 if (idx < 0 || idx > 4)
55 throw std::out_of_range("Peak index out of range (must be 0-4)");
56 if (val > 0x7FFFFF)
57 throw std::out_of_range("ADC_Integral value out of range (must be 0-8388607)");
58 word_t* tw = as_words();
59 tw[2 * idx] = (tw[2 * idx] & ~(0x7FFFFFu << 8)) | // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
60 ((val & 0x7FFFFF) << 8); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
61}
62
63inline uint8_t
65{
66 if (idx < 0 || idx > 4)
67 throw std::out_of_range("Peak index out of range (must be 0-4)");
68 const word_t* tw = as_words();
69 return static_cast<uint8_t>(tw[2 * idx] & 0xF); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
70}
71
72inline void
74{
75 if (idx < 0 || idx > 4)
76 throw std::out_of_range("Peak index out of range (must be 0-4)");
77 if (val > 0xF)
78 throw std::out_of_range("Num_SubPeaks value out of range (must be 0-15)");
79 word_t* tw = as_words();
80 tw[2 * idx] = (tw[2 * idx] & ~0xF) | (val & 0xF); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
81}
82
83inline uint16_t
85{
86 if (idx < 0 || idx > 4)
87 throw std::out_of_range("Peak index out of range (must be 0-4)");
88 const word_t* tw = as_words();
89 return static_cast<uint16_t>((tw[2 * idx + 1] >> 23) & // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
90 0x1FF); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
91}
92
93inline void
95{
96 if (idx < 0 || idx > 4)
97 throw std::out_of_range("Peak index out of range (must be 0-4)");
98 if (val > 0x1FF)
99 throw std::out_of_range("Time_Over_Baseline value out of range (must be 0-511)");
100 word_t* tw = as_words();
101 tw[2 * idx + 1] = (tw[2 * idx + 1] & ~(0x1FFu << 23)) | // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
102 ((val & 0x1FF) << 23); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
103}
104
105inline uint16_t
107{
108 if (idx < 0 || idx > 4)
109 throw std::out_of_range("Peak index out of range (must be 0-4)");
110 const word_t* tw = as_words();
111 return static_cast<uint16_t>((tw[2 * idx + 1] >> 14) & // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
112 0x1FF); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
113}
114
115inline void
117{
118 if (idx < 0 || idx > 4)
119 throw std::out_of_range("Peak index out of range (must be 0-4)");
120 if (val > 0x1FF)
121 throw std::out_of_range("Time_Peak value out of range (must be 0-511)");
122 word_t* tw = as_words();
123 tw[2 * idx + 1] = (tw[2 * idx + 1] & ~(0x1FFu << 14)) | // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
124 ((val & 0x1FF) << 14); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
125}
126
127inline uint16_t
129{
130 if (idx < 0 || idx > 4)
131 throw std::out_of_range("Peak index out of range (must be 0-4)");
132 const word_t* tw = as_words();
133 // Even word for idx is at index 2*idx+1; ADC Max is in bits 13:0.
134 return static_cast<uint16_t>(tw[2 * idx + 1] & 0x3FFF); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
135}
136
137inline void
139{
140 if (idx < 0 || idx > 4)
141 throw std::out_of_range("Peak index out of range (must be 0-4)");
142 if (val > 0x3FFF)
143 throw std::out_of_range("ADC Max value out of range (must be 0-16383)");
144 word_t* tw = as_words();
145 tw[2 * idx + 1] = // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
146 (tw[2 * idx + 1] & ~0x3FFFu) | (val & 0x3FFF); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
147}
148
149inline uint16_t
151{
152 if (idx < 0 || idx > 4)
153 throw std::out_of_range("Time_Start index out of range (must be 0-4)");
154
155 const word_t* tw = as_words();
156 if (idx < 3) {
157 int shift = 22 - 10 * idx;
158 return static_cast<uint16_t>((tw[10] >> shift) & 0x3FF); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
159 } else {
160 int shift = 22 - 10 * (idx - 3);
161 return static_cast<uint16_t>((tw[11] >> shift) & 0x3FF); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
162 }
163}
164
165inline void
167{
168 if (idx < 0 || idx > 4)
169 throw std::out_of_range("Time_Start index out of range (must be 0–4)");
170 if (val > 0x3FF)
171 throw std::out_of_range("Time_Start value out of range (must be 0–1023)");
172
173 word_t* tw = as_words();
174 word_t mask = 0x3FFu;
175
176 if (idx < 3) {
177 int shift = 22 - 10 * idx;
178 tw[10] = // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
179 (tw[10] & ~(mask << shift)) | ((val & mask) << shift); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
180 } else {
181 int shift = 22 - 10 * (idx - 3);
182 tw[11] = // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
183 (tw[11] & ~(mask << shift)) | ((val & mask) << shift); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
184 }
185}
186
187} // namespace dunedaq::fddetdataformats
void set_adc(int i, uint16_t val)
Set the ith ADC value in the frame to val.
uint16_t get_adc(int i) const
Get the ith ADC value in the frame.
WordType get_adc_1d(const int i_adc, const WordType(&adc_array)[NWords])
Definition Utils.hpp:156
void set_adc_1d(const int i_adc, WordType adc_val, WordType(&adc_array)[NWords])
Definition Utils.hpp:195
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]).