CbmRoot
Loading...
Searching...
No Matches
CriGet4Mess001.h
Go to the documentation of this file.
1/* Copyright (C) 2018-2020 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau [committer] */
4
5#ifndef CRI_GET4_MESS_V0_01_DEF_H
6#define CRI_GET4_MESS_V0_01_DEF_H
7
8#include <cstdint>
9#include <iostream>
10
11namespace critof001
12{
13 // Size of one clock cycle (=1 coarse bin)
14 const double kdClockCycleSize = 6250.0; //[ps]
15 const double kdClockCycleSizeNs = kdClockCycleSize / 1000.0; //[ns]
16 // TODO:For now make 100ps default, maybe need later an option for it
17 const double kdTotBinSize = 50.0; //ps
18
19 const uint32_t kuFineTime = 0x0000007F; // Fine Counter value
20 const uint32_t kuFtShift = 0; // Fine Counter offset
21 const uint32_t kuCoarseTime = 0x0007FF80; // Coarse Counter value
22 const uint32_t kuCtShift = 7; // Coarse Counter offset
23 const uint32_t kuCtSize = 12; // Coarse Counter size in bits
24
25 const uint32_t kuFineCounterSize = ((kuFineTime >> kuFtShift) + 1);
26 const uint32_t kuCoarseCounterSize = ((kuCoarseTime >> kuCtShift) + 1);
27 const uint32_t kuCoarseOverflowTest = kuCoarseCounterSize / 2; // Limit for overflow check
28 const uint32_t kuTotCounterSize = 256;
29
31 const double kdFtBinsNb = 112.;
32
33 // Nominal bin size of NL are neglected
35 // Epoch Size in bins
37 // Epoch Size in ps
38 // alternatively: (kiCoarseTime>>kiCtShift + 1)*kdClockCycleSize
39 const double kdEpochInPs = static_cast<double>(kuCoarseCounterSize) * kdClockCycleSize;
40 const double kdEpochInNs = kdEpochInPs / 1000.0;
41 const double kuEpochInNs = static_cast<uint64_t>(kdEpochInNs);
42
43 // Epoch counter size in epoch
44 const uint32_t kuEpochCounterSz = 0xFFFFFF;
45 // Epoch counter size in epoch
46 const uint64_t kulEpochCycleEp = static_cast<uint64_t>(kuEpochCounterSz + 1);
47 // Epoch counter size in bin
49 // Epoch counter size in ns (fits in 64b unsigned as epoch is an integer in ns)
51 // Epoch counter size in s
52 const double kdEpochCycleInS = static_cast<double>(kuEpochCounterSz + 1) * (kdEpochInNs / 1e9);
53
54 // Epoch Cycle MS start message size in bits
55 const uint64_t kulEpochCycleFieldSz = 0x1FFFFF; // 21 bits
56
57 const uint32_t kuChipIdMergedEpoch = 255; // 0xFF
58
59 const uint32_t kuFeePulserChannel = 3; // Channel where a pulser can be set ON at 20 ns 500 Hz
60 const uint32_t kuFeePulserChannelDiam = 0; // Channel where a pulser can be set ON at 20 ns 500 Hz
61
62 const uint64_t kuEndOfMsMask = 0xFFFFFFFFFFFF;
63 const uint64_t kuEndOfMsMarker = 0xdeadbeeeeeef;
64
66 {
70 MSG_SYST = 3
71 };
72
74 {
75 SYS_GET4_ERROR = 0, // GET4 error event
76 SYS_GDPB_UNKWN = 1, // Raw data from gDPB in case of unknown message type from GET4
77 SYS_GET4_SYNC_MISS = 2, // Added when GET4 is missing the SYNC flag when it is expected
78 // SYS_SYNC_ERROR = 3 // added to data stream when the closy-sync-strobe does not match the gDPB 160MHz timestamp counter
79 SYS_PATTERN = 3 // added to data stream when one of the ASIC patterns (missmatch, enable, resync) changed
80 };
81
83 {
84 PATT_MISSMATCH = 0, // Missmatch pattern, 1 bit per ASIC
85 PATT_ENABLE = 1, // Enable pattern, 1 bit per ASIC
86 PATT_RESYNC = 2, // Resync request pattern, 1 bit per ASIC
87 PATT_STATUS = 3 // Status pattern, 1 bit per ASIC (SW only)
88 };
89
97
104
112
137
138 class Message {
139
140 protected:
141 uint64_t data; // main and only storage field for the message
142
143 public:
144 Message() : data(0) {}
145
146 Message(const Message& src) : data(src.data) {}
147
148 Message(uint64_t dataIn) : data(dataIn) {}
149
151
152 void assign(const Message& src) { data = src.data; }
153
155 {
156 assign(src);
157 return *this;
158 }
159
160 inline void reset() { data = 0; }
161
162 inline uint64_t getData() const { return data; }
163 inline void setData(uint64_t value) { data = value; }
164
165 inline uint64_t getFieldLong(uint32_t shift, uint32_t len) const
166 {
167 return (data >> shift) & (((static_cast<uint64_t>(1)) << len) - 1);
168 }
169
170 inline uint32_t getField(uint32_t shift, uint32_t len) const
171 {
172 return (data >> shift) & (((static_cast<uint64_t>(1)) << len) - 1);
173 }
174
175 inline void setField(uint32_t shift, uint32_t len, uint32_t value)
176 {
177 uint64_t mask = (((static_cast<uint64_t>(1)) << len) - 1);
178 data = (data & ~(mask << shift)) | ((static_cast<uint64_t>(value) & mask) << shift);
179 }
180
181 inline void setFieldLong(uint32_t shift, uint32_t len, uint64_t value)
182 {
183 uint64_t mask = (((static_cast<uint64_t>(1)) << len) - 1);
184 data = (data & ~(mask << shift)) | ((value & mask) << shift);
185 }
186
187 inline uint8_t getBit(uint32_t shift) const { return (data >> shift) & 1; }
188
189 inline void setBit(uint32_t shift, uint8_t value)
190 {
191 data = value ? (data | ((static_cast<uint64_t>(1)) << shift)) : (data & ~((static_cast<uint64_t>(1)) << shift));
192 }
193
194
195 inline uint32_t getFieldBE(uint32_t shift, uint32_t len) const
196 {
197 return (dataBE() >> shift) & (((static_cast<uint32_t>(1)) << len) - 1);
198 }
199 inline uint8_t getBitBE(uint32_t shift) const { return (dataBE() >> shift) & 1; }
200 inline uint64_t dataBE() const
201 {
202 return ((data & 0x00000000000000FF) << 56) + ((data & 0x000000000000FF00) << 40)
203 + ((data & 0x0000000000FF0000) << 24) + ((data & 0x00000000FF000000) << 8)
204 + ((data >> 8) & 0x00000000FF000000) + ((data >> 24) & 0x0000000000FF0000)
205 + ((data >> 40) & 0x000000000000FF00) + ((data >> 56) & 0x00000000000000FF);
206 }
207
208 // --------------------------- common fields ---------------------------------
209
211 inline uint8_t getMessageType() const { return getField(0, 4); }
212
214 inline void setMessageType(uint8_t v) { setField(0, 4, v); }
215
216 // ---------- All types access methods ------------------------------------
217 inline uint16_t getDebugTimer() const { return getField(48, 16); }
218 inline void setDebugTimer(uint32_t v) { setField(48, 16, v); }
219 inline uint16_t getGet4Idx() const { return getField(40, 8); }
220 inline void setGet4Id(uint32_t v) { setField(40, 8, v); }
221
222 // ---------- Get4 Hit access methods -------------------------------------
223 inline uint16_t getGdpbHitChanId() const { return getField(32, 2); }
224 inline uint32_t getGdpbHitFullTs() const { return getField(13, 19); }
225 inline bool getGdpbHit32DllLck() const { return getBit(12); }
226 inline uint16_t getGdpbHit32Tot() const { return getField(4, 8); }
227
228 // ---------- Get4 Epoch access methods ----------------------------------
229 inline uint32_t getGdpbEpEpochNb() const { return getField(8, 24); }
230 inline bool getGdpbEpSync() const { return getBit(7); }
231 inline bool getGdpbEpDataLoss() const { return getBit(6); }
232 inline bool getGdpbEpEpochLoss() const { return getBit(5); }
233 inline bool getGdpbEpMissmatch() const { return getBit(4); }
234
235 // ---------- Get4 gDPB 24b/32b Slow cont. access methods -----------------
236 inline uint32_t getGdpbSlcMess() const { return getField(4, 29); }
237 inline uint32_t getGdpbSlcChan() const { return getField(31, 2); }
238 inline uint32_t getGdpbSlcEdge() const { return getBit(30); }
239 inline uint32_t getGdpbSlcType() const { return getField(28, 2); }
240 inline uint32_t getGdpbSlcData() const { return getField(4, 24); }
241
242 // ---------- Get4 gDPB System Msg access methods -------------------------
243 inline uint16_t getGdpbSysSubType() const { return getField(38, 2); }
244 inline bool getGdpbSysLinkId() const { return getBit(37); }
245 // ---------- Get4 gDPB 24b/32b Errors access methods ---------------------
246 inline bool getGdpbSysErrRoType() const { return getBit(36); }
247 inline uint16_t getGdpbSysErrUnused() const { return getField(32, 4); }
248 inline uint16_t getGdpbSysErrInfo() const { return getField(11, 21); }
249 inline uint16_t getGdpbSysErrChanId() const { return getField(12, 2); }
250 inline bool getGdpbSysErrEdge() const { return getBit(11); }
251 inline uint16_t getGdpbSysErrData() const { return getField(4, 7); }
252 // ---------- Get4 gDPB unknown msg type access methods -------------------
253 inline uint32_t getGdpbSysUnkwData() const { return getField(4, 32); }
254 // ---------- FW error msg type access methods ----------------------------
255 inline uint32_t getGdpbSysFwErrResync() const { return getBit(36); }
256 // ---------- ASIC Pattern messages access methods ------------------------
257 inline uint16_t getGdpbSysPattType() const { return getField(46, 2); }
258 inline uint16_t getGdpbSysPattIndex() const { return getField(40, 4); }
259 inline uint32_t getGdpbSysPattPattern() const { return getField(4, 32); }
260
261 // ---------- Get4 gDPB 24b/32b Epoch setter methods ----------------------
262 inline void setGdpbEpEpochNb(uint32_t v) { setField(8, 31, v); }
263
264 // ---------- Get4 gDPB System Msg access methods -------------------------
265 inline void setGdpbSysSubType(uint16_t v) { setField(38, 2, v); }
266 // ---------- ASIC Pattern messages access methods ------------------------
267 inline void setGdpbSysPattType(uint16_t v) { setField(46, 2, v); }
268 inline void setGdpbSysPattIndex(uint16_t v) { setField(40, 4, v); }
269 inline void setGdpbSysPattPattern(uint32_t v) { setField(4, 32, v); }
270
271 // ---------- Common functions -----------------------
273 inline bool isHitMsg() const { return getMessageType() == MSG_HIT; }
275 inline bool isEpochMsg() const { return getMessageType() == MSG_EPOCH; }
277 inline bool isGet4SlCtrMsg() const { return getMessageType() == MSG_SLOWC; }
279 inline bool isSystem() const { return getMessageType() == MSG_SYST; }
281 inline bool isEndOfMs() const { return kuEndOfMsMarker == (data & kuEndOfMsMask); }
282
283 void printDataCout(unsigned kind = msg_print_Prefix | msg_print_Data, uint32_t epoch = 0) const;
284 void printDataLog(unsigned kind = msg_print_Prefix | msg_print_Data, uint32_t epoch = 0) const;
285
286 void printData(unsigned outType = msg_print_Cout, unsigned kind = msg_print_Human, uint32_t epoch = 0,
287 std::ostream& os = std::cout) const;
288
289 uint64_t getMsgFullTime(uint64_t epoch) const;
290
291 double getMsgFullTimeD(uint64_t epoch) const;
292
294 inline static uint64_t FullTimeStamp(uint64_t epoch, uint32_t ts) { return (epoch << 19) | (ts & 0x7ffff); }
295
296
297 static uint64_t CalcDistance(uint64_t start, uint64_t stop);
298
299 static double CalcDistanceD(double start, double stop);
300
301 bool operator<(const critof001::Message& other) const;
302 bool operator==(const critof001::Message& other) const;
303 bool operator!=(const critof001::Message& other) const;
304 };
305
306 class FullMessage : public Message {
307 protected:
308 uint64_t fulExtendedEpoch; // Epoch of the message, extended with 32b epoch cycle counter
309
310 public:
312
313 FullMessage(const Message& src, uint64_t uEpIn = 0) : Message(src), fulExtendedEpoch(uEpIn) {}
314
316
317 void assign(const FullMessage& src)
318 {
319 Message::assign(src);
321 }
322
324 {
325 assign(src);
326 return *this;
327 }
328
329 bool operator<(const FullMessage& other) const;
330
331 inline void reset()
332 {
335 }
336
337 inline uint64_t getExtendedEpoch() const { return fulExtendedEpoch; }
338
339 inline double GetFullTimeNs() const { return getMsgFullTimeD(fulExtendedEpoch); }
340
341 void PrintMessage(unsigned outType = msg_print_Cout, unsigned kind = msg_print_Human) const;
342 };
343
344} // namespace critof001
345
346
347#endif // CRI_GET4_MESS_V0_01_DEF_H
fscal v[fmask::Size]
Definition KfSimdPseudo.h:4
void PrintMessage(unsigned outType=msg_print_Cout, unsigned kind=msg_print_Human) const
FullMessage(const Message &src, uint64_t uEpIn=0)
FullMessage(const FullMessage &src)
bool operator<(const FullMessage &other) const
strict weak ordering operator, including epoch for both messages
uint64_t getExtendedEpoch() const
FullMessage & operator=(const FullMessage &src)
double GetFullTimeNs() const
void assign(const FullMessage &src)
uint32_t getGdpbHitFullTs() const
bool getGdpbHit32DllLck() const
uint32_t getGdpbSysUnkwData() const
Message(const Message &src)
void setGdpbSysSubType(uint16_t v)
void setGdpbEpEpochNb(uint32_t v)
uint16_t getGdpbSysErrChanId() const
uint16_t getGdpbHit32Tot() const
bool operator==(const critof001::Message &other) const
equality operator, assumes same epoch for both messages
bool isEpochMsg() const
Returns true is message type is MSG_EPOCH (epoch2 marker)
bool isEndOfMs() const
Returns true is message type is an EndOfMs marker.
bool operator!=(const critof001::Message &other) const
inequality operator, assumes same epoch for both messages
uint8_t getBitBE(uint32_t shift) const
void setDebugTimer(uint32_t v)
void setGdpbSysPattIndex(uint16_t v)
uint64_t getData() const
uint16_t getGdpbSysErrInfo() const
bool isGet4SlCtrMsg() const
Returns true is message type is MSG_SLOWC (GET4 Slow Control)
uint32_t getGdpbSlcEdge() const
void printDataLog(unsigned kind=msg_print_Prefix|msg_print_Data, uint32_t epoch=0) const
Print message in human readable format to the Fairroot logger.
uint16_t getGet4Idx() const
bool getGdpbEpEpochLoss() const
uint8_t getMessageType() const
Returns the message type. Valid for all message types. 2 bit.
static uint64_t CalcDistance(uint64_t start, uint64_t stop)
Returns the time difference between two expanded time stamps.
uint32_t getGdpbSlcMess() const
uint32_t getGdpbSysPattPattern() const
bool isHitMsg() const
Returns true is message type is MSG_HIT (Get4 hit data)
void printData(unsigned outType=msg_print_Cout, unsigned kind=msg_print_Human, uint32_t epoch=0, std::ostream &os=std::cout) const
Print message in binary or human readable format to a stream.
void setFieldLong(uint32_t shift, uint32_t len, uint64_t value)
void setGet4Id(uint32_t v)
uint16_t getGdpbSysErrUnused() const
uint32_t getField(uint32_t shift, uint32_t len) const
Message(uint64_t dataIn)
uint16_t getGdpbHitChanId() const
uint64_t getFieldLong(uint32_t shift, uint32_t len) const
uint32_t getFieldBE(uint32_t shift, uint32_t len) const
uint16_t getGdpbSysPattType() const
void setField(uint32_t shift, uint32_t len, uint32_t value)
void setBit(uint32_t shift, uint8_t value)
void setMessageType(uint8_t v)
Sets the message type field in the current message.
uint32_t getGdpbSlcType() const
bool getGdpbSysErrEdge() const
bool operator<(const critof001::Message &other) const
strict weak ordering operator, assumes same epoch for both messages
Message & operator=(const Message &src)
bool getGdpbEpSync() const
void setGdpbSysPattPattern(uint32_t v)
void setGdpbSysPattType(uint16_t v)
bool getGdpbEpDataLoss() const
void printDataCout(unsigned kind=msg_print_Prefix|msg_print_Data, uint32_t epoch=0) const
Print message in human readable format to cout.
uint64_t dataBE() const
bool isSystem() const
Returns true is message type is #MSG_ERROR (error message)
bool getGdpbSysLinkId() const
uint32_t getGdpbEpEpochNb() const
uint32_t getGdpbSlcChan() const
uint64_t getMsgFullTime(uint64_t epoch) const
Returns expanded and adjusted time of message (in ns)
uint8_t getBit(uint32_t shift) const
void assign(const Message &src)
uint32_t getGdpbSlcData() const
uint16_t getDebugTimer() const
uint16_t getGdpbSysSubType() const
static double CalcDistanceD(double start, double stop)
Returns the time difference between two expanded time stamps.
uint32_t getGdpbSysFwErrResync() const
double getMsgFullTimeD(uint64_t epoch) const
Returns expanded and adjusted time of message in double (in ns)
void setData(uint64_t value)
uint16_t getGdpbSysPattIndex() const
static uint64_t FullTimeStamp(uint64_t epoch, uint32_t ts)
Expanded timestamp for 160 MHz * 19 bit (12 + 7) epochs.
bool getGdpbEpMissmatch() const
bool getGdpbSysErrRoType() const
uint16_t getGdpbSysErrData() const
const uint32_t kuEpochInBins
const double kdFtSize
const uint32_t kuTotCounterSize
@ GET4_V2X_ERR_UNPAIR_FALL
@ GET4_V2X_ERR_CHAN_STATE
@ GET4_V2X_ERR_ADD_RIS_EDG
@ GET4_V2X_ERR_SEQUENCE_ER
@ GET4_V2X_ERR_TOK_RING_ST
@ GET4_V2X_ERR_TOT_OVERWRT
@ GET4_V2X_ERR_FIFO_WRITE
@ GET4_V2X_ERR_EP_CNT_SYNC
@ GET4_V2X_ERR_EPOCH_OVERF
@ GET4_V2X_ERR_EVT_DISCARD
@ GET4_V2X_ERR_READOUT_ERR
const uint64_t kulEpochCycleInNs
const uint32_t kuCtShift
const uint64_t kuEndOfMsMask
const uint32_t kuCoarseTime
const double kdFtBinsNb
const uint32_t kuCoarseCounterSize
const uint32_t kuFeePulserChannelDiam
const double kdEpochInNs
const uint32_t kuFineTime
const uint64_t kulEpochCycleFieldSz
const double kdClockCycleSize
const uint32_t kuCtSize
const double kdEpochCycleInS
const uint64_t kulEpochCycleEp
const double kdBinSize
const double kdEpochInPs
const uint64_t kulEpochCycleBins
const uint64_t kuEndOfMsMarker
const uint32_t kuEpochCounterSz
Works as epoch integer in ns!
const double kdTotBinSize
const uint32_t kuFineCounterSize
const uint32_t kuChipIdMergedEpoch
const double kuEpochInNs
const double kdClockCycleSizeNs
const uint32_t kuCoarseOverflowTest
const uint32_t kuFtShift
const uint32_t kuFeePulserChannel