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  BTLSample& operator=(const BTLSample&) = default;
29 
33  void setThreshold(bool thr) { setFlagWord(thr, kThreshMask, kThreshShift); }
35  void setToA(uint16_t toa) { setDataWord(toa, kToAMask, kToAShift); }
38  void set(bool thr, bool mode, uint16_t toa2, uint16_t toa, uint16_t data, uint8_t row, uint8_t col) {
39  flag_ = (((uint16_t)thr & kThreshMask) << kThreshShift | ((uint16_t)mode & kModeMask) << kModeShift);
40 
41  value_ = (((uint32_t)toa2 & kToA2Mask) << kToA2Shift | ((uint32_t)toa & kToAMask) << kToAShift |
42  ((uint32_t)data & kDataMask) << kDataShift);
43  row_ = row;
44  col_ = col;
45  }
46  void print(std::ostream& out = std::cout) {
47  out << "THR: " << threshold() << " Mode: " << mode() << " ToA2: " << toa2() << " ToA: " << toa()
48  << " Data: " << data() << " Row: " << (uint32_t)row() << " Column: " << (uint32_t)column() << " Raw Flag=0x"
49  << std::hex << raw_flag() << std::dec << " Raw Data=0x" << std::hex << raw_data() << std::dec << std::endl;
50  }
51 
55  uint32_t raw_data() const { return value_; }
56  uint16_t raw_flag() const { return flag_; }
57  bool threshold() const { return ((flag_ >> kThreshShift) & kThreshMask); }
58  bool mode() const { return ((flag_ >> kModeShift) & kModeMask); }
59  uint32_t toa() const { return ((value_ >> kToAShift) & kToAMask); }
60  uint32_t toa2() const { return ((value_ >> kToA2Shift) & kToA2Mask); }
61  uint32_t data() const { return ((value_ >> kDataShift) & kDataMask); }
62  uint8_t row() const { return row_; }
63  uint8_t column() const { return col_; }
64 
65 private:
69  void setDataWord(uint32_t word, uint32_t mask, uint32_t pos) {
70  //clear required bits
71  value_ &= ~(mask << pos);
72  //now set the new value
73  value_ |= ((word & mask) << pos);
74  }
75  void setFlagWord(uint16_t word, uint16_t mask, uint16_t pos) {
76  //clear required bits
77  flag_ &= ~(mask << pos);
78  //now set the new value
79  flag_ |= ((word & mask) << pos);
80  }
81 
82  // bit-words for data and flags
83  uint32_t value_;
84  uint16_t flag_;
85  uint8_t row_, col_;
86 };
87 
88 #endif
uint32_t data() const
Definition: BTLSample.h:61
uint8_t row_
Definition: BTLSample.h:85
uint8_t column() const
Definition: BTLSample.h:63
uint16_t flag_
Definition: BTLSample.h:84
BTLSampleFlagMasks
Definition: BTLSample.h:18
uint32_t raw_data() const
getters
Definition: BTLSample.h:55
wrapper for a data word
Definition: BTLSample.h:13
uint8_t col_
Definition: BTLSample.h:85
uint32_t value_
Definition: BTLSample.h:83
void setToA2(uint16_t toa2)
Definition: BTLSample.h:36
BTLSample(const BTLSample &o)
Definition: BTLSample.h:27
uint8_t row() const
Definition: BTLSample.h:62
bool mode() const
Definition: BTLSample.h:58
uint64_t word
BTLSampleDataMasks
Definition: BTLSample.h:15
BTLSampleDataShifts
Definition: BTLSample.h:16
void setToA(uint16_t toa)
Definition: BTLSample.h:35
void setMode(bool mode)
Definition: BTLSample.h:34
Definition: value.py:1
uint32_t toa() const
Definition: BTLSample.h:59
void setData(uint16_t data)
Definition: BTLSample.h:37
BTLSample & operator=(const BTLSample &)=default
uint32_t toa2() const
Definition: BTLSample.h:60
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:69
BTLSample()
CTOR.
Definition: BTLSample.h:24
col
Definition: cuy.py:1009
bool threshold() const
Definition: BTLSample.h:57
void setThreshold(bool thr)
setters
Definition: BTLSample.h:33
void print(std::ostream &out=std::cout)
Definition: BTLSample.h:46
uint16_t raw_flag() const
Definition: BTLSample.h:56
void setFlagWord(uint16_t word, uint16_t mask, uint16_t pos)
Definition: BTLSample.h:75
BTLSample(uint32_t value, uint16_t flag, uint8_t row, uint8_t col)
Definition: BTLSample.h:25