CMS 3D CMS Logo

HGCSample.h
Go to the documentation of this file.
1 #ifndef DIGIHGCAL_HGCSAMPLE_H
2 #define DIGIHGCAL_HGCSAMPLE_H
3 
4 #include <iostream>
5 #include <ostream>
6 #include <cstdint>
7 
13 class HGCSample {
14 public:
16  kThreshMask = 0x1,
17  kModeMask = 0x1,
19  kGainMask = 0xf,
20  kToAMask = 0x3ff,
21  kDataMask = 0xfff
22  };
25  kModeShift = 30,
28  kToAShift = 12,
30  };
31 
35  HGCSample() : value_(0) {}
36  HGCSample(uint32_t value) : value_(value) {}
38  HGCSample& operator=(const HGCSample&) = default;
39 
43  void setThreshold(bool thr) { setWord(thr, kThreshMask, kThreshShift); }
45  void setGain(uint16_t gain) { setWord(gain, kGainMask, kToGainShift); }
46  void setToA(uint16_t toa) { setWord(toa, kToAMask, kToAShift); }
47  void setData(uint16_t data) { setWord(data, kDataMask, kDataShift); }
48  void setToAValid(bool toaFired) { setWord(toaFired, kToAValidMask, kToAValidShift); }
49 
50  void set(bool thr, bool mode, uint16_t gain, uint16_t toa, uint16_t data) {
51  setThreshold(thr);
52  setMode(mode);
53  setGain(gain);
54  setToA(toa);
55  setData(data);
56  }
57 
58  void print(std::ostream& out = std::cout) {
59  out << "THR: " << threshold() << " Mode: " << mode() << " ToA: " << toa() << " Data: " << data() << " Raw=0x"
60  << std::hex << raw() << std::dec << std::endl;
61  }
62 
66  uint32_t raw() const { return value_; }
67  bool threshold() const { return getWord(kThreshMask, kThreshShift); }
68  bool mode() const { return getWord(kModeMask, kModeShift); }
69  uint16_t gain() const { return getWord(kGainMask, kToGainShift); }
70  uint16_t toa() const { return getWord(kToAMask, kToAShift); }
71  uint16_t data() const { return getWord(kDataMask, kDataShift); }
72  bool getToAValid() const { return getWord(kToAValidMask, kToAValidShift); }
73  uint32_t operator()() { return value_; }
74 
78  static uint32_t convertV9ToV10(uint32_t valueOldForm, bool toaFiredOldForm) {
79  // combine value&toaFired from the dataformat V9-or-earlier
80  // from persisted objects
81  // to produce a value_ compatible w/ the V10 format
82  // i.e.
83  // 1) shift the 10 toa bits by 1 bit
84  // 2) insert the toaFired into _value
85  // NOTE: nothing can be done for the gain bits:
86  // info about gain was not preswent in V9-or-earlier, and will be left to 0 in V10
87  // root doc: https://root.cern.ch/root/html/io/DataModelEvolution.html
88  // see PR 28349 for more info
89 
90  // V9 Format: tm--------tttttttttt-dddddddddddd
91  uint32_t valueNewForm(valueOldForm);
92 
93  // set to 0 the 17 bits bits (between 13 and 29 - both included)
94  valueNewForm &= ~(0x3FFFF << kToAShift);
95 
96  // copy toa to start from bit 13
97  valueNewForm |= ((valueOldForm >> 13) & kToAMask) << kToAShift;
98 
99  // set 1 bit toaFiredOldForm in position 30
100  valueNewForm |= (toaFiredOldForm & kToAValidMask) << kToAValidShift;
101 
102  return valueNewForm;
103  }
104 
105 private:
110  // mask and shift bits
111  const uint32_t masked_word = (word & mask) << shift;
112 
113  //clear to 0 bits which will be set by word
114  value_ &= ~(mask << shift);
115 
116  //now set bits
117  value_ |= (masked_word);
118  }
119 
120  uint32_t getWord(HGCSampleMasks mask, HGCSampleShifts shift) const { return ((value_ >> shift) & mask); }
121 
122  // a 32-bit word
123  // V10 Format: tmt---ggggttttttttttdddddddddddd
124  uint32_t value_;
125 };
126 
127 #endif
HGCSample(const HGCSample &o)
Definition: HGCSample.h:37
void print(std::ostream &out=std::cout)
Definition: HGCSample.h:58
uint16_t gain() const
Definition: HGCSample.h:69
uint32_t value_
Definition: HGCSample.h:124
void setMode(bool mode)
Definition: HGCSample.h:44
bool mode() const
Definition: HGCSample.h:68
wrapper for a data word
Definition: HGCSample.h:13
constexpr uint32_t mask
Definition: gpuClustering.h:26
HGCSample()
CTOR.
Definition: HGCSample.h:35
uint16_t data() const
Definition: HGCSample.h:71
HGCSample(uint32_t value)
Definition: HGCSample.h:36
uint64_t word
void setThreshold(bool thr)
setters
Definition: HGCSample.h:43
HGCSampleShifts
Definition: HGCSample.h:23
HGCSampleMasks
Definition: HGCSample.h:15
void setToA(uint16_t toa)
Definition: HGCSample.h:46
void setGain(uint16_t gain)
Definition: HGCSample.h:45
Definition: value.py:1
void setToAValid(bool toaFired)
Definition: HGCSample.h:48
uint16_t toa() const
Definition: HGCSample.h:70
void setWord(uint16_t word, HGCSampleMasks mask, HGCSampleShifts shift)
wrapper to reset words at a given position
Definition: HGCSample.h:109
HGCSample & operator=(const HGCSample &)=default
bool threshold() const
Definition: HGCSample.h:67
static unsigned int const shift
static uint32_t convertV9ToV10(uint32_t valueOldForm, bool toaFiredOldForm)
Data Model Evolution.
Definition: HGCSample.h:78
bool getToAValid() const
Definition: HGCSample.h:72
uint32_t operator()()
Definition: HGCSample.h:73
void setData(uint16_t data)
Definition: HGCSample.h:47
uint32_t raw() const
getters
Definition: HGCSample.h:66
uint32_t getWord(HGCSampleMasks mask, HGCSampleShifts shift) const
Definition: HGCSample.h:120