CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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) {}
27  BTLSample(const BTLSample& o) : value_(o.value_), flag_(o.flag_), row_(o.row_), col_(o.col_) {}
28 
32  void setThreshold(bool thr) { setFlagWord(thr, kThreshMask, kThreshShift); }
33  void setMode(bool mode) { setFlagWord(mode, kModeMask, kModeShift); }
34  void setToA(uint16_t toa) { setDataWord(toa, kToAMask, kToAShift); }
35  void setToA2(uint16_t toa2) { setDataWord(toa2, kToA2Mask, kToA2Shift); }
36  void setData(uint16_t data) { setDataWord(data, kDataMask, kDataShift); }
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
uint8_t row_
Definition: BTLSample.h:84
uint16_t raw_flag() const
Definition: BTLSample.h:55
bool threshold() const
Definition: BTLSample.h:56
uint32_t data() const
Definition: BTLSample.h:60
uint32_t toa2() const
Definition: BTLSample.h:59
uint16_t flag_
Definition: BTLSample.h:83
bool mode() const
Definition: BTLSample.h:57
BTLSampleFlagMasks
Definition: BTLSample.h:18
uint32_t toa() const
Definition: BTLSample.h:58
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
uint64_t word
BTLSampleDataMasks
Definition: BTLSample.h:15
uint32_t raw_data() const
getters
Definition: BTLSample.h:54
BTLSampleDataShifts
Definition: BTLSample.h:16
void setToA(uint16_t toa)
Definition: BTLSample.h:34
void setMode(bool mode)
Definition: BTLSample.h:33
uint8_t row() const
Definition: BTLSample.h:61
void setData(uint16_t data)
Definition: BTLSample.h:36
uint8_t column() const
Definition: BTLSample.h:62
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
void set(bool thr, bool mode, uint16_t toa2, uint16_t toa, uint16_t data, uint8_t row, uint8_t col)
Definition: BTLSample.h:37
tuple cout
Definition: gather_cfg.py:144
void setThreshold(bool thr)
setters
Definition: BTLSample.h:32
int col
Definition: cuy.py:1009
void print(std::ostream &out=std::cout)
Definition: BTLSample.h:45
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