File indexing completed on 2024-04-06 12:04:21
0001 #ifndef DIGIHGCAL_HGCSAMPLE_H
0002 #define DIGIHGCAL_HGCSAMPLE_H
0003
0004 #include <iostream>
0005 #include <ostream>
0006 #include <cstdint>
0007
0008
0009
0010
0011
0012
0013 class HGCSample {
0014 public:
0015 enum HGCSampleMasks {
0016 kThreshMask = 0x1,
0017 kModeMask = 0x1,
0018 kToAValidMask = 0x1,
0019 kGainMask = 0xf,
0020 kToAMask = 0x3ff,
0021 kDataMask = 0xfff
0022 };
0023 enum HGCSampleShifts {
0024 kThreshShift = 31,
0025 kModeShift = 30,
0026 kToAValidShift = 29,
0027 kToGainShift = 22,
0028 kToAShift = 12,
0029 kDataShift = 0
0030 };
0031
0032
0033
0034
0035 HGCSample() : value_(0) {}
0036 HGCSample(uint32_t value) : value_(value) {}
0037 HGCSample(const HGCSample& o) : value_(o.value_) {}
0038 HGCSample& operator=(const HGCSample&) = default;
0039
0040
0041
0042
0043 void setThreshold(bool thr) { setWord(thr, kThreshMask, kThreshShift); }
0044 void setMode(bool mode) { setWord(mode, kModeMask, kModeShift); }
0045 void setGain(uint16_t gain) { setWord(gain, kGainMask, kToGainShift); }
0046 void setToA(uint16_t toa) { setWord(toa, kToAMask, kToAShift); }
0047 void setData(uint16_t data) { setWord(data, kDataMask, kDataShift); }
0048 void setToAValid(bool toaFired) { setWord(toaFired, kToAValidMask, kToAValidShift); }
0049
0050 void set(bool thr, bool mode, uint16_t gain, uint16_t toa, uint16_t data) {
0051 setThreshold(thr);
0052 setMode(mode);
0053 setGain(gain);
0054 setToA(toa);
0055 setData(data);
0056 }
0057
0058 void print(std::ostream& out = std::cout) {
0059 out << "THR: " << threshold() << " Mode: " << mode() << " ToA: " << toa() << " Data: " << data() << " Raw=0x"
0060 << std::hex << raw() << std::dec << std::endl;
0061 }
0062
0063
0064
0065
0066 uint32_t raw() const { return value_; }
0067 bool threshold() const { return getWord(kThreshMask, kThreshShift); }
0068 bool mode() const { return getWord(kModeMask, kModeShift); }
0069 uint16_t gain() const { return getWord(kGainMask, kToGainShift); }
0070 uint16_t toa() const { return getWord(kToAMask, kToAShift); }
0071 uint16_t data() const { return getWord(kDataMask, kDataShift); }
0072 bool getToAValid() const { return getWord(kToAValidMask, kToAValidShift); }
0073 uint32_t operator()() { return value_; }
0074
0075
0076
0077
0078 static uint32_t convertV9ToV10(uint32_t valueOldForm, bool toaFiredOldForm) {
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091 uint32_t valueNewForm(valueOldForm);
0092
0093
0094 valueNewForm &= ~(0x3FFFF << kToAShift);
0095
0096
0097 valueNewForm |= ((valueOldForm >> 13) & kToAMask) << kToAShift;
0098
0099
0100 valueNewForm |= (toaFiredOldForm & kToAValidMask) << kToAValidShift;
0101
0102 return valueNewForm;
0103 }
0104
0105 private:
0106
0107
0108
0109 void setWord(uint16_t word, HGCSampleMasks mask, HGCSampleShifts shift) {
0110
0111 const uint32_t masked_word = (word & mask) << shift;
0112
0113
0114 value_ &= ~(mask << shift);
0115
0116
0117 value_ |= (masked_word);
0118 }
0119
0120 uint32_t getWord(HGCSampleMasks mask, HGCSampleShifts shift) const { return ((value_ >> shift) & mask); }
0121
0122
0123
0124 uint32_t value_;
0125 };
0126
0127 #endif