CTB_content.h
Go to the documentation of this file.
1 /*
2  * content.h
3  *
4  * Created on: Oct 8, 2017
5  * Author: nbarros
6  */
7 
8 #ifndef DUNE_RAW_DATA_OVERLAYS_CTB_CONTENT_H_
9 #define DUNE_RAW_DATA_OVERLAYS_CTB_CONTENT_H_
10 
11 #include <cstdint>
12 
13 namespace ptb {
14 
15  namespace content {
16 
17  // NFB: Note that order denotes bit order in the word:
18  // Upper fields are in the lsb and lower field is in the msb
19 
20  /// Internal buffer definition
21  ///
22 
23  //static uint8_t format_version = 0x2;
24 
25  typedef struct buffer_t {
26  int handle;
27  size_t len;
28  } buffer_t;
29 
30  ///
31  /// -- TCP header
32  ///
33  typedef struct tcp_header_t {
34  typedef uint16_t pkt_size_t;
35  typedef uint8_t seq_size_t;
36  typedef uint8_t ver_size_t;
37  uint16_t packet_size : 16; // Size of the data content in bytes
38  uint8_t sequence_id : 8; // packet order...rotates every 256
39  uint8_t format_version : 8;
40 
41  static size_t const size_bytes = sizeof(uint32_t);
42  static size_t const n_bits_size = 16;
43  static size_t const n_bits_sequence_id = 8;
44  static size_t const n_bits_version = 8;
45 
46  } tcp_header_t;
47 
48  // NFB: Careful with unions. Setting one member and then accessing another
49  // is undefined behavior in C++.
50  // However, I have tested that they work on gcc on the PTB
51  typedef union tcp_header {
53  uint32_t value;
54  } tcp_header;
55 
56  namespace word {
57 
58 
59  enum word_type {t_fback=0x0,t_lt=0x1,t_gt=0x2, t_ch=0x3,t_chksum=0x4,t_ts=0x7};
60 
61 
62 
63  ///
64  /// -- payload
65  ///
66 
67  // -- The body of a word is composed of 12 bytes
68  typedef uint16_t trigger_code_t;
69 
70 
71  ///
72  /// N. Barros - May 7, 2018 : Changed the structure of the parsing
73  ///
74  /// Now all structures cast into 16 bytes, but declare different
75  /// bit fields to interpret each frame in the context of its respective type
76  ///
77  /// Also, to move into a format where the full timestamp is stored, the full timestamp
78  /// is now placed in the 64 lsb, instead of the msb. Does complies with the memory alignment
79  /// and simplifies the parsing of the structures
80  ///
81 
82  typedef struct word_t {
83  typedef uint64_t ts_size_t;
84  typedef uint64_t pad_size_t;
85  typedef uint64_t word_type_t;
86 
87  ts_size_t timestamp;
88  pad_size_t payload : 61;
89  word_type_t word_type : 3;
90 
91  static size_t const size_bytes = 4*sizeof(uint32_t);
92  static size_t const size_u32 = 4*sizeof(uint32_t)/sizeof(uint32_t);
93 
94  static size_t const n_bits_timestamp = 64;
95  static size_t const n_bits_payload = 61;
96  static size_t const n_bits_type = 3;
97 
98  } word_t;
99 
100 
101  typedef union word{
103  uint8_t *get_bytes() {return reinterpret_cast<uint8_t*>(&frame);}
104  } word;
105 
106 
107  /// -- Several different structures that can be used to reinterpret the payload depending on
108  /// the word type. All these structures map into the full 16 bytes of the CTB words
109  ///
110  typedef struct feedback_t {
111  typedef uint64_t ts_size_t;
112  typedef uint16_t code_size_t;
113  typedef uint16_t source_size_t;
114  typedef uint32_t wtype_size_t;
115  typedef uint32_t pad_size_t;
116 
117  ts_size_t timestamp;
118  code_size_t code : 16;
119  source_size_t source : 16;
120  pad_size_t padding : 29;
121  wtype_size_t word_type : 3;
122 
123 
124  static size_t const size_bytes = 2*sizeof(uint64_t);
125  static size_t const size_u32 = size_bytes/sizeof(uint32_t);
126 
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;
130 
131  } feedback_t;
132 
133 
134  typedef struct ch_status_t {
135  typedef uint64_t ts_size_t;
136  typedef uint64_t pds_size_t;
137  typedef uint64_t crt_size_t;
138  typedef uint64_t beam_size_t;
139  typedef uint64_t wtype_size_t;
140 
141  ts_size_t timestamp : 60;
142  beam_size_t beam_lo : 4;
143  beam_size_t beam_hi : 5;
144  crt_size_t crt : 32;
145  pds_size_t pds : 24;
146  wtype_size_t word_type : 3;
147 
148 
149  static size_t const size_bytes = 2*sizeof(uint64_t);
150  static size_t const size_u32 = size_bytes/sizeof(uint32_t);
151 
152  static size_t const n_bits_timestamp = 60;
153  static size_t const n_bits_payload = 32;
154  static size_t const n_bits_type = 3;
155 
156 
157  // aux_functions
158  beam_size_t get_beam() const {return (beam_hi << 4 | beam_lo);}
159  crt_size_t get_crt() const {return (crt & 0xFFFFFFFF);}
160  pds_size_t get_pds() const {return (pds & 0xFFFFFFF);}
161 
162  bool get_state_crt(const uint16_t channel) {
163  return ((crt & (0x1 << channel)) != 0x0);
164  }
165  bool get_state_pds(const uint16_t channel) {
166  return ((pds & (0x1 << channel)) != 0x0);
167  }
168  bool get_state_beam(const uint16_t channel) {
169  return (((beam_hi << 4 | beam_lo) & (0x1 << channel)) != 0x0);
170  }
171 
172  } ch_status_t;
173 
174 
175 
176  typedef struct timestamp_t {
177  typedef uint64_t ts_size_t;
178  typedef uint64_t pad_size_t;
179  typedef uint64_t wtype_size_t;
180 
181  ts_size_t timestamp;
182  pad_size_t padding : 61;
183  wtype_size_t word_type : 3;
184 
185  static size_t const size_bytes = 2*sizeof(uint64_t);
186  static size_t const size_u32 = size_bytes/sizeof(uint32_t);
187 
188  static size_t const n_bits_timestamp = 64;
189  static size_t const n_bits_unused = 61;
190  static size_t const n_bits_type = 3;
191 
192  } timestamp_t;
193 
194 
195  typedef struct trigger_t {
196 
197  typedef uint64_t ts_size_t;
198  typedef uint64_t mask_size_t;
199  typedef uint64_t wtype_size_t;
200 
201  ts_size_t timestamp ;
202  mask_size_t trigger_word : 61 ;
203  wtype_size_t word_type : 3 ;
204 
205  static size_t const size_bytes = 2*sizeof(uint64_t);
206  static size_t const size_u32 = size_bytes/sizeof(uint32_t);
207 
208  static size_t const n_bits_timestamp = 64;
209  static size_t const n_bits_tmask = 61;
210  static size_t const n_bits_type = 3;
211 
212  bool IsHLT() const { return word_type == word_type::t_gt ; }
213  bool IsLLT() const { return word_type == word_type::t_lt ; }
214  bool IsTrigger( const unsigned int i ) const {
215  if ( IsHLT() ) return trigger_word & ( 0x1 << i ) ;
216  if ( IsLLT() ) return i == 0 ? false : trigger_word & ( 0x1 << (i-1) ) ;
217  return false ;
218  }
219 
220  } trigger_t;
221 
222  } // -- namespace word
223  } // -- namespace content
224 } // -- namespace ptb
225 
226 
227 
228 
229 #endif /* SRC_CONTENT_H_ */
struct ptb::content::word::ch_status_t ch_status_t
struct ptb::content::tcp_header_t tcp_header_t
struct ptb::content::word::trigger_t trigger_t
struct ptb::content::buffer_t buffer_t
uint8_t channel
Definition: CRTFragment.hh:201
beam_size_t get_beam() const
Definition: CTB_content.h:158
crt_size_t get_crt() const
Definition: CTB_content.h:159
pds_size_t get_pds() const
Definition: CTB_content.h:160
uint16_t trigger_code_t
Definition: CTB_content.h:68
struct ptb::content::word::timestamp_t timestamp_t
CodeOutputInterface * code
union ptb::content::tcp_header tcp_header
struct ptb::content::word::feedback_t feedback_t
bool get_state_beam(const uint16_t channel)
Definition: CTB_content.h:168
bool get_state_crt(const uint16_t channel)
Definition: CTB_content.h:162
bool get_state_pds(const uint16_t channel)
Definition: CTB_content.h:165
union ptb::content::word::word word
bool IsTrigger(const unsigned int i) const
Definition: CTB_content.h:214
struct ptb::content::word::word_t word_t