CMS 3D CMS Logo

BTLSample.h
Go to the documentation of this file.
1 #ifndef DIGIFTL_BTLSAMPLE_H
2 #define DIGIFTL_BTLSAMPLE_H
3 
4 #include <iostream>
5 #include <ostream>
6 #include <cstdint>
7 
13 class BTLSample {
14 public:
15  enum BTLSampleDataMasks { kToA2Mask = 0x3ff, kToAMask = 0x3ff, kDataMask = 0x3ff };
17 
18  enum BTLSampleFlagMasks { kThreshMask = 0x1, kModeMask = 0x1 };
20 
24  BTLSample() : value_(0), flag_(0), row_(0), col_(0) {}
25  BTLSample(uint32_t value, uint16_t flag, uint8_t row, uint8_t col)
26  : value_(value), flag_(flag), row_(row), col_(col) {}
28 
32  void setThreshold(bool thr) { setFlagWord(thr, kThreshMask, kThreshShift); }
34  void setToA(uint16_t toa) { setDataWord(toa, kToAMask, kToAShift); }
37  void set(bool thr, bool mode, uint16_t toa2, uint16_t toa, uint16_t data, uint8_t row, uint8_t col) {
38  flag_ = (((uint16_t)thr & kThreshMask) << kThreshShift | ((uint16_t)mode & kModeMask) << kModeShift);
39 
40  value_ = (((uint32_t)toa2 & kToA2Mask) << kToA2Shift | ((uint32_t)toa & kToAMask) << kToAShift |
41  ((uint32_t)data & kDataMask) << kDataShift);
42  row_ = row;
43  col_ = col;
44  }
45  void print(std::ostream& out = std::cout) {
46  out << "THR: " << threshold() << " Mode: " << mode() << " ToA2: " << toa2() << " ToA: " << toa()
47  << " Data: " << data() << " Row: " << (uint32_t)row() << " Column: " << (uint32_t)column() << " Raw Flag=0x"
48  << std::hex << raw_flag() << std::dec << " Raw Data=0x" << std::hex << raw_data() << std::dec << std::endl;
49  }
50 
54  uint32_t raw_data() const { return value_; }
55  uint16_t raw_flag() const { return flag_; }
56  bool threshold() const { return ((flag_ >> kThreshShift) & kThreshMask); }
57  bool mode() const { return ((flag_ >> kModeShift) & kModeMask); }
58  uint32_t toa() const { return ((value_ >> kToAShift) & kToAMask); }
59  uint32_t toa2() const { return ((value_ >> kToA2Shift) & kToA2Mask); }
60  uint32_t data() const { return ((value_ >> kDataShift) & kDataMask); }
61  uint8_t row() const { return row_; }
62  uint8_t column() const { return col_; }
63 
64 private:
68  void setDataWord(uint32_t word, uint32_t mask, uint32_t pos) {
69  //clear required bits
70  value_ &= ~(mask << pos);
71  //now set the new value
72  value_ |= ((word & mask) << pos);
73  }
74  void setFlagWord(uint16_t word, uint16_t mask, uint16_t pos) {
75  //clear required bits
76  flag_ &= ~(mask << pos);
77  //now set the new value
78  flag_ |= ((word & mask) << pos);
79  }
80 
81  // bit-words for data and flags
82  uint32_t value_;
83  uint16_t flag_;
84  uint8_t row_, col_;
85 };
86 
87 #endif
uint32_t data() const
Definition: BTLSample.h:60
uint8_t row_
Definition: BTLSample.h:84
uint8_t column() const
Definition: BTLSample.h:62
uint16_t flag_
Definition: BTLSample.h:83
BTLSampleFlagMasks
Definition: BTLSample.h:18
uint32_t raw_data() const
getters
Definition: BTLSample.h:54
wrapper for a data word
Definition: BTLSample.h:13
uint8_t col_
Definition: BTLSample.h:84
uint32_t value_
Definition: BTLSample.h:82
void setToA2(uint16_t toa2)
Definition: BTLSample.h:35
BTLSample(const BTLSample &o)
Definition: BTLSample.h:27
uint8_t row() const
Definition: BTLSample.h:61
bool mode() const
Definition: BTLSample.h:57
uint64_t word
BTLSampleDataMasks
Definition: BTLSample.h:15
BTLSampleDataShifts
Definition: BTLSample.h:16
void setToA(uint16_t toa)
Definition: BTLSample.h:34
void setMode(bool mode)
Definition: BTLSample.h:33
Definition: value.py:1
uint32_t toa() const
Definition: BTLSample.h:58
void setData(uint16_t data)
Definition: BTLSample.h:36
uint32_t toa2() const
Definition: BTLSample.h:59
BTLSampleFlagShifts
Definition: BTLSample.h:19
void setDataWord(uint32_t word, uint32_t mask, uint32_t pos)
wrapper to reset words at a given position
Definition: BTLSample.h:68
BTLSample()
CTOR.
Definition: BTLSample.h:24
col
Definition: cuy.py:1009
bool threshold() const
Definition: BTLSample.h:56
void setThreshold(bool thr)
setters
Definition: BTLSample.h:32
void print(std::ostream &out=std::cout)
Definition: BTLSample.h:45
uint16_t raw_flag() const
Definition: BTLSample.h:55
void setFlagWord(uint16_t word, uint16_t mask, uint16_t pos)
Definition: BTLSample.h:74
BTLSample(uint32_t value, uint16_t flag, uint8_t row, uint8_t col)
Definition: BTLSample.h:25