stream  0.10.0
stream analysis framework
TdcIterator.h
1 #ifndef HADAQ_TDCITERATOR_H
2 #define HADAQ_TDCITERATOR_H
3 
4 #include "hadaq/definess.h"
5 
6 #include "hadaq/TdcMessage.h"
7 
8 namespace hadaq {
9 
16  class TdcIterator {
17  protected:
18 
19  enum { DummyEpoch = 0xffffffff };
20 
21  uint32_t* fBuf;
22  uint32_t* fLastBuf;
23  unsigned fBuflen;
24  bool fSwapped;
25 
27  uint32_t fCurEpoch;
28 
30 
31  public:
32 
34  TdcIterator(unsigned epochbitlen = 28) :
35  fBuf(0),
36  fLastBuf(0),
37  fBuflen(0),
38  fSwapped(false),
39  fMsg(),
40  fCurEpoch(DummyEpoch),
41  fConv()
42  {
43  // we have 11 bits for coarse stamp and 28 bits for epoch
44  // each bin is 5 ns
46  }
47 
49  void assign(uint32_t* buf, unsigned len, bool swapped = true)
50  {
51  fBuf = buf;
52  fLastBuf = 0;
53  fBuflen = len;
54  fSwapped = swapped;
55  fMsg.assign(0);
56 
57  if (fBuflen == 0) fBuf = 0;
58  fCurEpoch = DummyEpoch;
59  }
60 
62  void assign(hadaqs::RawSubevent* subev, unsigned indx, unsigned datalen)
63  {
64  if (subev!=0)
65  assign(subev->GetDataPtr(indx), datalen, subev->IsSwapped());
66  }
67 
69  void setRefEpoch(uint32_t epoch)
70  {
71  fConv.MoveRef(((uint64_t) epoch) << 11);
72  }
73 
75  bool next()
76  {
77  if (!fBuf) return false;
78 
79  if (fSwapped)
80  fMsg.assign((((uint8_t *) fBuf)[0] << 24) | (((uint8_t *) fBuf)[1] << 16) | (((uint8_t *) fBuf)[2] << 8) | (((uint8_t *) fBuf)[3]));
81  else
82  fMsg.assign(*fBuf);
83 
85 
86  fLastBuf = fBuf++;
87  if (--fBuflen == 0) fBuf = nullptr;
88 
89  return true;
90  }
91 
93  bool next4()
94  {
95  if (!fBuf) return false;
96 
97  if (fSwapped)
98  fMsg.assign((((uint8_t *) fBuf)[0] << 24) | (((uint8_t *) fBuf)[1] << 16) | (((uint8_t *) fBuf)[2] << 8) | (((uint8_t *) fBuf)[3]));
99  else
100  fMsg.assign(*fBuf);
101 
102  if (fMsg.isEPOC()) fCurEpoch = fMsg.getEPOC();
103 
104  fLastBuf = fBuf++;
105  if (--fBuflen == 0) fBuf = nullptr;
106 
107  return true;
108  }
109 
112  {
113  if (fBuf==0) return false;
114  if (fSwapped)
115  msg.assign((((uint8_t *) fBuf)[0] << 24) | (((uint8_t *) fBuf)[1] << 16) | (((uint8_t *) fBuf)[2] << 8) | (((uint8_t *) fBuf)[3]));
116  else
117  msg.assign(*fBuf);
118  return true;
119  }
120 
123  uint64_t getMsgStamp() const
124  { return (isCurEpoch() ? ((uint64_t) fCurEpoch) << 11 : 0) | (fMsg.isHitMsg() ? fMsg.getHitTmCoarse() : 0); }
125 
127  inline double getMsgTimeCoarse() const
128  { return fConv.ToSeconds(getMsgStamp()); }
129 
131  inline double getMsgTimeFine() const
132  {
135  return 0;
136  }
137 
139  hadaq::TdcMessage& msg() { return fMsg; }
140 
142  bool isCurEpoch() const { return fCurEpoch != DummyEpoch; }
143 
145  void clearCurEpoch() { fCurEpoch = DummyEpoch; }
146 
148  void setCurEpoch(uint32_t val) { fCurEpoch = val; }
149 
151  uint32_t getCurEpoch() const { return fCurEpoch; }
152 
154  void printmsg()
155  {
156  double tm = -1.;
157  if (msg().isHitMsg() || msg().isEpochMsg())
158  tm = getMsgTimeCoarse() - getMsgTimeFine();
159  msg().print(tm);
160  }
161 
163  void printall4()
164  {
165  uint32_t ttype = 0;
166  while (next4())
167  msg().print4(ttype);
168  }
169  };
170 }
171 
172 #endif
LocalStampConverter class should perform conversion of time stamps to time in seconds.
Definition: TimeStamp.h:35
void SetTimeSystem(unsigned wrapbits, double coef)
Set major timing parameters - wrap value and coefficient.
Definition: TimeStamp.h:70
void MoveRef(LocalStamp_t newref)
Move reference to the new position.
Definition: TimeStamp.h:113
double ToSeconds(LocalStamp_t stamp) const
Method convert time stamp to seconds, taking into account probable wrap relative to fRef value.
Definition: TimeStamp.h:98
TDC iterator.
Definition: TdcIterator.h:16
void assign(uint32_t *buf, unsigned len, bool swapped=true)
assign buffer
Definition: TdcIterator.h:49
hadaq::TdcMessage fMsg
! current message
Definition: TdcIterator.h:26
unsigned fBuflen
! length of raw data
Definition: TdcIterator.h:23
void setCurEpoch(uint32_t val)
Set value of current epoch.
Definition: TdcIterator.h:148
bool next4()
next TDC v4 message
Definition: TdcIterator.h:93
bool isCurEpoch() const
Returns true, if current epoch was assigned.
Definition: TdcIterator.h:142
uint64_t getMsgStamp() const
Returns 39-bit value, which combines epoch and coarse counter.
Definition: TdcIterator.h:123
TdcIterator(unsigned epochbitlen=28)
constructor
Definition: TdcIterator.h:34
void printmsg()
print current message
Definition: TdcIterator.h:154
base::LocalStampConverter fConv
! use to covert time stamps in seconds
Definition: TdcIterator.h:29
uint32_t fCurEpoch
! current epoch
Definition: TdcIterator.h:27
double getMsgTimeCoarse() const
get coarse time for the current message
Definition: TdcIterator.h:127
void setRefEpoch(uint32_t epoch)
One should call method to set current reference epoch.
Definition: TdcIterator.h:69
double getMsgTimeFine() const
return fine time value for current message
Definition: TdcIterator.h:131
void printall4()
print all v4 messages
Definition: TdcIterator.h:163
uint32_t * fBuf
! pointer on raw data
Definition: TdcIterator.h:21
void clearCurEpoch()
Clear current epoch value.
Definition: TdcIterator.h:145
bool fSwapped
! true if raw data are swapped
Definition: TdcIterator.h:24
void assign(hadaqs::RawSubevent *subev, unsigned indx, unsigned datalen)
assign data from sub event
Definition: TdcIterator.h:62
bool lookForwardMsg(TdcMessage &msg)
try to check forward message - without shifting iterator
Definition: TdcIterator.h:111
uint32_t getCurEpoch() const
Return value of current epoch.
Definition: TdcIterator.h:151
hadaq::TdcMessage & msg()
get current message
Definition: TdcIterator.h:139
uint32_t * fLastBuf
! pointer on last extracted message
Definition: TdcIterator.h:22
bool next()
next TDC message
Definition: TdcIterator.h:75
TDC message.
Definition: TdcMessage.h:70
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
static double CoarseUnit()
default coarse unit for 200 MHz
Definition: TdcMessage.h:280
bool isEpochMsg() const
is epoch message
Definition: TdcMessage.h:107
static double SimpleFineCalibr(unsigned fine)
get simple linear calibration for fine counter
Definition: TdcMessage.h:286
uint32_t getEpochValue() const
Return Epoch for epoch marker, 28 bit.
Definition: TdcMessage.h:120
bool isHitMsg() const
is any of hit message
Definition: TdcMessage.h:104
void print(double tm=-1.)
print message
Definition: TdcMessage.cxx:22
void assign(uint32_t d)
assign raw data to message
Definition: TdcMessage.h:86
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
bool isHit1Msg() const
is repaired 0x3fff message
Definition: TdcMessage.h:100
bool isEPOC() const
is v4 EPOC message
Definition: TdcMessage.h:191
bool isHit0Msg() const
is original hit message
Definition: TdcMessage.h:98
bool isHit2Msg() const
is hit message with replaced (calibrated) fine counter
Definition: TdcMessage.h:102
bool IsSwapped() const
msb of decode word is always non zero...?
Definition: definess.h:138
Raw hades subevent.
Definition: definess.h:408
uint32_t * GetDataPtr(unsigned indx) const
Return pointer on data by index - user should care itself about swapping.
Definition: definess.h:437