Orion
high-rate readout
fragheader.hpp
Go to the documentation of this file.
1 // ╭─╮╭─╴╷╭─╮┌─╮
2 // ╰─╯╵ ╵╰─╯╵ ╵
8 #pragma once
9 
10 #include <cassert>
11 #include <vector>
12 #include <span>
13 
14 namespace itk::fragment {
15 
16 // global timestamp is written to ROB fragment
17 // all ROD will have relative timestamp with respect to ROB
18 
19 // ROB defines FelixID pattern without V.ElinkID bits
20 // ROD defines fid by replacing V.ElinkID in FelixID pattern
21 
26 struct FelixPacket {
27  uint64_t fid = 0;
28  uint64_t time = 0;
29  const uint8_t* data = nullptr;
30  size_t size = 0;
31  uint8_t status = 0;
32 }; // Packet
33 
34 
35 using uint = uint32_t;
36 
37 // VID - VersionID[8]
38 // DID - DetectorID[8]
39 // CID - ConnectorID[16]
40 // LID - LinkID[14]
41 // TID - TransportID[14]
42 // V - Virtual Link
43 // EID - ElinkID[19]
44 // D - Direction
45 // SID - StreamID[8]
46 // ╭──╮╭──────╮╭──────────────╮╭────────────╮╭────────────╮╭──────╮
47 // VID DID CID LID TID SID
48 // vvvvddddddddccccccccccccccccllllllllllllllttttttttttttttssssssss
49 // ╰──╯╰──────╯╰──────────────╯╰────────────╯╰────────────╯╰──────╯
50 // ╭──╮╭──────╮╭──────────────╮╷╭─────────────────╮╷╭─────╮╭──────╮
51 // VID DID CID V EID D PID SID
52 // vvvvddddddddccccccccccccccccqeeeeeeeeeeeeeeeeeeerpppppppssssssss
53 // ╰──╯╰──────╯╰──────────────╯╵╰─────────────────╯╵╰─────╯╰──────╯
54 
55 struct FelixID {
56  union {
57  uint64_t felix_id;
58  struct {
59  uint stream_id : 8;
60  union {
61  struct {
62  uint transport_id : 14;
63  uint link_id : 14;
64  };
65  struct {
66  uint proto_id : 7;
67  uint direction : 1;
68  uint elink_id : 19;
69  uint virtlink : 1;
70  };
71  };
72  uint connector_id : 16;
73  uint detector_id : 8;
74  uint version_id : 4;
75  };
76  };
77 } __attribute__((packed, aligned(4))); // FelixID
78 
79 
80 
81 namespace FLX {
82 
87 struct Header {
95  uint32_t fragment_size : 22 = 0;
96  uint8_t padding_bytes : 2 = 0;
97  uint8_t felix_status : 8 = 0;
98  uint32_t elink_id : 20 = 0;
99  uint8_t format_type : 4 = 0;
100  uint8_t swrod_status : 8 = 0;
101  uint32_t timestamp = 0;
102 } __attribute__((packed, aligned(4)));
103 
105 static constexpr uint32_t HEADER_SIZE = sizeof(Header)/4;
106 
108 static constexpr uint32_t MAX_DATA32_SIZE = (0x1 << 22) - HEADER_SIZE;
109 
110 } // FLX
111 
112 
113 namespace SWROD {
114 
119 struct Header {
125  uint16_t size = 0;
126  uint8_t felix_status = 0;
127  uint8_t swrod_status = 0;
128  uint32_t link_id = 0;
129 } __attribute__((packed, aligned(4)));
130 
132 constexpr uint32_t HEADER_SIZE = sizeof(Header)/4;
133 
134 } // SWROD
135 
136 
137 
138 namespace ROD { // Read-Out Driver
139 
141 constexpr uint32_t HEADER_MARKER = 0xee1234ee;
142 
144 constexpr uint32_t HEADER_SIZE = 9;
145 
147 static constexpr uint32_t TRAILER_SIZE = 3;
148 
153 struct Header {
154  uint32_t header_marker = HEADER_MARKER;
155  uint32_t header_size = HEADER_SIZE;
156  uint32_t format_version;
157  uint32_t source_id;
158  uint32_t run_number;
159  uint32_t ext_l1id;
160  uint32_t bcid;
161  uint32_t trigger_type;
162  uint32_t event_type;
163 } __attribute__((packed, aligned(4)));
164 
165 static_assert(sizeof(Header) == HEADER_SIZE*4);
166 
167 
172 struct Trailer {
173  uint32_t status_size = 0;
174  uint32_t data_size = 0;
175  uint32_t status_pos = 1;
176 } __attribute__((packed, aligned(4)));
177 
178 static_assert(sizeof(Trailer) == TRAILER_SIZE*4);
179 
180 
181 } // ROD
182 
183 
184 namespace ROB { // Read-Out Buffer
185 
190 
193 
196 };
197 
198 
200 constexpr uint32_t HEADER_MARKER = 0xdd1234dd;
201 
206 struct BaseHeader {
207  uint32_t header_marker = HEADER_MARKER;
208  uint32_t fragment_size = 0;
209  uint32_t header_size;
210  uint32_t format_version;
211  uint32_t source_id;
212  uint32_t status_size;
213  uint32_t status[0];
214 };
215 
217 static constexpr uint32_t BASE_HEADER_SIZE = sizeof(BaseHeader)/4;
218 
219 
224 template<int n>
225 struct Header {
227  static constexpr uint32_t HEADER_SIZE = sizeof(Header)/4;
228 
229  uint32_t header_marker = HEADER_MARKER;
230  uint32_t fragment_size = 0;
232  uint32_t format_version;
233  uint32_t source_id = 0;
234  uint32_t status_size = n;
235  uint32_t status[n];
236  uint32_t checksum_type = 0;
237 
244  uint64_t timestamp = 0x2000000010000000L;
245  uint32_t felix_device = 0xF;
246 } __attribute__((packed, aligned(4)));
247 
248 } // ROB
249 
250 } // itk::fragment
constexpr uint32_t HEADER_MARKER
ROD Header marker.
Definition: fragheader.hpp:141
checksum_t
Checksum type.
Definition: fragheader.hpp:187
@ CHECKSUM_CRC16
CRC-16/CCITT checksum.
Definition: fragheader.hpp:192
@ CHECKSUM_ADLER32
Adler-32 checksum.
Definition: fragheader.hpp:195
@ CHECKSUM_NONE
No checksum.
Definition: fragheader.hpp:189
Definition: fragheader.hpp:87
uint32_t timestamp
SWROD status.
Definition: fragheader.hpp:101
uint8_t swrod_status
format type
Definition: fragheader.hpp:100
uint32_t fragment_size
Definition: fragheader.hpp:95
uint8_t format_type
Virtual[1].ElinkID[19].
Definition: fragheader.hpp:99
uint8_t felix_status
bytes added to align to word
Definition: fragheader.hpp:97
uint8_t padding_bytes
size of fragment in words
Definition: fragheader.hpp:96
uint32_t elink_id
FELIX status.
Definition: fragheader.hpp:98
Definition: fragheader.hpp:55
Felix Packet structure.
Definition: fragheader.hpp:26
uint64_t time
FELIX ID.
Definition: fragheader.hpp:28
const uint8_t * data
timestamp in BC
Definition: fragheader.hpp:29
Definition: fragheader.hpp:206
uint32_t format_version
header size in words
Definition: fragheader.hpp:210
uint32_t source_id
format version major[16].minor[16]
Definition: fragheader.hpp:211
uint32_t fragment_size
header marker
Definition: fragheader.hpp:208
uint32_t status[0]
number of status elements
Definition: fragheader.hpp:213
uint32_t status_size
origin of the fragment [sub-detector id, module id]
Definition: fragheader.hpp:212
uint32_t header_size
size of fragment in words
Definition: fragheader.hpp:209
Definition: fragheader.hpp:225
uint32_t header_size
size of fragment in words
Definition: fragheader.hpp:231
uint32_t status_size
origin of the fragment [sub-detector id, module id]
Definition: fragheader.hpp:234
uint32_t status[n]
number of status elements
Definition: fragheader.hpp:235
uint64_t timestamp
check sum type, after status elements
Definition: fragheader.hpp:244
uint32_t fragment_size
header marker
Definition: fragheader.hpp:230
uint32_t format_version
header size in words
Definition: fragheader.hpp:232
uint32_t felix_device
Timestamp for ROB in bunch crossing.
Definition: fragheader.hpp:245
static constexpr uint32_t HEADER_SIZE
ROB header size.
Definition: fragheader.hpp:227
uint32_t checksum_type
status elements
Definition: fragheader.hpp:236
uint32_t source_id
format version major[16].minor[16]
Definition: fragheader.hpp:233
Definition: fragheader.hpp:153
uint32_t trigger_type
bunch crossing ID : bcid[12]
Definition: fragheader.hpp:161
uint32_t event_type
Leve1 ID trigger type.
Definition: fragheader.hpp:162
uint32_t ext_l1id
run number
Definition: fragheader.hpp:159
uint32_t format_version
header size in words
Definition: fragheader.hpp:156
uint32_t header_size
header marker, for ROD = 0xee1234ee
Definition: fragheader.hpp:155
uint32_t bcid
extended Level1 ID : ecr[8].l1id[24]
Definition: fragheader.hpp:160
uint32_t run_number
origin of the fragment : optional[8].sub-detector[8].ROL[16]
Definition: fragheader.hpp:158
uint32_t source_id
format version major[16].minor[16]
Definition: fragheader.hpp:157
Definition: fragheader.hpp:172
uint32_t data_size
number of status elements
Definition: fragheader.hpp:174
uint32_t status_pos
number of data elements
Definition: fragheader.hpp:175
Definition: fragheader.hpp:119
uint8_t felix_status
size of fragment including header in 4 byte words
Definition: fragheader.hpp:126
uint8_t swrod_status
felix status
Definition: fragheader.hpp:127
uint32_t link_id
swrod status
Definition: fragheader.hpp:128
uint16_t size
Definition: fragheader.hpp:125
Definition: pixmem.hpp:28