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 
15 public:
16 
17  enum BTLSampleDataMasks { kToA2Mask = 0x3ff, kToAMask = 0x3ff, kDataMask = 0x3ff};
19 
22 
26  BTLSample() : value_(0), flag_(0), row_(0), col_(0) { }
27  BTLSample(uint32_t value, uint16_t flag, uint8_t row, uint8_t col) : value_(value), flag_(flag), row_(row), col_(col) { }
28  BTLSample( const BTLSample& o ) : value_(o.value_), flag_(o.flag_), row_(o.row_), col_(o.col_) { }
29 
33  void setThreshold(bool thr) { setFlagWord(thr, kThreshMask, kThreshShift); }
34  void setMode(bool mode) { setFlagWord(mode, kModeMask, kModeShift); }
35  void setToA(uint16_t toa) { setDataWord(toa, kToAMask, kToAShift); }
36  void setToA2(uint16_t toa2) { setDataWord(toa2, kToA2Mask, kToA2Shift); }
37  void setData(uint16_t data) { setDataWord(data, kDataMask, kDataShift); }
38  void set(bool thr, bool mode, uint16_t toa2, uint16_t toa, uint16_t data, uint8_t row, uint8_t col)
39  {
40  flag_ = ( ( (uint16_t)thr & kThreshMask ) << kThreshShift |
41  ( (uint16_t)mode & kModeMask ) << kModeShift );
42 
43  value_ = ( ( (uint32_t)toa2 & kToA2Mask ) << kToA2Shift |
44  ( (uint32_t)toa & kToAMask ) << kToAShift |
45  ( (uint32_t)data & kDataMask ) << kDataShift );
46  row_ = row;
47  col_ = col;
48  }
49  void print(std::ostream &out=std::cout)
50  {
51  out << "THR: " << threshold()
52  << " Mode: " << mode()
53  << " ToA2: " << toa2()
54  << " ToA: " << toa()
55  << " Data: " << data()
56  << " Row: " << (uint32_t)row()
57  << " Column: " << (uint32_t)column()
58  << " Raw Flag=0x" << std::hex << raw_flag() << std::dec
59  << " Raw Data=0x" << std::hex << raw_data() << std::dec << std::endl;
60 
61  }
62 
66  uint32_t raw_data() const { return value_; }
67  uint16_t raw_flag() const { return flag_; }
68  bool threshold() const { return ( (flag_ >> kThreshShift) & kThreshMask ); }
69  bool mode() const { return ( (flag_ >> kModeShift) & kModeMask ); }
70  uint32_t toa() const { return ( (value_ >> kToAShift) & kToAMask ); }
71  uint32_t toa2() const { return ( (value_ >> kToA2Shift) & kToA2Mask ); }
72  uint32_t data() const { return ( (value_ >> kDataShift) & kDataMask ); }
73  uint8_t row() const { return row_; }
74  uint8_t column() const { return col_; }
75 
76 private:
77 
81  void setDataWord(uint32_t word, uint32_t mask, uint32_t pos)
82  {
83  //clear required bits
84  value_ &= ~(mask << pos);
85  //now set the new value
86  value_ |= ( (word & mask) << pos );
87  }
88  void setFlagWord(uint16_t word, uint16_t mask, uint16_t pos)
89  {
90  //clear required bits
91  flag_ &= ~(mask << pos);
92  //now set the new value
93  flag_ |= ( (word & mask) << pos );
94  }
95 
96  // bit-words for data and flags
97  uint32_t value_;
98  uint16_t flag_;
99  uint8_t row_,col_;
100 };
101 
102 
103 #endif
uint8_t row_
Definition: BTLSample.h:99
uint16_t raw_flag() const
Definition: BTLSample.h:67
bool threshold() const
Definition: BTLSample.h:68
uint32_t data() const
Definition: BTLSample.h:72
uint32_t toa2() const
Definition: BTLSample.h:71
uint16_t flag_
Definition: BTLSample.h:98
bool mode() const
Definition: BTLSample.h:69
BTLSampleFlagMasks
Definition: BTLSample.h:20
uint32_t toa() const
Definition: BTLSample.h:70
wrapper for a data word
Definition: BTLSample.h:13
uint8_t col_
Definition: BTLSample.h:99
uint32_t value_
Definition: BTLSample.h:97
void setToA2(uint16_t toa2)
Definition: BTLSample.h:36
BTLSample(const BTLSample &o)
Definition: BTLSample.h:28
BTLSampleDataMasks
Definition: BTLSample.h:17
uint32_t raw_data() const
getters
Definition: BTLSample.h:66
BTLSampleDataShifts
Definition: BTLSample.h:18
void setToA(uint16_t toa)
Definition: BTLSample.h:35
void setMode(bool mode)
Definition: BTLSample.h:34
Definition: value.py:1
uint8_t row() const
Definition: BTLSample.h:73
void setData(uint16_t data)
Definition: BTLSample.h:37
uint8_t column() const
Definition: BTLSample.h:74
BTLSampleFlagShifts
Definition: BTLSample.h:21
void setDataWord(uint32_t word, uint32_t mask, uint32_t pos)
wrapper to reset words at a given position
Definition: BTLSample.h:81
BTLSample()
CTOR.
Definition: BTLSample.h:26
col
Definition: cuy.py:1010
void setThreshold(bool thr)
setters
Definition: BTLSample.h:33
void print(std::ostream &out=std::cout)
Definition: BTLSample.h:49
void setFlagWord(uint16_t word, uint16_t mask, uint16_t pos)
Definition: BTLSample.h:88
BTLSample(uint32_t value, uint16_t flag, uint8_t row, uint8_t col)
Definition: BTLSample.h:27