DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
CRTBernFrame.hpp
Go to the documentation of this file.
1
15#ifndef FDDETDATAFORMATS_INCLUDE_FDDETDATAFORMATS_CRTBERNFRAME_HPP_
16#define FDDETDATAFORMATS_INCLUDE_FDDETDATAFORMATS_CRTBERNFRAME_HPP_
17
19
21
22#include <algorithm> // For std::min
23#include <cassert> // For assert()
24#include <cstdint> // For uint32_t etc
25#include <cstdio>
26#include <cstdlib>
27#include <stdexcept> // For std::out_of_range
28
30
31// NOLINTBEGIN(build/unsigned)
32
38{
39 // The definition of the format is in terms of 64-bit words
40 using word_t = uint64_t; // NOLINT
41
42 static constexpr int s_num_channels = 32;
43 static constexpr uint64_t s_DTS_ticks_per_second = 62'500'000;
44 static constexpr uint64_t s_ns_per_DTS_tick = 16;
45
47 {
48 static constexpr std::size_t s_expected_bytes { 2 + 2 + 2 + 4 + 4 + 2 * s_num_channels + 4 };
49
50 uint16_t flags = 0;
51 uint16_t lostcpu = 0;
52 uint16_t lostfpga = 0;
53 uint32_t ts0 = 0;
54 uint32_t ts1 = 0;
55 uint16_t adc[s_num_channels] = { 0 }; // NOLINT
56 uint32_t coinc = 0;
57 };
58 #warning "CRTBernData has padding inserted"
59 //static_assert(sizeof(CRTBernData) == CRTBernData::s_expected_bytes);
60
61 static constexpr std::size_t s_expected_bytes { sizeof(detdataformats::DAQEthHeader) + sizeof(uint16_t) +
63
65 uint16_t get_adc(int i_ch) const
66 {
67 if (i_ch < 0 || i_ch >= s_num_channels)
68 throw std::out_of_range("ADC channel index out of range");
69
70 return data.adc[i_ch];
71 }
72
74 void set_adc(int i_ch, uint16_t val)
75 {
76 if (i_ch < 0 || i_ch >= s_num_channels)
77 throw std::out_of_range("ADC channel index out of range");
78
79 data.adc[i_ch] = val; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
80 }
81
83 uint64_t get_timestamp() const { return daq_header.get_timestamp(); }
84
88 void set_timestamp(const uint64_t new_timestamp)
89 {
90 daq_header.timestamp = new_timestamp;
91 data.ts0 = (new_timestamp % s_DTS_ticks_per_second) * s_ns_per_DTS_tick;
92 }
93
94 uint16_t get_mac5() const { return mac5; }
95
96 void set_mac5(const uint16_t new_mac5) { mac5 = new_mac5; }
97
98 uint16_t get_flags() const { return data.flags; }
99
100 void set_flags(const uint16_t new_flags) { data.flags = new_flags; }
101
103 uint16_t get_lostcpu() const { return data.lostcpu; }
104
106 void set_lostcpu(const uint16_t new_lostcpu) { data.lostcpu = new_lostcpu; }
107
109 uint16_t get_lostfpga() const { return data.lostfpga; }
110
112 void set_lostfpga(const uint16_t new_lostfpga) { data.lostfpga = new_lostfpga; }
113
114 uint32_t get_ts0() const { return data.ts0; }
115
116 void set_ts0(const uint32_t new_ts0) { data.ts0 = new_ts0; }
117
118 uint32_t get_ts1() const { return data.ts1; }
119
120 void set_ts1(const uint32_t new_ts1) { data.ts1 = new_ts1; }
121
122 uint32_t get_coinc() const { return data.coinc; }
123
124 void set_coinc(const uint32_t new_coinc) { data.coinc = new_coinc; }
125
126 detdataformats::DAQEthHeader daq_header; // Note this is de-facto public thanks to non-const get_daqheader
127 uint16_t mac5;
129
130}; // CRTBernFrame
131 #warning "CRTBernFrame has padding inserted"
132 // static_assert(sizeof(CRTBernFrame) == CRTBernFrame::s_expected_bytes)
133
134 static_assert(std::endian::native == std::endian::little,
135 "The CRTBernFrame bitfield layout assumes little-endian architecture");
136 static_assert(std::is_trivially_copyable_v<CRTBernFrame>,
137 "CRTBernFrame isn't trivially copyable and can't be safely std::memcpy'd");
138 static_assert(std::is_standard_layout_v<CRTBernFrame>,
139 "CRTBernFrame isn't standard layout; reinterpret_cast and offsetof can't safely be used with it");
140
141} // namespace dunedaq::fddetdataformats
142
143// NOLINTEND(build/unsigned)
144
145#endif // FDDETDATAFORMATS_INCLUDE_FDDETDATAFORMATS_CRTBERNFRAME_HPP_
DAQEthHeader is a versioned and unified structure for every FE electronics.
Struct for accessing/holding raw CRT data from the 'Bern' panels ProtoDUNE-II VD.
void set_mac5(const uint16_t new_mac5)
uint16_t get_lostcpu() const
Get the lostcpu counter of the CRTBernData.
void set_adc(int i_ch, uint16_t val)
Set the adc value for channel i_ch to val.
uint16_t get_adc(int i_ch) const
Get the adc value for channel i_ch.
static constexpr uint64_t s_ns_per_DTS_tick
void set_lostcpu(const uint16_t new_lostcpu)
Set the lostcpu counter of the CRTBernData.
void set_coinc(const uint32_t new_coinc)
uint64_t get_timestamp() const
Get the starting 64-bit timestamp of the frame.
static constexpr uint64_t s_DTS_ticks_per_second
detdataformats::DAQEthHeader daq_header
uint16_t get_lostfpga() const
Get the lostfpga counter of the CRTBernData.
void set_ts1(const uint32_t new_ts1)
static constexpr std::size_t s_expected_bytes
void set_lostfpga(const uint16_t new_lostfpga)
Set the lostfpga counter of the CRTBernData.
void set_flags(const uint16_t new_flags)
void set_timestamp(const uint64_t new_timestamp)
Set the starting 64-bit timestamp of the frame also set the underlying ts0 to be consistent.
void set_ts0(const uint32_t new_ts0)