DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DAPHNEStreamFrame.hpp
Go to the documentation of this file.
1
15#ifndef FDDETDATAFORMATS_INCLUDE_FDDETDATAFORMATS_DAPHNESTREAMFRAME_HPP_
16#define FDDETDATAFORMATS_INCLUDE_FDDETDATAFORMATS_DAPHNESTREAMFRAME_HPP_
17
18#include "detdataformats/DAQHeader.hpp" // For unified DAQ header
19
20#include <algorithm> // For std::min
21#include <cassert> // For assert()
22#include <cstdio>
23#include <cstdlib>
24#include <stdexcept> // For std::out_of_range
25#include <cstdint> // For uint32_t etc
26
28
30{
31public:
32 // ===============================================================
33 // Preliminaries
34 // ===============================================================
35
36 // The definition of the format is in terms of 32-bit words
37 typedef uint32_t word_t; // NOLINT
38
39 static constexpr int s_bits_per_adc = 14;
40 static constexpr int s_bits_per_word = 8 * sizeof(word_t);
41 static constexpr int s_channels_per_frame = 4;
42 static constexpr int s_adcs_per_channel = 64;
43 static constexpr int s_daphnes_per_frame = 1;
45
46 struct Header
47 {
50 };
51
52 struct Trailer
53 {
54 word_t tbd : 32;
55 };
56
57 // ===============================================================
58 // Data members
59 // ===============================================================
64
65 // ===============================================================
66 // Accessors
67 // ===============================================================
68
69 uint64_t get_timestamp() const
70 {
72 }
73
76 void set_timestamp(const uint64_t new_timestamp) // NOLINT(build/unsigned)
77 {
78 daq_header.timestamp_1 = new_timestamp;
79 daq_header.timestamp_2 = new_timestamp >> 32;
80 }
81
82
86 uint16_t get_adc(uint i, uint chn) const // NOLINT
87 {
88
89 if (i >= s_adcs_per_channel)
90 throw std::out_of_range("ADC index out of range");
91
92 if (chn >= s_channels_per_frame)
93 throw std::out_of_range("ADC index out of range");
94
95 // find absolute index in frame
96 uint j = i*s_channels_per_frame+chn;
97 // The index of the first (and sometimes only) word containing the required ADC value
98 uint word_index = s_bits_per_adc * j / s_bits_per_word;
99 assert(word_index < s_num_adc_words);
100 // Where in the word the lowest bit of our ADC value is located
101 int first_bit_position = (s_bits_per_adc * j) % s_bits_per_word;
102 // How many bits of our desired ADC are located in the `word_index`th word
103 int bits_from_first_word = std::min(s_bits_per_adc, s_bits_per_word - first_bit_position);
104 uint16_t adc = adc_words[word_index] >> first_bit_position; // NOLINT(build/unsigned)
105
106 if (bits_from_first_word < s_bits_per_adc) {
107 assert(word_index + 1 < s_num_adc_words);
108 adc |= adc_words[word_index + 1] << bits_from_first_word;
109 }
110 // Mask out all but the lowest 14 bits;
111 return adc & 0x3FFFu;
112 }
113
117 void set_adc(uint i, uint chn, uint16_t val) // NOLINT
118 {
119
120 if (i >= s_adcs_per_channel)
121 throw std::out_of_range("ADC index out of range");
122
123 if (chn >= s_channels_per_frame)
124 throw std::out_of_range("ADC index out of range");
125
126 if (val >= (1 << s_bits_per_adc))
127 throw std::out_of_range("ADC value out of range");
128
129
130 // find absolute index in frame
131 uint j = i*s_channels_per_frame+chn;
132 // The index of the first (and sometimes only) word containing the required ADC value
133 int word_index = s_bits_per_adc * j / s_bits_per_word;
134 assert(word_index < s_num_adc_words);
135 // Where in the word the lowest bit of our ADC value is located
136 int first_bit_position = (s_bits_per_adc * j) % s_bits_per_word;
137 // How many bits of our desired ADC are located in the `word_index`th word
138 int bits_in_first_word = std::min(s_bits_per_adc, s_bits_per_word - first_bit_position);
139 uint32_t mask = (1 << (first_bit_position)) - 1;
140 adc_words[word_index] = ((val << first_bit_position) & ~mask) | (adc_words[word_index] & mask);
141 // If we didn't put the full 14 bits in this word, we need to put the rest in the next word
142 if (bits_in_first_word < s_bits_per_adc) {
143 assert(word_index + 1 < s_num_adc_words);
144 mask = (1 << (s_bits_per_adc - bits_in_first_word)) - 1;
145 adc_words[word_index + 1] = ((val >> bits_in_first_word) & mask) | (adc_words[word_index + 1] & ~mask);
146 }
147
148 }
151 uint8_t get_channel0() const { return header.channel_0; } // NOLINT(build/unsigned)
152
155 uint8_t get_channel1() const { return header.channel_1; } // NOLINT(build/unsigned)
156
159 uint8_t get_channel2() const { return header.channel_2; } // NOLINT(build/unsigned)
160
163 uint8_t get_channel3() const { return header.channel_3; } // NOLINT(build/unsigned)
164};
165
166
167} // namespace dunedaq::fddetdataformats
168
169#endif // FDDETDATAFORMATS_INCLUDE_FDDETDATAFORMATS_DAPHNESTREAMFRAME_HPP_
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 64-bit timestamp of the frame.
uint8_t get_channel2() const
Get the channel 2 from the DAPHNE Stream frame header
uint8_t get_channel0() const
Get the channel 0 from the DAPHNE Stream frame header
uint8_t get_channel3() const
Get the channel 3 from the DAPHNE Stream frame header
void set_adc(uint i, uint chn, uint16_t val)
Set the i ADC value of chn in the frame to val.
uint16_t get_adc(uint i, uint chn) const
Get the i ADC value of chn in the frame.
DAQHeader is a versioned and unified structure for every FE electronics.
Definition DAQHeader.hpp:22