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) {}
41 
45  const D& id() const { return id_; }
46 
52  void fill(bool charMode, bool tc, bool tp, uint16_t adcm1, uint16_t adc, uint16_t tot, uint16_t toa) {
53  uint16_t word3(charMode ? adc : adcm1);
54  uint16_t word2((charMode || tc) ? compressToT(tot) : adc);
55  fillRaw(tc, tp, word3, word2, toa);
56  }
57 
66  void fillRaw(bool flag2, bool flag1, uint16_t word3, uint16_t word2, uint16_t word1) {
69  fillPacket3(word3);
70  fillPacket2(word2);
71  fillPacket1(word1);
72  }
73 
78  uint16_t compressToT(uint16_t totraw) {
79  if (totraw > 0x1ff)
80  return (0x200 | (totraw >> 3));
81  return (totraw & 0x1ff);
82  }
83 
88  uint16_t decompressToT(uint16_t totraw) const {
89  uint16_t totout(totraw & 0x1ff);
90  if (totraw & 0x200) {
91  totout = ((totraw & 0x1ff) << 3);
92  totout += (1 << 2);
93  }
94  return totout;
95  }
96 
100  uint32_t operator()() const { return value_; }
101  uint32_t raw() const { return value_; }
102  bool tc() const { return flag2(); }
103  bool tp() const { return flag1(); }
104  uint16_t tctp() const { return (tc() << 1) | tp(); }
105  uint16_t adc(bool charMode = false) const { return charMode ? packet3() : (tc() ? 0 : packet2()); }
106  uint16_t adcm1(bool charMode = false) const { return charMode ? 0 : packet3(); }
107  uint16_t tot(bool charMode = false) const {
108  uint16_t tot12b(decompressToT(packet2()));
109  return charMode || tc() ? tot12b : 0;
110  }
111  uint16_t rawtot(bool charMode = false) const { return charMode || tc() ? packet2() : 0; }
112  uint16_t toa() const { return packet1(); }
113  bool flag2() const { return readPacket(kFlagMask, kFlag2Shift); }
114  bool flag1() const { return readPacket(kFlagMask, kFlag1Shift); }
115  uint16_t packet3() const { return readPacket(kPacketMask, kPacket3Shift); }
116  uint16_t packet2() const { return readPacket(kPacketMask, kPacket2Shift); }
117  uint16_t packet1() const { return readPacket(kPacketMask, kPacket1Shift); }
118 
119  void print(std::ostream& out = std::cout) const {
120  out << "Raw=0x" << std::hex << raw() << std::dec << std::endl
121  << "\tf2: " << flag2() << " f1: " << flag1() << " p3: " << packet3() << " p2: " << packet2()
122  << " p1: " << packet1() << std::endl
123  << "\ttc: " << tc() << " tp: " << tp() << " adcm1: " << adcm1() << " (" << adcm1(false) << ") "
124  << " adc: " << adc() << " (" << adc(false) << ") "
125  << " tot: " << tot() << " (" << tot(false) << ") "
126  << " toa: " << toa() << std::endl;
127  }
128 
129 private:
134  // mask and shift bits
135  const uint32_t masked_word = (word & mask) << shift;
136 
137  //clear to 0 bits which will be set by word
138  value_ &= ~(mask << shift);
139 
140  //now set bits
141  value_ |= (masked_word);
142  }
143 
148  return ((value_ >> shift) & mask);
149  }
150 
151  //det-id for this dataframe
153 
154  // a 32-bit word
155  uint32_t value_;
156 };
157 
158 #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...
constexpr uint32_t mask
Definition: gpuClustering.h:26
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(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