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::HGCSample
HGCSample(const HGCSample &o)
Definition: HGCSample.h:37
HGCSample::HGCSample
HGCSample()
CTOR.
Definition: HGCSample.h:35
HGCSample::kModeShift
Definition: HGCSample.h:25
HGCSample::setThreshold
void setThreshold(bool thr)
setters
Definition: HGCSample.h:42
HGCSample::kGainMask
Definition: HGCSample.h:19
gather_cfg.cout
cout
Definition: gather_cfg.py:144
HGCSample::HGCSampleShifts
HGCSampleShifts
Definition: HGCSample.h:23
HGCSample::set
void set(bool thr, bool mode, uint16_t gain, uint16_t toa, uint16_t data)
Definition: HGCSample.h:49
HGCSample::getToAValid
bool getToAValid() const
Definition: HGCSample.h:71
HGCSample::raw
uint32_t raw() const
getters
Definition: HGCSample.h:65
HGCSample::setGain
void setGain(uint16_t gain)
Definition: HGCSample.h:44
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:36
HGCSample::kDataMask
Definition: HGCSample.h:21
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
HGCSample::HGCSample
HGCSample(uint32_t value)
Definition: HGCSample.h:36
HGCSample::setToAValid
void setToAValid(bool toaFired)
Definition: HGCSample.h:47
HGCSample::print
void print(std::ostream &out=std::cout)
Definition: HGCSample.h:57
HGCSample::gain
uint16_t gain() const
Definition: HGCSample.h:68
HGCSample::setToA
void setToA(uint16_t toa)
Definition: HGCSample.h:45
HGCSample
wrapper for a data word
Definition: HGCSample.h:13
HGCSample::setData
void setData(uint16_t data)
Definition: HGCSample.h:46
HGCSample::kToAValidMask
Definition: HGCSample.h:18
HGCSample::kToGainShift
Definition: HGCSample.h:27
HGCSample::kToAShift
Definition: HGCSample.h:28
HGCSample::kThreshMask
Definition: HGCSample.h:16
HGCSample::kThreshShift
Definition: HGCSample.h:24
HGCSample::convertV9ToV10
static uint32_t convertV9ToV10(uint32_t valueOldForm, bool toaFiredOldForm)
Data Model Evolution.
Definition: HGCSample.h:77
value
Definition: value.py:1
HGCSample::toa
uint16_t toa() const
Definition: HGCSample.h:69
HGCSample::kToAMask
Definition: HGCSample.h:20
HGCSample::mode
bool mode() const
Definition: HGCSample.h:67
HGCSample::kDataShift
Definition: HGCSample.h:29
HGCSample::HGCSampleMasks
HGCSampleMasks
Definition: HGCSample.h:15
edm::shift
static unsigned const int shift
Definition: LuminosityBlockID.cc:7
HGCSample::value_
uint32_t value_
Definition: HGCSample.h:123
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
HGCSample::threshold
bool threshold() const
Definition: HGCSample.h:66
HGCSample::data
uint16_t data() const
Definition: HGCSample.h:70
HGCSample::operator()
uint32_t operator()()
Definition: HGCSample.h:72
HGCSample::getWord
uint32_t getWord(HGCSampleMasks mask, HGCSampleShifts shift) const
Definition: HGCSample.h:119
HGCSample::setMode
void setMode(bool mode)
Definition: HGCSample.h:43
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
HGCSample::kToAValidShift
Definition: HGCSample.h:26
HGCSample::setWord
void setWord(uint16_t word, HGCSampleMasks mask, HGCSampleShifts shift)
wrapper to reset words at a given position
Definition: HGCSample.h:108
HGCSample::kModeMask
Definition: HGCSample.h:17