BmnRoot
Loading...
Searching...
No Matches
BmnHgndRaw.h
Go to the documentation of this file.
1#ifndef BMNHGNDRAW_H
2#define BMNHGNDRAW_H
3
4#include <array>
5#include <cstdint>
6#include <vector>
7
8namespace BmnHgndRaw
9{
10
11namespace Block
12{
13
14// Header
15static constexpr uint32_t HEADER_MASK = 0xF000;
16static constexpr uint8_t EVENT_HEADER = 0xA;
17
18inline bool is_word_event_header(uint16_t word)
19{
20 return ((word & HEADER_MASK) >> 12) == EVENT_HEADER;
21}
22
23// Version
25{
26 ERR,
27 V1,
28 V2
29};
30
32{
33 uint8_t version = uint8_t(word & 0x000F);
34 if (version == 1)
35 return EventPacketVersion::V1;
36 if (version == 2)
37 return EventPacketVersion::V2;
38 return EventPacketVersion::ERR;
39}
40
41// Length
42static constexpr uint16_t EVENT_TYPE_1_PACKET_LENGTH = 8;
43static constexpr uint16_t EVENT_TYPE_2_PACKET_LENGTH = 18;
44
45inline uint16_t get_block_size(EventPacketVersion packet_version = ERR)
46{
47 if (packet_version == Block::EventPacketVersion::V1) {
48 return Block::EVENT_TYPE_1_PACKET_LENGTH;
49 }
50 if (packet_version == Block::EventPacketVersion::V2) {
51 return Block::EVENT_TYPE_2_PACKET_LENGTH;
52 }
53 return 0;
54}
55
56} // namespace Block
57
58struct FIFO_block
59{
60 std::vector<uint16_t> p_words;
61 FIFO_block() = default;
62 FIFO_block(std::vector<uint16_t> words)
63 : p_words(words)
64 {}
65 virtual ~FIFO_block() = default;
66
67 virtual bool validate() = 0;
68 virtual void reset() = 0;
69};
70
71struct Event : public FIFO_block
72{
73 uint64_t timestamp;
74 uint8_t channel_number;
75 uint16_t channel_number_global;
76
78 : FIFO_block() {};
79 Event(std::vector<uint16_t> words)
80 : FIFO_block(words)
81 {}
82 ~Event() override {}
83};
84
85struct Event_type_1 final : public Event
86{
87 uint8_t TDC_rise_time;
88 uint8_t TDC_falling_time;
89 uint16_t pulse_length;
90
91 bool validate() override
92 {
93 uint16_t trailer = p_words[7];
94 if (trailer != 0xABBA)
95 return false;
96
97 if ((p_words[5] & 0x80) != 0)
98 return false;
99 if ((p_words[5] & 0x8000) != 0)
100 return false;
101
102 return true;
103 }
104
105 Event_type_1(std::vector<uint16_t> words)
106 : Event(words)
107 {
108 channel_number = (p_words[0] & 0x0FF0) >> 4;
109 // Timestamp
110 timestamp = 0;
111 for (size_t i = 0; i < 4; i++)
112 timestamp += uint64_t(p_words[i + 1]) << 16 * i;
113 TDC_rise_time = p_words[5] & 0x007F;
114 TDC_falling_time = (p_words[5] & 0x7F00) >> 8;
116 }
117
119 : Event()
120 {}
121 ~Event_type_1() override {}
122 void reset() override { *this = Event_type_1(); }
123};
124
125struct Event_type_2 final : public Event
126{
127 uint8_t TDC_rise_time;
128 uint8_t TDC_falling_time;
129 uint8_t raw_tdc_rise_0;
130 uint8_t raw_tdc_rise_1;
131 uint8_t raw_tdc_rise_2;
132 uint8_t raw_tdc_rise_3;
133 uint8_t TDC_time_rise_0;
134 uint8_t TDC_time_rise_1;
135 uint8_t TDC_time_rise_2;
136 uint8_t TDC_time_rise_3;
137 uint8_t raw_tdc_fall_0;
138 uint8_t raw_tdc_fall_1;
139 uint8_t raw_tdc_fall_2;
140 uint8_t raw_tdc_fall_3;
141 uint8_t TDC_time_fall_0;
142 uint8_t TDC_time_fall_1;
143 uint8_t TDC_time_fall_2;
144 uint8_t TDC_time_fall_3;
145 uint8_t post_gen_rise;
146 uint8_t post_gen_fall;
147 uint16_t pulse_length;
148
149 bool validate() override
150 {
151 uint16_t trailer = (p_words[15] & 0xFF00) >> 8;
152 if (trailer != 0xB0)
153 return false;
154
155 if ((p_words[13] & 0x80) != 0)
156 return false;
157 if ((p_words[13] & 0x8000) != 0)
158 return false;
159
160 return true;
161 }
162
163 Event_type_2(std::vector<uint16_t> words)
164 : Event(words)
165 {
166 channel_number = (p_words[0] & 0x0FF0) >> 4;
167 // Timestamp
168 timestamp = 0;
169 for (int i = 0; i < 4; i++)
170 timestamp += uint64_t(p_words[i + 1]) << 16 * i;
171 raw_tdc_rise_0 = p_words[5] & 0x00FF;
172 raw_tdc_rise_1 = (p_words[5] & 0xFF00) >> 8;
173 raw_tdc_rise_2 = p_words[6] & 0x00FF;
174 raw_tdc_rise_3 = (p_words[6] & 0xFF00) >> 8;
175 TDC_time_rise_0 = p_words[7] & 0x00FF;
176 TDC_time_rise_1 = (p_words[7] & 0xFF00) >> 8;
177 TDC_time_rise_2 = p_words[8] & 0x00FF;
178 TDC_time_rise_3 = (p_words[8] & 0xFF00) >> 8;
179 raw_tdc_fall_0 = p_words[9] & 0x00FF;
180 raw_tdc_fall_1 = (p_words[9] & 0xFF00) >> 8;
181 raw_tdc_fall_2 = p_words[10] & 0x00FF;
182 raw_tdc_fall_3 = (p_words[10] & 0xFF00) >> 8;
183 TDC_time_fall_0 = p_words[11] & 0x00FF;
184 TDC_time_fall_1 = (p_words[11] & 0xFF00) >> 8;
185 TDC_time_fall_2 = p_words[12] & 0x00FF;
186 TDC_time_fall_3 = (p_words[12] & 0xFF00) >> 8;
187 TDC_rise_time = p_words[13] & 0x007F;
188 TDC_falling_time = (p_words[13] & 0x7F00) >> 8;
189 pulse_length = p_words[14];
190 post_gen_rise = p_words[15] & 0x000F;
191 post_gen_rise = (p_words[15] & 0x00F0) >> 4;
193 }
194
196 : Event()
197 {}
198 ~Event_type_2() override {}
199 void reset() override { *this = Event_type_2(); }
200};
201
202} // namespace BmnHgndRaw
203
204#endif
int i
Definition P4_F32vec4.h:22
bool is_word_event_header(uint16_t word)
Definition BmnHgndRaw.h:18
uint16_t get_block_size(EventPacketVersion packet_version=ERR)
Definition BmnHgndRaw.h:45
EventPacketVersion get_event_packet_version(uint16_t word)
Definition BmnHgndRaw.h:31
Event_type_1(std::vector< uint16_t > words)
Definition BmnHgndRaw.h:105
bool validate() override
Definition BmnHgndRaw.h:91
void reset() override
Definition BmnHgndRaw.h:122
Event_type_2(std::vector< uint16_t > words)
Definition BmnHgndRaw.h:163
bool validate() override
Definition BmnHgndRaw.h:149
void reset() override
Definition BmnHgndRaw.h:199
Event(std::vector< uint16_t > words)
Definition BmnHgndRaw.h:79
~Event() override
Definition BmnHgndRaw.h:82
uint64_t timestamp
Definition BmnHgndRaw.h:73
uint8_t channel_number
Definition BmnHgndRaw.h:74
uint16_t channel_number_global
Definition BmnHgndRaw.h:75
virtual bool validate()=0
FIFO_block(std::vector< uint16_t > words)
Definition BmnHgndRaw.h:62
std::vector< uint16_t > p_words
Definition BmnHgndRaw.h:60
virtual void reset()=0
virtual ~FIFO_block()=default