DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DAPHNEEthFrame.hpp
Go to the documentation of this file.
1
14#ifndef FDDETDATAFORMATS_INCLUDE_FDDETDATAFORMATS_DAPHNEETHFRAME_HPP_
15#define FDDETDATAFORMATS_INCLUDE_FDDETDATAFORMATS_DAPHNEETHFRAME_HPP_
16
18
19#include <algorithm> // For std::min
20#include <cassert> // For assert()
21#include <cstdint> // For uint32_t etc
22#include <cstdio>
23#include <cstdlib>
24#include <stdexcept> // For std::out_of_range
25
27
35{
36public:
37 // ===============================================================
38 // Preliminaries
39 // ===============================================================
40
41 // The definition of the format is in terms of 64-bit words
42 typedef uint64_t word_t; // NOLINT
43
44 // Dataframe format version
45 static constexpr uint8_t version = 1;
46
47 static constexpr int s_bits_per_adc = 14;
48 static constexpr int s_bits_per_word = 8 * sizeof(word_t);
49 static constexpr int s_num_adcs = 1024;
51
71
72 // ===============================================================
73 // Data members
74 // ===============================================================
78
79// ===============================================================
80// Accessors
81// ===============================================================
82
90uint16_t
91get_adc(int i) const // NOLINT
92{
93 if (i < 0 || i >= s_num_adcs)
94 throw std::out_of_range("ADC index out of range");
95
96 // The index of the first (and sometimes only) word containing the required ADC value
97 int word_index = s_bits_per_adc * i / s_bits_per_word;
98 assert(word_index < s_num_adc_words);
99 // Where in the word the lowest bit of our ADC value is located
100 int first_bit_position = (s_bits_per_adc * i) % s_bits_per_word;
101 // How many bits of our desired ADC are located in the `word_index`th word
102 int bits_from_first_word = std::min(s_bits_per_adc, s_bits_per_word - first_bit_position);
103 uint16_t adc = adc_words[word_index] >> first_bit_position; // NOLINT
104 // If we didn't get the full 14 bits from this word, we need the rest from the next word
105 if (bits_from_first_word < s_bits_per_adc) {
106 assert(word_index + 1 < s_num_adc_words);
107 adc |= adc_words[word_index + 1] << bits_from_first_word;
108 }
109 // Mask out all but the lowest 14 bits;
110 return adc & 0x3FFFu;
111}
112
116void
117set_adc(int i, uint16_t val) // NOLINT
118{
119 if (i < 0 || i >= s_num_adcs)
120 throw std::out_of_range("ADC index out of range");
121 if (val >= (1 << s_bits_per_adc))
122 throw std::out_of_range("ADC value out of range");
123
124 // The index of the first (and sometimes only) word containing the required ADC value
125 int word_index = s_bits_per_adc * i / s_bits_per_word;
126 assert(word_index < s_num_adc_words);
127 // Where in the word the lowest bit of our ADC value is located
128 int first_bit_position = (s_bits_per_adc * i) % s_bits_per_word;
129 // How many bits of our desired ADC are located in the `word_index`th word
130 int bits_in_first_word = std::min(s_bits_per_adc, s_bits_per_word - first_bit_position);
131 uint32_t mask = (1 << (first_bit_position)) - 1;
132 adc_words[word_index] = ((val << first_bit_position) & ~mask) | (adc_words[word_index] & mask);
133 // If we didn't put the full 14 bits in this word, we need to put the rest in the next word
134 if (bits_in_first_word < s_bits_per_adc) {
135 assert(word_index + 1 < s_num_adc_words);
136 mask = (1 << (s_bits_per_adc - bits_in_first_word)) - 1;
137 adc_words[word_index + 1] = ((val >> bits_in_first_word) & mask) | (adc_words[word_index + 1] & ~mask);
138 }
139}
140
143 uint64_t get_timestamp() const // NOLINT(build/unsigned)
144 {
145 return daq_header.get_timestamp() ; // NOLINT(build/unsigned)
146 }
147
150 void set_timestamp(const uint64_t new_timestamp) // NOLINT(build/unsigned)
151 {
152 daq_header.timestamp = new_timestamp;
153 }
154
157 uint8_t get_channel() const // NOLINT(build/unsigned)
158 {
159 return header.channel ; // NOLINT(build/unsigned)
160 }
161
164 void set_channel(const uint8_t new_channel) // NOLINT(build/unsigned)
165 {
166 header.channel = new_channel;
167 }
168
169};
170
171} // namespace dunedaq::fddetdataformats
172
173#endif // FDDETDATAFORMATS_INCLUDE_FDDETDATAFORMATS_DAPHNEETHFRAME_HPP_
Class for accessing raw WIB eth frames, as used in ProtoDUNE-II.
void set_adc(int i, uint16_t val)
Set the ith ADC value in the frame to val.
void set_timestamp(const uint64_t new_timestamp)
Set the starting 64-bit timestamp of the frame.
uint64_t get_timestamp() const
Get the starting 64-bit timestamp of the frame.
void set_channel(const uint8_t new_channel)
Set the channel identifier of the frame.
detdataformats::DAQEthHeader daq_header
uint8_t get_channel() const
Get the channel identifier of the frame.
uint16_t get_adc(int i) const
Get the ith ADC value in the frame.
DAQEthHeader is a versioned and unified structure for every FE electronics.