DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::fddetdataformats Namespace Reference

Namespaces

namespace  python

Classes

struct  CRTBernFrame
 Struct for accessing/holding raw CRT data from the 'Bern' panels ProtoDUNE-II VD. More...
struct  CRTGrenobleFrame
 Struct for accessing/holding raw CRT data from the 'Grenoble' panels ProtoDUNE-II VD. More...
struct  DAPHNEEthFrame
 Struct for accessing raw DAPHNE eth frames. More...
struct  DAPHNEEthStreamFrame
 Struct for accessing raw DAPHNE eth stream frames. More...
struct  DAPHNEFrame
struct  DAPHNEStreamFrame
struct  TDEEthFrame
 Struct for accessing raw TDE eth frames, as used in ProtoDUNE-II. More...
struct  WIBEthFrame
 struct for accessing raw WIB eth frames, as used in ProtoDUNE-II More...

Concepts

concept  HasGetADC
concept  HasSetADC
concept  HasDAQHeader
concept  HasFrameHeader
concept  HasLessThan
concept  HasNoCompilerPadding
concept  HasGetTimestamp
concept  HasSetTimestamp
concept  AdaptableFrameConcept

Functions

template<typename WordType, int NWords, int BitsPerADC, int ADCSPerChannel, int NChannels>
WordType get_adc_2d_as_1d (const int i_adc, const int i_channel, const WordType(&adc_matrix)[NWords])
template<typename WordType, int NWords, int BitsPerADC, int ADCSPerChannel, int NChannels>
void set_adc_2d_as_1d (const int i_adc, const int i_channel, const WordType adc_val, WordType(&adc_matrix)[NWords])
template<typename WordType, int NWords, int BitsPerADC>
WordType get_adc_1d (const int i_adc, const WordType(&adc_array)[NWords])
template<typename WordType, int Rows, int Columns, int BitsPerADC>
WordType get_adc_2d (const int i_sample, const int i_adc, const WordType(&adc_matrix)[Rows][Columns])
template<typename WordType, int NWords, int BitsPerADC>
void set_adc_1d (const int i_adc, WordType adc_val, WordType(&adc_array)[NWords])
template<typename WordType, int Rows, int Columns, int BitsPerADC>
void set_adc_2d (const int i_sample, const int i_adc, WordType adc_val, WordType(&adc_matrix)[Rows][Columns])

Function Documentation

◆ get_adc_1d()

template<typename WordType, int NWords, int BitsPerADC>
WordType dunedaq::fddetdataformats::get_adc_1d ( const int i_adc,
const WordType(&) adc_array[NWords] )

Definition at line 157 of file Utils.hpp.

158{
159
160 static_assert(std::is_integral_v<WordType> && std::is_unsigned_v<WordType>,
161 "WordType must be an unsigned integral type");
162
163 constexpr int bits_per_word = std::numeric_limits<WordType>::digits; // Fine since we know integer is unsigned
164
165 static_assert(BitsPerADC > 0);
166 constexpr int num_adcs = NWords * bits_per_word / BitsPerADC;
167
169}
WordType get_adc_2d_as_1d(const int i_adc, const int i_channel, const WordType(&adc_matrix)[NWords])
Definition Utils.hpp:41

◆ get_adc_2d()

template<typename WordType, int Rows, int Columns, int BitsPerADC>
WordType dunedaq::fddetdataformats::get_adc_2d ( const int i_sample,
const int i_adc,
const WordType(&) adc_matrix[Rows][Columns] )

Definition at line 180 of file Utils.hpp.

181{
182
183 if (i_sample < 0 || i_sample >= Rows) {
184 throw std::out_of_range(
185 std::format("Requested index of {}th 1-d ADC array is outside of allowed range 0-{}", i_sample, Rows - 1));
186 }
187
188 return get_adc_1d<WordType, Columns, BitsPerADC>(i_adc, adc_matrix[i_sample]);
189}
WordType get_adc_1d(const int i_adc, const WordType(&adc_array)[NWords])
Definition Utils.hpp:157

