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) { }
27  BTLSample(uint32_t value, uint16_t flag) : value_(value), flag_(flag) { }
28  BTLSample( const BTLSample& o ) : value_(o.value_), flag_(o.flag_) { }
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)
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  }
47  void print(std::ostream &out=std::cout)
48  {
49  out << "THR: " << threshold()
50  << " Mode: " << mode()
51  << " ToA2: " << toa2()
52  << " ToA: " << toa()
53  << " Data: " << data()
54  << " Raw Flag=0x" << std::hex << raw_flag() << std::dec
55  << " Raw Data=0x" << std::hex << raw_data() << std::dec << std::endl;
56  }
57 
61  uint32_t raw_data() const { return value_; }
62  uint16_t raw_flag() const { return flag_; }
63  bool threshold() const { return ( (flag_ >> kThreshShift) & kThreshMask ); }
64  bool mode() const { return ( (flag_ >> kModeShift) & kModeMask ); }
65  uint32_t toa() const { return ( (value_ >> kToAShift) & kToAMask ); }
66  uint32_t toa2() const { return ( (value_ >> kToA2Shift) & kToA2Mask ); }
67  uint32_t data() const { return ( (value_ >> kDataShift) & kDataMask ); }
68 
69 private:
70 
74  void setDataWord(uint32_t word, uint32_t mask, uint32_t pos)
75  {
76  //clear required bits
77  value_ &= ~(mask << pos);
78  //now set the new value
79  value_ |= ( (word & mask) << pos );
80  }
81  void setFlagWord(uint16_t word, uint16_t mask, uint16_t pos)
82  {
83  //clear required bits
84  flag_ &= ~(mask << pos);
85  //now set the new value
86  flag_ |= ( (word & mask) << pos );
87  }
88 
89  // bit-words for data and flags
90  uint32_t value_;
91  uint16_t flag_;
92 };
93 
94 
95 #endif
uint16_t raw_flag() const
Definition: BTLSample.h:62
bool threshold() const
Definition: BTLSample.h:63
uint32_t data() const
Definition: BTLSample.h:67
uint32_t toa2() const
Definition: BTLSample.h:66
uint16_t flag_
Definition: BTLSample.h:91
bool mode() const
Definition: BTLSample.h:64
BTLSampleFlagMasks
Definition: BTLSample.h:20
BTLSample(uint32_t value, uint16_t flag)
Definition: BTLSample.h:27
uint32_t toa() const
Definition: BTLSample.h:65
wrapper for a data word
Definition: BTLSample.h:13
uint32_t value_
Definition: BTLSample.h:90
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:61
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
void setData(uint16_t data)
Definition: BTLSample.h:37
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:74
BTLSample()
CTOR.
Definition: BTLSample.h:26
void setThreshold(bool thr)
setters
Definition: BTLSample.h:33
void print(std::ostream &out=std::cout)
Definition: BTLSample.h:47
void setFlagWord(uint16_t word, uint16_t mask, uint16_t pos)
Definition: BTLSample.h:81