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