◆ get_adc_2d_as_1d()

template<typename WordType, int NWords, int BitsPerADC, int ADCSPerChannel, int NChannels>
WordType dunedaq::fddetdataformats::get_adc_2d_as_1d ( const int i_adc,
const int i_channel,
const WordType(&) adc_matrix[NWords] )

Definition at line 41 of file Utils.hpp.

42{
43
44 static_assert(std::is_integral_v<WordType> && std::is_unsigned_v<WordType>,
45 "WordType must be an unsigned integral type");
46
47 constexpr int bits_per_word = std::numeric_limits<WordType>::digits; // Fine since we know integer is unsigned
48
49 static_assert(BitsPerADC > 0 && BitsPerADC <= bits_per_word);
50 static_assert(ADCSPerChannel * NChannels * BitsPerADC == NWords * bits_per_word);
51
52 if (i_channel < 0 || i_channel >= NChannels) {
53 throw std::out_of_range(
54 std::format("Requested channel of {} is out of channel range 0-{}", i_channel, NChannels - 1));
55 }
56
57 if (i_adc < 0 || i_adc >= ADCSPerChannel) {
58 throw std::out_of_range(std::format("Requested ADC index of {} if out of range 0-{}", i_adc, ADCSPerChannel - 1));
59 }
60
61 // find absolute index in frame
62 int i_abs = i_adc * NChannels + i_channel;
63
64 if constexpr (BitsPerADC == bits_per_word) {
65 return adc_matrix[i_abs];
66 } else {
67
68 // The index of the first (and sometimes only) word containing the required ADC value
69 int i_word = BitsPerADC * i_abs / bits_per_word;
70 assert(i_word < NWords);
71
72 // Where in the word the lowest bit of our ADC value is located
73 int first_bit_position = (BitsPerADC * i_abs) % bits_per_word;
74
75 // How many bits of our desired ADC are located in the `i_word`th word
76 int bits_from_first_word = std::min(BitsPerADC, bits_per_word - first_bit_position);
77
78 WordType adc_val = adc_matrix[i_word] >> first_bit_position; // NOLINT(build/unsigned)
79
80 if (bits_from_first_word < BitsPerADC) {
81 assert(i_word < NWords - 1);
82 adc_val |= adc_matrix[i_word + 1] << bits_from_first_word;
83 }
84
85 // Mask out all but the lowest BitsPerADC bits;
86 return adc_val & ((static_cast<WordType>(1) << BitsPerADC) - 1);
87
88 } // if BitsPerADC != bits_per_word
89}

◆ set_adc_1d()

template<typename WordType, int NWords, int BitsPerADC>
void dunedaq::fddetdataformats::set_adc_1d ( const int i_adc,
WordType adc_val,
WordType(&) adc_array[NWords] )

Definition at line 196 of file Utils.hpp.

197{
198 static_assert(std::is_integral_v<WordType> && std::is_unsigned_v<WordType>,
199 "WordType must be an unsigned integral type");
200
201 constexpr int bits_per_word = std::numeric_limits<WordType>::digits; // Fine since we know integer is unsigned
202
203 static_assert(BitsPerADC > 0 && BitsPerADC <= bits_per_word);
204 static_assert((NWords * bits_per_word) % BitsPerADC == 0);
205
206 constexpr int num_adcs = NWords * bits_per_word / BitsPerADC;
207
209}
void set_adc_2d_as_1d(const int i_adc, const int i_channel, const WordType adc_val, WordType(&adc_matrix)[NWords])
Definition Utils.hpp:95

◆ set_adc_2d()

template<typename WordType, int Rows, int Columns, int BitsPerADC>
void dunedaq::fddetdataformats::set_adc_2d ( const int i_sample,
const int i_adc,
WordType adc_val,
WordType(&) adc_matrix[Rows][Columns] )

