DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
CTBPacketContent.hpp
Go to the documentation of this file.
1/*
2 * CTBPacketContent.hpp
3 *
4 * Ported from
5 * https://cdcvs.fnal.gov/redmine/projects/dune-raw-data/repository/revisions/develop/entry/dune-raw-data/Overlays/CTB_content.h
6 *
7 * Developer: willpvazquez (27 July 2022)
8 *
9 * Originally Created on: Oct 8, 2017
10 * Author: nbarros
11 */
12
13#ifndef CTBMODULES_SRC_CTBPACKETCONTENT_HPP_
14#define CTBMODULES_SRC_CTBPACKETCONTENT_HPP_
15
16#include <cstdint>
17
18namespace dunedaq {
19namespace ctbmodules {
20namespace content {
21
22// NFB: Note that order denotes bit order in the word:
23// Upper fields are in the lsb and lower field is in the msb
26// static uint8_t format_version = 0x2;
27
28typedef struct buffer_t
29{
30 int handle;
31 size_t len;
33
37
38typedef struct tcp_header_t
39{
40 typedef uint16_t pkt_size_t;
41 typedef uint8_t seq_size_t;
42 typedef uint8_t ver_size_t;
43 uint16_t packet_size : 16; // Size of the data content in bytes
44 uint8_t sequence_id : 8; // packet order...rotates every 256
45 uint8_t format_version : 8;
46 static size_t const size_bytes = sizeof(uint32_t);
47 static size_t const n_bits_size = 16;
48 static size_t const n_bits_sequence_id = 8;
49 static size_t const n_bits_version = 8;
51
52// NFB: Careful with unions. Setting one member and then accessing another
53// is undefined behavior in C++.
54// However, I have tested that they work on gcc on the PTB
55
56typedef union tcp_header
57{
59 uint32_t value;
61
62namespace word {
64{
65 t_fback = 0x0,
66 t_lt = 0x1,
67 t_gt = 0x2,
68 t_ch = 0x3,
69 t_chksum = 0x4,
70 t_ts = 0x7
71};
72
75// -- The body of a word is composed of 12 bytes
76typedef uint16_t trigger_code_t;
87
88typedef struct word_t
89{
90 typedef uint64_t ts_size_t;
91 typedef uint64_t pad_size_t;
92 typedef uint64_t word_type_t;
96 static size_t const size_bytes = 4 * sizeof(uint32_t);
97 static size_t const size_u32 = 4 * sizeof(uint32_t) / sizeof(uint32_t);
98 static size_t const n_bits_timestamp = 64;
99 static size_t const n_bits_payload = 61;
100 static size_t const n_bits_type = 3;
102
103typedef union word
104{
106 uint8_t* get_bytes() { return reinterpret_cast<uint8_t*>(&frame); }
108
112
113typedef struct feedback_t
114{
115 typedef uint64_t ts_size_t;
116 typedef uint16_t code_size_t;
117 typedef uint16_t source_size_t;
118 typedef uint32_t wtype_size_t;
119 typedef uint32_t pad_size_t;
125 static size_t const size_bytes = 2 * sizeof(uint64_t);
126 static size_t const size_u32 = size_bytes / sizeof(uint32_t);
127 static size_t const n_bits_timestamp = 64;
128 static size_t const n_bits_payload = 32;
129 static size_t const n_bits_type = 3;
131
132typedef struct ch_status_t
133{
134 typedef uint64_t ts_size_t;
135 typedef uint64_t pds_size_t;
136 typedef uint64_t crt_size_t;
137 typedef uint64_t beam_size_t;
138 typedef uint64_t wtype_size_t;
145 static size_t const size_bytes = 2 * sizeof(uint64_t);
146 static size_t const size_u32 = size_bytes / sizeof(uint32_t);
147 static size_t const n_bits_timestamp = 60;
148 static size_t const n_bits_payload = 32;
149 static size_t const n_bits_type = 3;
150
151 // aux_functions
152 beam_size_t get_beam() const { return (beam_hi << 4 | beam_lo); }
153 crt_size_t get_crt() const { return (crt & 0xFFFFFFFF); }
154 pds_size_t get_pds() const { return (pds & 0x1FFFF); }
155
156 bool get_state_crt(const uint16_t channel) { return ((crt & (0x1 << channel)) != 0x0); }
157
158 bool get_state_pds(const uint16_t channel) { return ((pds & (0x1 << channel)) != 0x0); }
159
160 bool get_state_beam(const uint16_t channel) { return (((beam_hi << 4 | beam_lo) & (0x1 << channel)) != 0x0); }
162
163typedef struct timestamp_t
164{
165 typedef uint64_t ts_size_t;
166 typedef uint64_t pad_size_t;
167 typedef uint64_t wtype_size_t;
171 static size_t const size_bytes = 2 * sizeof(uint64_t);
172 static size_t const size_u32 = size_bytes / sizeof(uint32_t);
173 static size_t const n_bits_timestamp = 64;
174 static size_t const n_bits_unused = 61;
175 static size_t const n_bits_type = 3;
177
178typedef struct trigger_t
179{
180 typedef uint64_t ts_size_t;
181 typedef uint64_t mask_size_t;
182 typedef uint64_t wtype_size_t;
186 static size_t const size_bytes = 2 * sizeof(uint64_t);
187 static size_t const size_u32 = size_bytes / sizeof(uint32_t);
188 static size_t const n_bits_timestamp = 64;
189 static size_t const n_bits_tmask = 61;
190 static size_t const n_bits_type = 3;
191
192 bool IsHLT() const { return word_type == word_type::t_gt; }
193 bool IsLLT() const { return word_type == word_type::t_lt; }
194 bool IsTrigger(const unsigned int i) const
195 {
196 if (IsHLT())
197 return trigger_word & (0x1 << i);
198 if (IsLLT())
199 return i == 0 ? false : trigger_word & (0x1 << (i - 1));
200 return false;
201 }
203
204} // -- namespace word
205} // -- namespace content
206} // -- namespace ctbmodules
207} // -- namespace dunedaq
208
209#endif /* CTBMODULES_SRC_CTBPACKETCONTENT_HPP_ */
struct dunedaq::ctbmodules::content::word::timestamp_t timestamp_t
struct dunedaq::ctbmodules::content::word::feedback_t feedback_t
struct dunedaq::ctbmodules::content::word::ch_status_t ch_status_t
struct dunedaq::ctbmodules::content::word::trigger_t trigger_t
struct dunedaq::ctbmodules::content::word::word_t word_t
union dunedaq::ctbmodules::content::tcp_header tcp_header
struct dunedaq::ctbmodules::content::tcp_header_t tcp_header_t
struct dunedaq::ctbmodules::content::buffer_t buffer_t
The DUNE-DAQ namespace.