DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DAPHNEEthStreamFrame.hpp
Go to the documentation of this file.
1
14#ifndef FDDETDATAFORMATS_INCLUDE_FDDETDATAFORMATS_DAPHNEETHSTREAMFRAME_HPP_
15#define FDDETDATAFORMATS_INCLUDE_FDDETDATAFORMATS_DAPHNEETHSTREAMFRAME_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_adcs_per_channel = 280;
50 static constexpr int s_num_channels = 4;
52
54 {
55 word_t tbd : 52;
58 };
59
64
65 // ===============================================================
66 // Data members
67 // ===============================================================
71
72// ===============================================================
73// Accessors
74// ===============================================================
75
79uint16_t get_adc(uint i, uint chn) const // NOLINT
80{
81
82 if (i >= s_adcs_per_channel)
83 throw std::out_of_range("ADC index out of range");
84
85 if (chn >= s_num_channels)
86 throw std::out_of_range("Channel index out of range");
87
88 // find absolute index in frame
89 uint j = i*s_num_channels+chn;
90 // The index of the first (and sometimes only) word containing the required ADC value
91 uint word_index = s_bits_per_adc * j / s_bits_per_word;
92 assert(word_index < s_num_adc_words);
93 // Where in the word the lowest bit of our ADC value is located
94 int first_bit_position = (s_bits_per_adc * j) % s_bits_per_word;
95 // How many bits of our desired ADC are located in the `word_index`th word
96 int bits_from_first_word = std::min(s_bits_per_adc, s_bits_per_word - first_bit_position);
97 uint16_t adc = adc_words[word_index] >> first_bit_position; // NOLINT(build/unsigned)
98
99 if (bits_from_first_word < s_bits_per_adc) {
100 assert(word_index + 1 < s_num_adc_words);
101 adc |= adc_words[word_index + 1] << bits_from_first_word;
102 }
103 // Mask out all but the lowest 14 bits;
104 return adc & 0x3FFFu;
105}
106
110void set_adc(uint chn, uint i, uint16_t val) // NOLINT
111{
112 if (chn >= s_num_channels)
113 throw std::out_of_range("Channel index out of range");
114
115 if (i >= s_adcs_per_channel)
116 throw std::out_of_range("ADC index out of range");
117
118 if (val >= (1 << s_bits_per_adc))
119 throw std::out_of_range("ADC value out of range");
120
121
122 // find absolute index in frame
123 uint j = i*s_num_channels+chn;
124 // The index of the first (and sometimes only) word containing the required ADC value
125 int word_index = s_bits_per_adc * j / 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 * j) % 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(uint ch) const // NOLINT(build/unsigned)
158 {
159 if (ch >= s_num_channels)
160 throw std::out_of_range("Channel index out of range");
161
162 return header.channel_words[ch].channel ; // NOLINT(build/unsigned)
163 }
164
167 void set_channel(uint channel_index, const uint8_t new_channel_val) // NOLINT(build/unsigned)
168 {
169 if (channel_index >= s_num_channels)
170 throw std::out_of_range("Channel index out of range");
171
172 header.channel_words[channel_index].channel = new_channel_val;
173 }
174
177 uint8_t get_channel0() const { return header.channel_words[0].channel; } // NOLINT(build/unsigned)
178
181 uint8_t get_channel1() const { return header.channel_words[1].channel; } // NOLINT(build/unsigned)
182
185 uint8_t get_channel2() const { return header.channel_words[2].channel; } // NOLINT(build/unsigned)
186
189 uint8_t get_channel3() const { return header.channel_words[3].channel; } // NOLINT(build/unsigned)
190
191};
192
193} // namespace dunedaq::fddetdataformats
194
195#endif // FDDETDATAFORMATS_INCLUDE_FDDETDATAFORMATS_DAPHNEETHSTREAMFRAME_HPP_
Class for accessing raw DAPHNE eth stream frames, as used in ProtoDUNE-II.
void set_channel(uint channel_index, const uint8_t new_channel_val)
Set the channel identifier of the frame.
uint8_t get_channel1() const
Get the channel 1 from the DAPHNE Stream frame header
void set_timestamp(const uint64_t new_timestamp)
Set the starting 64-bit timestamp of the frame.
void set_adc(uint chn, uint i, uint16_t val)
Set the i ADC value of chn in the frame to val.
uint8_t get_channel0() const
Get the channel 0 from the DAPHNE Stream frame header
uint16_t get_adc(uint i, uint chn) const
Get the i ADC value of chn in the frame.
uint8_t get_channel3() const
Get the channel 3 from the DAPHNE Stream frame header
uint8_t get_channel2() const
Get the channel 2 from the DAPHNE Stream frame header
uint64_t get_timestamp() const
Get the starting 64-bit timestamp of the frame.
uint8_t get_channel(uint ch) const
Get the channel identifier of the frame.
DAQEthHeader is a versioned and unified structure for every FE electronics.