stream  0.10.0
stream analysis framework
TdcMessage.h
1 #ifndef HADAQ_TDCMESSAGE_H
2 #define HADAQ_TDCMESSAGE_H
3 
4 #include <cstdint>
5 
6 #include <cstdio>
7 
8 namespace hadaq {
9 
11  enum TdcMessageKind {
12  tdckind_Trailer = 0x00000000,
13  tdckind_Header = 0x20000000,
14  tdckind_Debug = 0x40000000,
15  tdckind_Epoch = 0x60000000,
16  tdckind_Mask = 0xe0000000,
17  tdckind_Hit = 0x80000000,
18  tdckind_Hit1 = 0xa0000000,
19  tdckind_Hit2 = 0xc0000000,
20  tdckind_Calibr = 0xe0000000
21  };
22 
24  enum TdcConstants {
25  MaxNumTdcChannels = 65
26  };
27 
29  enum TdcNewMessageKinds {
30  newkind_TMDT = 0x80000000,
31  // with mask 3
32  newkind_Mask3 = 0xE0000000,
33  newkind_HDR = 0x20000000,
34  newkind_TRL = 0x00000000,
35  newkind_EPOC = 0x60000000,
36  // with mask 4
37  newkind_Mask4 = 0xF0000000,
38  newkind_TMDS = 0x40000000,
39  // with mask 6
40  newkind_Mask6 = 0xFC000000,
41  newkind_TBD = 0x50000000,
42  // with mask 8
43  newkind_Mask8 = 0xFF000000,
44  newkind_HSTM = 0x54000000,
45  newkind_HSTL = 0x55000000,
46  newkind_HSDA = 0x56000000,
47  newkind_HSDB = 0x57000000,
48  newkind_CTA = 0x58000000,
49  newkind_CTB = 0x59000000,
50  newkind_TEMP = 0x5A000000,
51  newkind_BAD = 0x5B000000,
52  // with mask 9
53  newkind_Mask9 = 0xFF800000,
54  newkind_TTRM = 0x5C000000,
55  newkind_TTRL = 0x5C800000,
56  newkind_TTCM = 0x5D000000,
57  newkind_TTCL = 0x5D800000,
58  // with mask 7
59  newkind_Mask7 = 0xFE000000,
60  newkind_TMDR = 0x5E000000
61  };
62 
70  struct TdcMessage {
71  protected:
72  uint32_t fData;
73 
74  static unsigned gFineMinValue;
75  static unsigned gFineMaxValue;
76 
77  public:
78 
80  TdcMessage() : fData(0) {}
81 
83  TdcMessage(uint32_t d) : fData(d) {}
84 
86  void assign(uint32_t d) { fData = d; }
87 
89  inline uint32_t getData() const { return fData; }
90 
92  TdcMessage& operator=(const TdcMessage& src) { fData = src.fData; return *this; }
93 
96  inline uint32_t getKind() const { return fData & tdckind_Mask; }
98  inline bool isHit0Msg() const { return getKind() == tdckind_Hit; }
100  inline bool isHit1Msg() const { return getKind() == tdckind_Hit1; }
102  inline bool isHit2Msg() const { return getKind() == tdckind_Hit2; }
104  inline bool isHitMsg() const { return isHit0Msg() || isHit1Msg() || isHit2Msg(); }
105 
107  inline bool isEpochMsg() const { return getKind() == tdckind_Epoch; }
109  inline bool isDebugMsg() const { return getKind() == tdckind_Debug; }
111  inline bool isHeaderMsg() const { return getKind() == tdckind_Header; }
113  inline bool isTrailerMsg() const { return getKind() == tdckind_Trailer; }
115  inline bool isCalibrMsg() const { return getKind() == tdckind_Calibr; }
116 
117  // methods for epoch
118 
120  inline uint32_t getEpochValue() const { return fData & 0xFFFFFFF; }
122  inline uint32_t getEpochRes() const { return (fData >> 28) & 0x1; }
123 
124  // methods for hit
125 
127  inline uint32_t getHitChannel() const { return (fData >> 22) & 0x7F; }
128 
130  inline uint32_t getHitTmCoarse() const { return fData & 0x7FF; }
132  inline void setHitTmCoarse(uint32_t coarse) { fData = (fData & ~0x7FF) | (coarse & 0x7FF); }
133 
135  inline uint32_t getHitTmFine() const { return (fData >> 12) & 0x3FF; }
136 
138  inline uint32_t getHitTmStamp() const { return (getHitTmCoarse() << 10) | getHitTmFine(); }
139 
141  inline uint32_t getHitEdge() const { return (fData >> 11) & 0x1; }
142 
144  inline bool isHitRisingEdge() const { return getHitEdge() == 0x1; }
146  inline bool isHitFallingEdge() const { return getHitEdge() == 0x0; }
147 
148  void setAsHit2(uint32_t finebin);
149 
151  inline uint32_t getHitReserved() const { return (fData >> 29) & 0x3; }
152 
153  // methods for calibration message
154 
156  inline uint32_t getCalibrFine(unsigned n = 0) const { return (fData >> n*14) & 0x3fff; }
158  inline void setCalibrFine(unsigned n = 0, uint32_t v = 0) { fData = (fData & ~(0x3fff << n*14)) | ((v & 0x3fff) << n*14); }
159 
160  // methods for header
161 
163  inline uint32_t getHeaderErr() const { return fData & 0xFFFF; }
164 
166  inline uint32_t getHeaderHwType() const { return (fData >> 8) & 0xFF; }
167 
169  inline uint32_t getHeaderRes() const { return (fData >> 16) & 0xFF; }
170 
172  inline uint32_t getHeaderFmt() const { return (fData >> 24) & 0xF; }
173 
175  inline bool IsVer4Header() const { return isHeaderMsg() && (getHeaderFmt() == 4); }
176 
177  // methods for debug message
178 
180  inline uint32_t getDebugKind() const { return (fData >> 24) & 0xF; }
181 
183  inline uint32_t getDebugValue() const { return fData & 0xFFFFFF; }
184 
185 
186  // methods for ver4 messages
187 
189  inline bool isHDR() const { return (fData & newkind_Mask3) == newkind_HDR; }
191  inline bool isEPOC() const { return (fData & newkind_Mask3) == newkind_EPOC; }
193  inline bool isTMDR() const { return (fData & newkind_Mask7) == newkind_TMDR; }
195  inline bool isTMDT() const { return (fData & newkind_TMDT) == newkind_TMDT; }
197  inline bool isTMDS() const { return (fData & newkind_Mask4) == newkind_TMDS; }
199  inline bool isTRL() const { return (fData & newkind_Mask3) == newkind_TRL; }
200 
201 
202  // method for HDR
204  inline uint32_t getHDRMajor() const { return (fData >> 24) & 0xF; }
206  inline uint32_t getHDRMinor() const { return (fData >> 20) & 0xF; }
208  inline uint32_t getHDRTType() const { return (fData >> 16) & 0xF; }
210  inline uint32_t getHDRTrigger() const { return (fData & 0xFFFF); }
211 
212 
214  inline uint32_t getEPOC() const { return fData & 0xFFFFFFF; }
216  inline bool getEPOCError() const { return (fData & 0x10000000) != 0; }
217 
218  // methods for TMDT - hist message
220  inline uint32_t getTMDTMode() const { return (fData >> 27) & 0xF; }
222  inline uint32_t getTMDTChannel() const { return (fData >> 21) & 0x3F; }
224  inline uint32_t getTMDTCoarse() const { return (fData >> 9) & 0xFFF; }
226  inline uint32_t getTMDTFine() const { return fData & 0x1FF; }
227 
228  // methods for TMDR - ref channel message
230  inline uint32_t getTMDRMode() const { return (fData >> 21) & 0xF; }
232  inline uint32_t getTMDRCoarse() const { return (fData >> 9) & 0xFFF; }
234  inline uint32_t getTMDRFine() const { return fData & 0x1FF; }
235 
236  // methods for TMDS - sampling TDC message
238  inline uint32_t getTMDSChannel() const { return (fData >> 21) & 0x7F; }
240  inline uint32_t getTMDSCoarse() const { return (fData >> 9) & 0xFFF; }
242  inline uint32_t getTMDSPattern() const { return fData & 0x1FF; }
243 
244  // methods for TRLA
246  inline uint32_t getTRLAPlatformId() const { return (fData >> 20) & 0xff; }
248  inline uint32_t getTRLAMajor() const { return (fData >> 16) & 0xf; }
250  inline uint32_t getTRLAMinor() const { return (fData >> 12) & 0xf; }
252  inline uint32_t getTRLASub() const { return (fData >> 8) & 0xf; }
254  inline uint32_t getTRLANumCh() const { return (fData & 0x7F) + 1; }
255 
256  // methods for TRLB
258  inline uint32_t getTRLBEflags() const { return (fData >> 24) & 0xF; }
260  inline uint32_t getTRLBMaxdc() const { return (fData >> 20) & 0xF; }
262  inline uint32_t getTRLBTptime() const { return (fData >> 16) & 0xF; }
264  inline uint32_t getTRLBFreq() const { return (fData & 0xFFFF); }
265 
266  // methods for TRLC
268  inline uint32_t getTRLCCpc() const { return (fData >> 24) & 0x7; }
270  inline uint32_t getTRLCCcs() const { return (fData >> 20) & 0xF; }
272  inline uint32_t getTRLCCcdiv() const { return (fData >> 16) & 0xF; }
274  inline uint32_t getTRLCFreq() const { return (fData & 0xFFFF); }
275 
276  void print(double tm = -1.);
277  void print4(uint32_t &ttype);
278 
280  static double CoarseUnit() { return 5e-9; }
281 
283  static double CoarseUnit280() { return 1/2.8e8; }
284 
286  static double SimpleFineCalibr(unsigned fine)
287  {
288  if (fine<=gFineMinValue) return 0.;
289  if (fine>=gFineMaxValue) return CoarseUnit();
290  return (CoarseUnit() * (fine - gFineMinValue)) / (gFineMaxValue - gFineMinValue);
291  }
292 
294  static void SetFineLimits(unsigned min, unsigned max)
295  {
296  gFineMinValue = min;
297  gFineMaxValue = max;
298  }
299 
301  static unsigned GetFineMinValue() { return gFineMinValue; }
303  static unsigned GetFineMaxValue() { return gFineMaxValue; }
304  };
305 
306 }
307 
308 #endif
TDC message.
Definition: TdcMessage.h:70
uint32_t getHeaderFmt() const
Return data format: 0 - normal, 1 - double edges for each hit.
Definition: TdcMessage.h:172
TdcMessage()
constructor
Definition: TdcMessage.h:80
bool isCalibrMsg() const
is calibration message
Definition: TdcMessage.h:115
bool isTMDR() const
is v4 TMDR message
Definition: TdcMessage.h:193
uint32_t fData
message raw data
Definition: TdcMessage.h:72
uint32_t getHitTmCoarse() const
Returns hit coarse time counter, 11 bit.
Definition: TdcMessage.h:130
uint32_t getEPOC() const
Return Epoch for EPOC marker, 28 bit.
Definition: TdcMessage.h:214
uint32_t getHeaderHwType() const
Return hardware type coded in header message.
Definition: TdcMessage.h:166
uint32_t getHeaderErr() const
Return error bits of header message.
Definition: TdcMessage.h:163
uint32_t getHitChannel() const
Returns hit channel ID.
Definition: TdcMessage.h:127
uint32_t getTRLAMinor() const
TRLA minor.
Definition: TdcMessage.h:250
void setCalibrFine(unsigned n=0, uint32_t v=0)
set calibration for fine counter
Definition: TdcMessage.h:158
static unsigned GetFineMaxValue()
get pre-configured max fine counter
Definition: TdcMessage.h:303
TdcMessage & operator=(const TdcMessage &src)
assign operator for the message
Definition: TdcMessage.h:92
uint32_t getHitTmStamp() const
Returns time stamp, which is simple combination coarse and fine counter.
Definition: TdcMessage.h:138
static unsigned GetFineMinValue()
get pre-configured min fine counter
Definition: TdcMessage.h:301
static double CoarseUnit()
default coarse unit for 200 MHz
Definition: TdcMessage.h:280
bool isTrailerMsg() const
is trailer message
Definition: TdcMessage.h:113
bool isEpochMsg() const
is epoch message
Definition: TdcMessage.h:107
uint32_t getTRLBMaxdc() const
TRLB maxdc.
Definition: TdcMessage.h:260
uint32_t getTMDTChannel() const
TMDT channel.
Definition: TdcMessage.h:222
bool isHitRisingEdge() const
Is rising edge.
Definition: TdcMessage.h:144
bool isTMDT() const
is v4 TMDT message
Definition: TdcMessage.h:195
static double SimpleFineCalibr(unsigned fine)
get simple linear calibration for fine counter
Definition: TdcMessage.h:286
uint32_t getTMDSPattern() const
TMDS pattern.
Definition: TdcMessage.h:242
void setHitTmCoarse(uint32_t coarse)
Set hit coarse time counter, 11 bit.
Definition: TdcMessage.h:132
TdcMessage(uint32_t d)
constructor
Definition: TdcMessage.h:83
uint32_t getTRLASub() const
TRLA sub.
Definition: TdcMessage.h:252
uint32_t getTRLBTptime() const
TRLB tptime.
Definition: TdcMessage.h:262
uint32_t getEpochValue() const
Return Epoch for epoch marker, 28 bit.
Definition: TdcMessage.h:120
uint32_t getHDRTrigger() const
HDR trigger.
Definition: TdcMessage.h:210
bool isHitMsg() const
is any of hit message
Definition: TdcMessage.h:104
uint32_t getDebugKind() const
Return error bits of header message.
Definition: TdcMessage.h:180
void print(double tm=-1.)
print message
Definition: TdcMessage.cxx:22
uint32_t getTRLCCpc() const
TRLC cpc.
Definition: TdcMessage.h:268
uint32_t getTRLCFreq() const
TRLC freq.
Definition: TdcMessage.h:274
uint32_t getTMDRCoarse() const
TMDR coarse.
Definition: TdcMessage.h:232
uint32_t getHitReserved() const
Returns hit reserved value, 2 bits.
Definition: TdcMessage.h:151
uint32_t getTMDSChannel() const
TMDS channel.
Definition: TdcMessage.h:238
bool IsVer4Header() const
is V4 header
Definition: TdcMessage.h:175
uint32_t getTMDTCoarse() const
TMDT coarse.
Definition: TdcMessage.h:224
static unsigned gFineMinValue
default fine min
Definition: TdcMessage.h:74
void assign(uint32_t d)
assign raw data to message
Definition: TdcMessage.h:86
uint32_t getTMDRFine() const
TMDR fine.
Definition: TdcMessage.h:234
uint32_t getHitTmFine() const
Returns hit fine time counter, 10 bit.
Definition: TdcMessage.h:135
void print4(uint32_t &ttype)
print v4 message
Definition: TdcMessage.cxx:62
uint32_t getTMDRMode() const
TMDR mode.
Definition: TdcMessage.h:230
static double CoarseUnit280()
default coarse unit for 280 MHz
Definition: TdcMessage.h:283
void setAsHit2(uint32_t finebin)
set as hit2
Definition: TdcMessage.cxx:9
bool isHit1Msg() const
is repaired 0x3fff message
Definition: TdcMessage.h:100
bool isEPOC() const
is v4 EPOC message
Definition: TdcMessage.h:191
uint32_t getTRLBEflags() const
TRLB eflags.
Definition: TdcMessage.h:258
static unsigned gFineMaxValue
default fine max
Definition: TdcMessage.h:75
bool isHeaderMsg() const
is header message
Definition: TdcMessage.h:111
bool isHitFallingEdge() const
Is falling edge.
Definition: TdcMessage.h:146
bool isHit0Msg() const
is original hit message
Definition: TdcMessage.h:98
static void SetFineLimits(unsigned min, unsigned max)
Method set static limits, which are used for simple interpolation of time for fine counter.
Definition: TdcMessage.h:294
bool isTMDS() const
is v4 TMDS message
Definition: TdcMessage.h:197
bool isTRL() const
is v4 TRL message
Definition: TdcMessage.h:199
bool getEPOCError() const
Is EPOC marker error.
Definition: TdcMessage.h:216
uint32_t getTRLCCcs() const
TRLC ccs.
Definition: TdcMessage.h:270
uint32_t getHeaderRes() const
Return reserved bits of header message.
Definition: TdcMessage.h:169
uint32_t getTRLANumCh() const
TRLA numch.
Definition: TdcMessage.h:254
uint32_t getCalibrFine(unsigned n=0) const
get calibration for fine counter
Definition: TdcMessage.h:156
bool isDebugMsg() const
is debug message
Definition: TdcMessage.h:109
uint32_t getHDRMajor() const
HDR major.
Definition: TdcMessage.h:204
uint32_t getTRLCCcdiv() const
TRLC ccdiv.
Definition: TdcMessage.h:272
uint32_t getHitEdge() const
Returns hit edge 1 - rising, 0 - falling.
Definition: TdcMessage.h:141
uint32_t getData() const
get message raw data
Definition: TdcMessage.h:89
uint32_t getTMDTMode() const
TMDT mode.
Definition: TdcMessage.h:220
bool isHDR() const
is v4 HDR message
Definition: TdcMessage.h:189
uint32_t getKind() const
Returns kind of the message If used for the hit message, four different values can be returned.
Definition: TdcMessage.h:96
uint32_t getTRLAPlatformId() const
TRLA platform id
Definition: TdcMessage.h:246
uint32_t getDebugValue() const
Return reserved bits of header message.
Definition: TdcMessage.h:183
uint32_t getTMDSCoarse() const
TMDS coarse.
Definition: TdcMessage.h:240
uint32_t getTMDTFine() const
TMDT fine.
Definition: TdcMessage.h:226
bool isHit2Msg() const
is hit message with replaced (calibrated) fine counter
Definition: TdcMessage.h:102
uint32_t getHDRMinor() const
HDR minor.
Definition: TdcMessage.h:206
uint32_t getTRLAMajor() const
TRLA major.
Definition: TdcMessage.h:248
uint32_t getHDRTType() const
HDR type.
Definition: TdcMessage.h:208
uint32_t getTRLBFreq() const
TRLB freq.
Definition: TdcMessage.h:264
uint32_t getEpochRes() const
Get reserved bit for epoch, 1 bit.
Definition: TdcMessage.h:122