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 162 of file Utils.hpp.

163{
164
165 static_assert(std::is_integral_v<WordType> && std::is_unsigned_v<WordType>,
166 "WordType must be an unsigned integral type");
167
168 constexpr int bits_per_word = std::numeric_limits<WordType>::digits; // Fine since we know integer is unsigned
169
170 static_assert(BitsPerADC > 0);
171 constexpr int num_adcs = NWords * bits_per_word / BitsPerADC;
172
174}
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 185 of file Utils.hpp.

188{
189
190 if (i_sample < 0 || i_sample >= Rows) {
191 throw std::out_of_range(
192 std::format("Requested index of {}th 1-d ADC array is outside of allowed range 0-{}", i_sample, Rows - 1));
193 }
194
195 return get_adc_1d<WordType, Columns, BitsPerADC>(i_adc, adc_matrix[i_sample]);
196}
WordType get_adc_1d(const int i_adc, const WordType(&adc_array)[NWords])
Definition Utils.hpp:162

◆ 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.

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

◆ 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 203 of file Utils.hpp.

204{
205 static_assert(std::is_integral_v<WordType> && std::is_unsigned_v<WordType>,
206 "WordType must be an unsigned integral type");
207
208 constexpr int bits_per_word = std::numeric_limits<WordType>::digits; // Fine since we know integer is unsigned
209
210 static_assert(BitsPerADC > 0 && BitsPerADC <= bits_per_word);
211 static_assert((NWords * bits_per_word) % BitsPerADC == 0);
212
213 constexpr int num_adcs = NWords * bits_per_word / BitsPerADC;
214
216}
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:97

◆ 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 224 of file Utils.hpp.

228{
229 if (i_sample < 0 || i_sample >= Rows) {
230 throw std::out_of_range(
231 std::format("Requested index of {}th 1-d ADC array is outside of allowed range 0-{}", i_sample, Rows - 1));
232 }
233
234 set_adc_1d<WordType, Columns, BitsPerADC>(i_adc, adc_val, adc_matrix[i_sample]);
235}
void set_adc_1d(const int i_adc, WordType adc_val, WordType(&adc_array)[NWords])
Definition Utils.hpp:203

◆ 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 97 of file Utils.hpp.

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