CbmRoot
Loading...
Searching...
No Matches
gDpbMessv100.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 GDPB_MESS_V1_00_DEF_H
6#define GDPB_MESS_V1_00_DEF_H
7
8#include <cstdint>
9#include <iostream>
10
11namespace gdpbv100
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
42 // Epoch counter size in epoch
43 const uint32_t kuEpochCounterSz = 0x7FFFFFFF;
44 // Epoch counter size in bin
45 const uint64_t kulEpochCycleBins = static_cast<uint64_t>(kuEpochCounterSz + 1) * kuEpochInBins;
46 // Epoch counter size in s
47 const double kdEpochCycleInS = static_cast<double>(kuEpochCounterSz + 1) * (kdEpochInNs / 1e9);
48
49 // Epoch Cycle MS start message size in bits
50 const uint64_t kulEpochCycleFieldSz = 0x1FFFFF; // 21 bits
51
52 const uint32_t kuChipIdMergedEpoch = 255; // 0xFF
53
54 const uint32_t kuFeePulserChannel = 3; // Channel where a pulser can be set ON at 20 ns 500 Hz
55 const uint32_t kuFeePulserChannelDiam = 0; // Channel where a pulser can be set ON at 20 ns 500 Hz
56
68
70 {
71 SYS_GET4_ERROR = 0, // GET4 error event
72 SYS_GDPB_UNKWN = 1, // Raw data from gDPB in case of unknown message type from GET4
73 SYS_GET4_SYNC_MISS = 2, // Added when GET4 is missing the SYNC flag when it is expected
74 // SYS_SYNC_ERROR = 3 // added to data stream when the closy-sync-strobe does not match the gDPB 160MHz timestamp counter
75 SYS_PATTERN = 3 // added to data stream when one of the ASIC patterns (missmatch, enable, resync) changed
76 };
77
79 {
80 PATT_MISSMATCH = 0, // Missmatch pattern, 1 bit per ASIC
81 PATT_ENABLE = 1, // Enable pattern, 1 bit per ASIC
82 PATT_RESYNC = 2, // Resync request pattern, 1 bit per ASIC
83 PATT_STATUS = 3 // Status pattern, 1 bit per ASIC (SW only)
84 };
85
93
100
108
133
134 class Message {
135
136 protected:
137 uint64_t data; // main and only storage field for the message
138
139 public:
140 Message() : data(0) {}
141
142 Message(const Message& src) : data(src.data) {}
143
144 Message(uint64_t dataIn) : data(dataIn) {}
145
147
148 void assign(const Message& src) { data = src.data; }
149
151 {
152 assign(src);
153 return *this;
154 }
155
156 inline void reset() { data = 0; }
157
158 inline uint64_t getData() const { return data; }
159 inline void setData(uint64_t value) { data = value; }
160
161 inline uint64_t getFieldLong(uint32_t shift, uint32_t len) const
162 {
163 return (data >> shift) & (((static_cast<uint64_t>(1)) << len) - 1);
164 }
165
166 inline uint32_t getField(uint32_t shift, uint32_t len) const
167 {
168 return (data >> shift) & (((static_cast<uint64_t>(1)) << len) - 1);
169 }
170
171 inline void setField(uint32_t shift, uint32_t len, uint32_t value)
172 {
173 uint64_t mask = (((static_cast<uint64_t>(1)) << len) - 1);
174 data = (data & ~(mask << shift)) | ((static_cast<uint64_t>(value) & mask) << shift);
175 }
176
177 inline void setFieldLong(uint32_t shift, uint32_t len, uint64_t value)
178 {
179 uint64_t mask = (((static_cast<uint64_t>(1)) << len) - 1);
180 data = (data & ~(mask << shift)) | ((value & mask) << shift);
181 }
182
183 inline uint8_t getBit(uint32_t shift) const { return (data >> shift) & 1; }
184
185 inline void setBit(uint32_t shift, uint8_t value)
186 {
187 data = value ? (data | ((static_cast<uint64_t>(1)) << shift)) : (data & ~((static_cast<uint64_t>(1)) << shift));
188 }
189
190
191 inline uint32_t getFieldBE(uint32_t shift, uint32_t len) const
192 {
193 return (dataBE() >> shift) & (((static_cast<uint32_t>(1)) << len) - 1);
194 }
195 inline uint8_t getBitBE(uint32_t shift) const { return (dataBE() >> shift) & 1; }
196 inline uint64_t dataBE() const
197 {
198 return ((data & 0x00000000000000FF) << 56) + ((data & 0x000000000000FF00) << 40)
199 + ((data & 0x0000000000FF0000) << 24) + ((data & 0x00000000FF000000) << 8)
200 + ((data >> 8) & 0x00000000FF000000) + ((data >> 24) & 0x0000000000FF0000)
201 + ((data >> 40) & 0x000000000000FF00) + ((data >> 56) & 0x00000000000000FF);
202 }
203
204 // --------------------------- common fields ---------------------------------
205
207 inline uint8_t getMessageType() const { return getField(0, 3); }
208
210 inline void setMessageType(uint8_t v) { setField(0, 3, v); }
211
212 // ---------- Get4 gDPB 24b/32b ALL access methods ------------------------
213 inline uint16_t getGdpbGenGdpbId() const { return getField(48, 16); }
214 inline void setGdpbGenGdpbId(uint32_t v) { setField(48, 16, v); }
215 inline uint16_t getGdpbGenChipId() const { return getField(40, 8); }
216 inline void setGdpbGenChipId(uint32_t v) { setField(40, 8, v); }
217
218 // ---------- Get4 gDPB 24b/32b Hit access methods ------------------------
219 inline uint16_t getGdpbHitIs24b() const { return getBit(39); }
220 inline uint16_t getGdpbHitChanId() const { return getField(32, 2); }
221 inline uint32_t getGdpbHitFullTs() const { return getField(13, 19); }
222 inline uint16_t getGdpbHitCoarse() const { return getField(20, 12); }
223 inline uint16_t getGdpbHitFineTs() const { return getField(13, 7); }
224 // ---------- Get4 gDPB 24b Hit access methods ----------------------------
225 inline bool getGdpbHit24Edge() const { return getBit(34); }
226 // ---------- Get4 gDPB 32b Hit access methods ----------------------------
227 inline bool getGdpbHit32DllLck() const { return getBit(12); }
228 inline uint16_t getGdpbHit32Tot() const { return getField(4, 8); }
229
230 // ---------- Get4 gDPB 24b/32b Epoch access methods ----------------------
231 inline bool getGdpbEpLinkId() const { return getBit(39); }
232 inline uint32_t getGdpbEpEpochNb() const { return getField(8, 31); }
233 inline bool getGdpbEpSync() const { return getBit(7); }
234 inline bool getGdpbEpDataLoss() const { return getBit(6); }
235 inline bool getGdpbEpEpochLoss() const { return getBit(5); }
236 inline bool getGdpbEpMissmatch() const { return getBit(4); }
237
238 // ---------- Get4 gDPB 24b/32b Slow cont. access methods -----------------
239 inline uint32_t getGdpbSlcMess() const { return getField(4, 29); }
240 inline uint32_t getGdpbSlcChan() const { return getField(31, 2); }
241 inline uint32_t getGdpbSlcEdge() const { return getBit(30); }
242 inline uint32_t getGdpbSlcType() const { return getField(28, 2); }
243 inline uint32_t getGdpbSlcData() const { return getField(4, 24); }
244
245 // ---------- Get4 gDPB System Msg access methods -------------------------
246 inline uint16_t getGdpbSysSubType() const { return getField(38, 2); }
247 inline bool getGdpbSysLinkId() const { return getBit(37); }
248 // ---------- Get4 gDPB 24b/32b Errors access methods ---------------------
249 inline bool getGdpbSysErrRoType() const { return getBit(36); }
250 inline uint16_t getGdpbSysErrUnused() const { return getField(32, 4); }
251 inline uint16_t getGdpbSysErrInfo() const { return getField(11, 21); }
252 inline uint16_t getGdpbSysErrChanId() const { return getField(12, 2); }
253 inline bool getGdpbSysErrEdge() const { return getBit(11); }
254 inline uint16_t getGdpbSysErrData() const { return getField(4, 7); }
255 // ---------- Get4 gDPB unknown msg type access methods -------------------
256 inline uint32_t getGdpbSysUnkwData() const { return getField(4, 32); }
257 // ---------- FW error msg type access methods ----------------------------
258 inline uint32_t getGdpbSysFwErrResync() const { return getBit(36); }
259 // ---------- ASIC Pattern messages access methods ------------------------
260 inline uint16_t getGdpbSysPattType() const { return getField(46, 2); }
261 inline uint16_t getGdpbSysPattIndex() const { return getField(40, 4); }
262 inline uint32_t getGdpbSysPattPattern() const { return getField(4, 32); }
263
264 // ---------- STAR Trigger messages access methods ------------------------
265 inline uint16_t getStarTrigMsgIndex() const { return getField(0, 2); }
266 //++++//
267 inline uint64_t getGdpbTsMsbStarA() const { return getFieldLong(4, 40); }
268 //++++//
269 inline uint64_t getGdpbTsLsbStarB() const { return getFieldLong(20, 24); }
270 inline uint64_t getStarTsMsbStarB() const { return getFieldLong(4, 16); }
271 //++++//
272 inline uint64_t getStarTsMidStarC() const { return getFieldLong(4, 40); }
273 //++++//
274 inline uint64_t getStarTsLsbStarD() const { return getFieldLong(36, 8); }
276 inline uint32_t getStarFillerD() const { return getField(24, 12); } // Should be always 0
277 inline uint32_t getStarTrigCmdStarD() const { return getField(20, 4); }
278 inline uint32_t getStarDaqCmdStarD() const { return getField(16, 4); }
279 inline uint32_t getStarTokenStarD() const { return getField(4, 12); }
280
281 // ---------- Get4 gDPB 24b/32b Epoch setter methods ----------------------
282 inline void setGdpbEpEpochNb(uint32_t v) { setField(8, 31, v); }
283
284 // ---------- Get4 gDPB System Msg access methods -------------------------
285 inline void setGdpbSysSubType(uint16_t v) { setField(38, 2, v); }
286 // ---------- ASIC Pattern messages access methods ------------------------
287 inline void setGdpbSysPattType(uint16_t v) { setField(46, 2, v); }
288 inline void setGdpbSysPattIndex(uint16_t v) { setField(40, 4, v); }
289 inline void setGdpbSysPattPattern(uint32_t v) { setField(4, 32, v); }
290
291 // ---------- STAR Trigger messages setter methods ------------------------
292 inline void setStarTrigMsgIndex(uint8_t v) { setField(0, 2, v); }
293 //++++//
294 inline void setGdpbTsMsbStarA(uint64_t fullGdpbTs) { setFieldLong(4, 40, (fullGdpbTs >> 24)); }
295 //++++//
296 inline void setGdpbTsLsbStarB(uint64_t fullGdpbTs) { setFieldLong(20, 24, (fullGdpbTs)); }
297 inline void setStarTsMsbStarB(uint64_t fullStarTs) { setFieldLong(4, 16, (fullStarTs >> 48)); }
298 //++++//
299 inline void setStarTsMidStarC(uint64_t fullStarTs) { setFieldLong(4, 40, (fullStarTs >> 8)); }
300 //++++//
301 inline void setStarTsLsbStarD(uint64_t fullStarTs) { setFieldLong(36, 8, (fullStarTs)); }
303 inline void setStarFillerD() { setField(24, 12, 0); } // Should be always 0
304 inline void setStarTrigCmdStarD(uint8_t v) { setField(20, 4, v); }
305 inline void setStarDaqCmdStarD(uint8_t v) { setField(16, 4, v); }
306 inline void setStarTokenStarD(uint16_t v) { setField(4, 12, v); }
307
308 // ---------- Common functions -----------------------
310 inline bool isHitMsg() const { return getMessageType() == MSG_HIT; }
312 inline bool isEpochMsg() const { return getMessageType() == MSG_EPOCH; }
314 inline bool isGet4SlCtrMsg() const { return getMessageType() == MSG_SLOWC; }
316 inline bool isSysMsg() const { return getMessageType() == MSG_SYST; }
318 inline bool isStarTrigger() const { return MSG_STAR_TRI_A <= getMessageType(); }
319
320 void printDataCout(unsigned kind = msg_print_Prefix | msg_print_Data, uint32_t epoch = 0) const;
321 void printDataLog(unsigned kind = msg_print_Prefix | msg_print_Data, uint32_t epoch = 0) const;
322
323 void printData(unsigned outType = msg_print_Cout, unsigned kind = msg_print_Human, uint32_t epoch = 0,
324 std::ostream& os = std::cout) const;
325
326 uint64_t getMsgFullTime(uint64_t epoch) const;
327
328 double getMsgFullTimeD(uint64_t epoch) const;
329
331 inline static uint64_t FullTimeStamp(uint64_t epoch, uint32_t ts) { return (epoch << 19) | (ts & 0x7ffff); }
332
333
334 static uint64_t CalcDistance(uint64_t start, uint64_t stop);
335
336 static double CalcDistanceD(double start, double stop);
337
338 bool operator<(const gdpbv100::Message& other) const;
339 bool operator==(const gdpbv100::Message& other) const;
340 bool operator!=(const gdpbv100::Message& other) const;
341 };
342
343 class FullMessage : public Message {
344 protected:
345 uint64_t fulExtendedEpoch; // Epoch of the message, extended with 32b epoch cycle counter
346
347 public:
349
350 FullMessage(const Message& src, uint64_t uEpIn = 0) : Message(src), fulExtendedEpoch(uEpIn) {}
351
353
354 void assign(const FullMessage& src)
355 {
356 Message::assign(src);
358 }
359
361 {
362 assign(src);
363 return *this;
364 }
365
366 bool operator<(const FullMessage& other) const;
367
368 inline void reset()
369 {
372 }
373
374 inline uint64_t getExtendedEpoch() const { return fulExtendedEpoch; }
375
376 inline double GetFullTimeNs() const { return getMsgFullTimeD(fulExtendedEpoch); }
377
378 void PrintMessage(unsigned outType = msg_print_Cout, unsigned kind = msg_print_Human) const;
379 };
380
381} // namespace gdpbv100
382
383
384#endif // GDPB_MESS_V1_00_DEF_H
fscal v[fmask::Size]
Definition KfSimdPseudo.h:4
FullMessage & operator=(const FullMessage &src)
void assign(const FullMessage &src)
void PrintMessage(unsigned outType=msg_print_Cout, unsigned kind=msg_print_Human) const
FullMessage(const Message &src, uint64_t uEpIn=0)
double GetFullTimeNs() const
bool operator<(const FullMessage &other) const
strict weak ordering operator, including epoch for both messages
FullMessage(const FullMessage &src)
uint64_t getExtendedEpoch() const
static uint64_t CalcDistance(uint64_t start, uint64_t stop)
Returns the time difference between two expanded time stamps.
uint16_t getGdpbHitIs24b() const
uint16_t getStarTrigMsgIndex() const
Message(const Message &src)
uint32_t getGdpbEpEpochNb() const
uint16_t getGdpbHit32Tot() const
uint16_t getGdpbSysPattType() const
void setStarTsLsbStarD(uint64_t fullStarTs)
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.
uint64_t getStarTsMidStarC() const
uint16_t getGdpbSysSubType() const
uint64_t getGdpbTsLsbStarB() const
uint8_t getBit(uint32_t shift) const
void setGdpbTsMsbStarA(uint64_t fullGdpbTs)
uint32_t getGdpbSlcChan() const
void setData(uint64_t value)
void setGdpbSysPattType(uint16_t v)
bool getGdpbEpMissmatch() const
bool getGdpbHit24Edge() const
double getMsgFullTimeD(uint64_t epoch) const
Returns expanded and adjusted time of message in double (in ns)
uint16_t getGdpbSysPattIndex() const
void setStarTrigCmdStarD(uint8_t v)
void setGdpbGenChipId(uint32_t v)
uint64_t getFieldLong(uint32_t shift, uint32_t len) const
uint64_t dataBE() const
uint16_t getGdpbHitFineTs() const
uint32_t getGdpbSlcData() const
void setGdpbEpEpochNb(uint32_t v)
bool getGdpbEpSync() const
uint32_t getGdpbSysFwErrResync() const
uint64_t getStarTsMsbStarB() const
void setStarFillerD()
12 bits in between are set to 0
void setStarTokenStarD(uint16_t v)
uint32_t getGdpbHitFullTs() const
uint32_t getStarTrigCmdStarD() const
uint32_t getGdpbSysPattPattern() const
uint32_t getGdpbSlcType() const
bool isStarTrigger() const
Returns true is message type is MSG_STAR_TRI_A, _B, _C, _D (STAR Trigger message)
bool getGdpbHit32DllLck() const
Message & operator=(const Message &src)
uint16_t getGdpbGenGdpbId() const
bool getGdpbSysLinkId() const
bool getGdpbEpEpochLoss() const
uint32_t getStarDaqCmdStarD() const
void setBit(uint32_t shift, uint8_t value)
void setGdpbSysPattPattern(uint32_t v)
void setMessageType(uint8_t v)
Sets the message type field in the current message.
static uint64_t FullTimeStamp(uint64_t epoch, uint32_t ts)
Expanded timestamp for 160 MHz * 19 bit (12 + 7) epochs.
uint64_t getGdpbTsMsbStarA() const
void setStarTsMsbStarB(uint64_t fullStarTs)
uint16_t getGdpbGenChipId() const
bool isHitMsg() const
Returns true is message type is MSG_HIT (Get4 hit data)
uint16_t getGdpbSysErrUnused() const
void setStarTsMidStarC(uint64_t fullStarTs)
void printDataCout(unsigned kind=msg_print_Prefix|msg_print_Data, uint32_t epoch=0) const
Print message in human readable format to cout.
void setField(uint32_t shift, uint32_t len, uint32_t value)
bool getGdpbEpDataLoss() const
uint32_t getStarFillerD() const
12 bits in between are set to 0
bool getGdpbSysErrRoType() const
void setGdpbSysPattIndex(uint16_t v)
bool isGet4SlCtrMsg() const
Returns true is message type is MSG_SLOWC (GET4 Slow Control)
uint16_t getGdpbHitCoarse() const
uint32_t getStarTokenStarD() const
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 setGdpbGenGdpbId(uint32_t v)
bool operator<(const gdpbv100::Message &other) const
strict weak ordering operator, assumes same epoch for both messages
bool operator!=(const gdpbv100::Message &other) const
inequality operator, assumes same epoch for both messages
void setStarDaqCmdStarD(uint8_t v)
uint32_t getGdpbSlcMess() const
void setFieldLong(uint32_t shift, uint32_t len, uint64_t value)
bool getGdpbEpLinkId() const
uint32_t getFieldBE(uint32_t shift, uint32_t len) const
bool operator==(const gdpbv100::Message &other) const
equality operator, assumes same epoch for both messages
uint8_t getBitBE(uint32_t shift) const
uint32_t getGdpbSlcEdge() const
static double CalcDistanceD(double start, double stop)
Returns the time difference between two expanded time stamps.
uint64_t getStarTsLsbStarD() const
void setGdpbTsLsbStarB(uint64_t fullGdpbTs)
uint8_t getMessageType() const
Returns the message type. Valid for all message types. 4 bit.
void assign(const Message &src)
void setStarTrigMsgIndex(uint8_t v)
uint32_t getGdpbSysUnkwData() const
Message(uint64_t dataIn)
uint64_t getData() const
uint16_t getGdpbSysErrData() const
bool getGdpbSysErrEdge() const
uint16_t getGdpbSysErrInfo() const
uint16_t getGdpbSysErrChanId() const
void setGdpbSysSubType(uint16_t v)
uint64_t getMsgFullTime(uint64_t epoch) const
Returns expanded and adjusted time of message (in ns)
bool isSysMsg() const
Returns true is message type is MSG_SYST (system message)
bool isEpochMsg() const
Returns true is message type is MSG_EPOCH (epoch2 marker)
uint16_t getGdpbHitChanId() const
uint32_t getField(uint32_t shift, uint32_t len) const
const uint32_t kuFineTime
const uint32_t kuFeePulserChannelDiam
const double kdEpochCycleInS
const double kdClockCycleSize
const double kdClockCycleSizeNs
const uint64_t kulEpochCycleBins
const uint32_t kuCoarseTime
const uint32_t kuFineCounterSize
@ GET4_32B_SLC_SCALER
@ GET4_32B_SLC_DEADT
@ GET4_32B_SLC_SPIREAD
@ GET4_32B_SLC_START_SEU
const double kdBinSize
const uint32_t kuCtShift
const uint32_t kuTotCounterSize
@ GET4_V2X_ERR_LOST_EVT
@ GET4_V2X_ERR_TOT_RANGE
@ GET4_V2X_ERR_FIFO_WRITE
@ GET4_V2X_ERR_DLL_LOCK
@ GET4_V2X_ERR_EPOCH_OVERF
@ GET4_V2X_ERR_EP_CNT_SYNC
@ GET4_V2X_ERR_UNKNOWN
@ GET4_V2X_ERR_READ_INIT
@ GET4_V2X_ERR_DLL_RESET
@ GET4_V2X_ERR_ADD_RIS_EDG
@ GET4_V2X_ERR_TOK_RING_ST
@ GET4_V2X_ERR_TOKEN
@ GET4_V2X_ERR_TOT_OVERWRT
@ GET4_V2X_ERR_READOUT_ERR
@ GET4_V2X_ERR_EVT_DISCARD
@ GET4_V2X_ERR_UNPAIR_FALL
@ GET4_V2X_ERR_CHAN_STATE
@ GET4_V2X_ERR_SYNC
@ GET4_V2X_ERR_SEQUENCE_ER
const double kdTotBinSize
const uint32_t kuCtSize
const double kdEpochInPs
const uint32_t kuChipIdMergedEpoch
const double kdFtBinsNb
const uint32_t kuFeePulserChannel
const uint32_t kuEpochCounterSz
const double kdFtSize
const double kdEpochInNs
@ msg_print_Prefix
@ msg_print_Human
@ msg_print_FairLog
const uint64_t kulEpochCycleFieldSz
const uint32_t kuCoarseCounterSize
const uint32_t kuCoarseOverflowTest
const uint32_t kuEpochInBins
@ SYS_GET4_SYNC_MISS
const uint32_t kuFtShift