LDMX Software
Fragment.h
1// Fragment.h
2#ifndef EVENTBUILDER_FRAGMENT_H
3#define EVENTBUILDER_FRAGMENT_H
4
5#include <cstdint>
6#include <vector>
7
8namespace eventbuilder {
9
10// Define a simple CRC32 implementation for checksum
11inline 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
26enum class ContributorId { Channel, Module };
27
29 uint32_t checksum_; // For error detection
30};
31
33 // Header Word 0
34 uint64_t magic_number_ : 8; // 0xA5
35 uint64_t contributor_id_ : 8;
36 uint64_t subsystem_id_ : 8;
37 uint64_t version_ : 8;
38 uint64_t padding_ : 32; // Unused bits
39
40 // Header Word 1
41 uint64_t timestamp_;
42};
43
44// Represents a single data fragment
46 FragmentHeader header_;
47 std::vector<uint8_t> payload_; // Raw byte data from the readout
48 FragmentTrailer trailer_;
49};
50
51} // namespace eventbuilder
52
53#endif