CMS 3D CMS Logo

HGCROCChannelDataFrame.h
Go to the documentation of this file.
1 #ifndef DataFormats_HGCalDigis_HGCROCChannelDataFrame_h
2 #define DataFormats_HGCalDigis_HGCROCChannelDataFrame_h
3 
4 #include <iostream>
5 #include <ostream>
6 #include <cstdint>
7 
17 template <class D>
19 public:
20  //although not used directly below, it is used to sort the collection
21  typedef D key_type;
22 
24 
31  };
32 
37  HGCROCChannelDataFrame(const D& id) : id_(id), value_(0) {}
39  HGCROCChannelDataFrame(const D& id, uint32_t value) : id_(id), value_(value) {}
42 
46  const D& id() const { return id_; }
47 
53  void fill(bool charMode, bool tc, bool tp, uint16_t adcm1, uint16_t adc, uint16_t tot, uint16_t toa) {
54  uint16_t word3(charMode ? adc : adcm1);
55  uint16_t word2((charMode || tc) ? compressToT(tot) : adc);
56  fillRaw(tc, tp, word3, word2, toa);
57  }
58 
67  void fillRaw(bool flag2, bool flag1, uint16_t word3, uint16_t word2, uint16_t word1) {
70  fillPacket3(word3);
71  fillPacket2(word2);
72  fillPacket1(word1);
73  }
74 
79  uint16_t compressToT(uint16_t totraw) {
80  if (totraw > 0x1ff)
81  return (0x200 | (totraw >> 3));
82  return (totraw & 0x1ff);
83  }
84 
89  uint16_t decompressToT(uint16_t totraw) const {
90  uint16_t totout(totraw & 0x1ff);
91  if (totraw & 0x200) {
92  totout = ((totraw & 0x1ff) << 3);
93  totout += (1 << 2);
94  }
95  return totout;
96  }
97 
101  uint32_t operator()() const { return value_; }
102  uint32_t raw() const { return value_; }
103  bool tc() const { return flag2(); }
104  bool tp() const { return flag1(); }
105  uint16_t tctp() const { return (tc() << 1) | tp(); }
106  uint16_t adc(bool charMode = false) const { return charMode ? packet3() : (tc() ? 0 : packet2()); }
107  uint16_t adcm1(bool charMode = false) const { return charMode ? 0 : packet3(); }
108  uint16_t tot(bool charMode = false) const {
109  uint16_t tot12b(decompressToT(packet2()));
110  return charMode || tc() ? tot12b : 0;
111  }
112  uint16_t rawtot(bool charMode = false) const { return charMode || tc() ? packet2() : 0; }
113  uint16_t toa() const { return packet1(); }
114  bool flag2() const { return readPacket(kFlagMask, kFlag2Shift); }
115  bool flag1() const { return readPacket(kFlagMask, kFlag1Shift); }
116  uint16_t packet3() const { return readPacket(kPacketMask, kPacket3Shift); }
117  uint16_t packet2() const { return readPacket(kPacketMask, kPacket2Shift); }
118  uint16_t packet1() const { return readPacket(kPacketMask, kPacket1Shift); }
119 
120  void print(std::ostream& out = std::cout) const {
121  out << "Raw=0x" << std::hex << raw() << std::dec << std::endl
122  << "\tf2: " << flag2() << " f1: " << flag1() << " p3: " << packet3() << " p2: " << packet2()
123  << " p1: " << packet1() << std::endl
124  << "\ttc: " << tc() << " tp: " << tp() << " adcm1: " << adcm1() << " (" << adcm1(false) << ") "
125  << " adc: " << adc() << " (" << adc(false) << ") "
126  << " tot: " << tot() << " (" << tot(false) << ") "
127  << " toa: " << toa() << std::endl;
128  }
129 
130 private:
135  // mask and shift bits
136  const uint32_t masked_word = (word & mask) << shift;
137 
138  //clear to 0 bits which will be set by word
139  value_ &= ~(mask << shift);
140 
141  //now set bits
142  value_ |= (masked_word);
143  }
144 
149  return ((value_ >> shift) & mask);
150  }
151 
152  //det-id for this dataframe
154 
155  // a 32-bit word
156  uint32_t value_;
157 };
158 
159 #endif
void print(std::ostream &out=std::cout) const
HGCROCChannelDataFrame(const D &id, uint32_t value)
const D & id() const
det id
uint32_t readPacket(HGCROCChannelDataFrameMask mask, HGCROCChannelDataFrameShift shift) const
wrapper to get packet at a given position
void fill(bool charMode, bool tc, bool tp, uint16_t adcm1, uint16_t adc, uint16_t tot, uint16_t toa)
fills the 32b word characterization mode : tc|tp|adc|tot|toa normal mode: tc|tp|adcm1|*|toa with *=to...
uint16_t rawtot(bool charMode=false) const
uint64_t word
HGCROCChannelDataFrame(uint32_t value)
Definition: value.py:1
void fillFlag2(bool flag)
setters
uint16_t adcm1(bool charMode=false) const
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:141
uint16_t adc(bool charMode=false) const
void fillPacket(uint16_t word, HGCROCChannelDataFrameMask mask, HGCROCChannelDataFrameShift shift)
wrapper to reset words at a given position
uint32_t operator()() const
getters
static unsigned int const shift
wrapper for a 32b data word from a single channel and its detid The format is always the same: |1b|1b...
uint16_t compressToT(uint16_t totraw)
the 12-bit TOT is compressed to a 10bit word truncating the first two bits when the value is above 0x...
uint16_t decompressToT(uint16_t totraw) const
the 10-bit TOT word is decompressed back to 12 bit word In case truncation occurred the word is shift...
HGCROCChannelDataFrame & operator=(const HGCROCChannelDataFrame &)=default
HGCROCChannelDataFrame(const HGCROCChannelDataFrame &o)
void fillRaw(bool flag2, bool flag1, uint16_t word3, uint16_t word2, uint16_t word1)
uint16_t tot(bool charMode=false) const