Definition at line 217 of file Utils.hpp.

218{
219 if (i_sample < 0 || i_sample >= Rows) {
220 throw std::out_of_range(
221 std::format("Requested index of {}th 1-d ADC array is outside of allowed range 0-{}", i_sample, Rows - 1));
222 }
223
224 set_adc_1d<WordType, Columns, BitsPerADC>(i_adc, adc_val, adc_matrix[i_sample]);
225}
void set_adc_1d(const int i_adc, WordType adc_val, WordType(&adc_array)[NWords])
Definition Utils.hpp:196

◆ set_adc_2d_as_1d()

template<typename WordType, int NWords, int BitsPerADC, int ADCSPerChannel, int NChannels>
void dunedaq::fddetdataformats::set_adc_2d_as_1d ( const int i_adc,
const int i_channel,
const WordType adc_val,
WordType(&) adc_matrix[NWords] )

Definition at line 95 of file Utils.hpp.

96{
97 static_assert(std::is_integral_v<WordType> && std::is_unsigned_v<WordType>,
98 "WordType must be an unsigned integral type");
99
100 constexpr int bits_per_word = std::numeric_limits<WordType>::digits; // Fine since we know integer is unsigned
101
102 static_assert(BitsPerADC > 0 && BitsPerADC <= bits_per_word);
103 static_assert(ADCSPerChannel * NChannels * BitsPerADC == NWords * bits_per_word);
104
105 if (i_channel < 0 || i_channel >= NChannels) {
106 throw std::out_of_range(
107 std::format("Requested channel of {} is out of channel range 0-{}", i_channel, NChannels - 1));
108 }
109
110 if (i_adc < 0 || i_adc >= ADCSPerChannel) {
111 throw std::out_of_range(std::format("Requested ADC index of {} is out of range 0-{}", i_adc, ADCSPerChannel - 1));
112 }
113
114 if constexpr (BitsPerADC < bits_per_word) {
115 if (adc_val >= (static_cast<WordType>(1) << BitsPerADC)) {
116 throw std::out_of_range(std::format(
117 "Requested ADC value of {} exceeds max value of {}", adc_val, (static_cast<WordType>(1) << BitsPerADC) - 1));
118 }
119 }
120
121 // find absolute index in frame
122 int i_abs = i_adc * NChannels + i_channel;
123
124 if constexpr (BitsPerADC == bits_per_word) {
125 adc_matrix[i_abs] = adc_val;
126 } else {
127
128 // The index of the first (and sometimes only) word containing the required ADC value
129 int i_word = BitsPerADC * i_abs / bits_per_word;
130 assert(i_word < NWords);
131
132 // Where in the word the lowest bit of our ADC value is located
133 int first_bit_position = (BitsPerADC * i_abs) % bits_per_word;
134
135 // How many bits of our desired ADC are located in the `i_word`th word
136 int bits_in_first_word = std::min(BitsPerADC, bits_per_word - first_bit_position);
137
138 WordType mask = ((static_cast<WordType>(1) << bits_in_first_word) - 1) << first_bit_position;
139
140 adc_matrix[i_word] = (adc_matrix[i_word] & ~mask) | ((static_cast<WordType>(adc_val) << first_bit_position) & mask);
141
142 // If we didn't put the full 14 bits in this word, we need to put the rest in the next word
143 if (bits_in_first_word < BitsPerADC) {
144 assert(i_word < NWords - 1);
145 int bits_in_second_word = BitsPerADC - bits_in_first_word;
146 WordType mask2 = (static_cast<WordType>(1) << bits_in_second_word) - 1;
147 adc_matrix[i_word + 1] = (adc_matrix[i_word + 1] & ~mask2) | ((adc_val >> bits_in_first_word) & mask2);
148 }
149 } // BitsPerADC != bits_per_word
150}