LDMX Software
EventBuilder
include
EventBuilder
Fragment.h
1
// Fragment.h
2
#ifndef EVENTBUILDER_FRAGMENT_H
3
#define EVENTBUILDER_FRAGMENT_H
4
5
#include <vector>
6
#include <cstdint>
7
8
namespace
eventbuilder {
9
10
// Define a simple CRC32 implementation for checksum
11
inline
uint32_t crc32(
const
std::vector<uint8_t>& data) {
12
uint32_t crc = 0xFFFFFFFF;
13
for
(uint8_t c : data) {
14
crc ^=
static_cast<
uint8_t
>
(c);
15
for
(
int
i = 0; i < 8; ++i) {
16
if
(crc & 1) {
17
crc = (crc >> 1) ^ 0xEDB88320;
18
}
else
{
19
crc >>= 1;
20
}
21
}
22
}
23
return
~crc;
24
}
25
26
enum class
ContributorId {
27
Channel,
28
Module
29
};
30
31
struct
FragmentTrailer
{
32
uint32_t checksum;
// For error detection
33
};
34
35
struct
FragmentHeader
{
36
// Header Word 0
37
uint64_t magic_number : 8;
// 0xA5
38
uint64_t contributor_id : 8;
39
uint64_t subsystem_id : 8;
40
uint64_t version : 8;
41
uint64_t padding : 32;
// Unused bits
42
43
// Header Word 1
44
uint64_t timestamp;
45
};
46
47
// Represents a single data fragment
48
struct
DataFragment
{
49
FragmentHeader
header;
50
std::vector<uint8_t> payload;
// Raw byte data from the readout
51
FragmentTrailer
trailer;
52
};
53
54
}
// namespace eventbuilder
55
56
#endif
eventbuilder::DataFragment
Definition
Fragment.h:48
eventbuilder::FragmentHeader
Definition
Fragment.h:35
eventbuilder::FragmentTrailer
Definition
Fragment.h:31
Generated by
1.12.0