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) {
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()() { return value_; }
101  uint32_t raw() { return value_; }
102  bool tc() { return flag2(); }
103  bool tp() { return flag1(); }
104  uint16_t adc(bool charMode = false) { return charMode ? packet3() : (tc() ? 0 : packet2()); }
105  uint16_t adcm1(bool charMode = false) { return charMode ? 0 : packet3(); }
106  uint16_t tot(bool charMode = false) {
107  uint16_t tot12b(decompressToT(packet2()));
108  return charMode || tc() ? tot12b : 0;
109  }
110  uint16_t toa() { return packet1(); }
111  bool flag2() const { return readPacket(kFlagMask, kFlag2Shift); }
112  bool flag1() const { return readPacket(kFlagMask, kFlag1Shift); }
113  uint16_t packet3() const { return readPacket(kPacketMask, kPacket3Shift); }
114  uint16_t packet2() const { return readPacket(kPacketMask, kPacket2Shift); }
115  uint16_t packet1() const { return readPacket(kPacketMask, kPacket1Shift); }
116 
117  void print(std::ostream& out = std::cout) {
118  out << "Raw=0x" << std::hex << raw() << std::dec << std::endl
119  << "\tf2: " << flag2() << " f1: " << flag1() << " p3: " << packet3() << " p2: " << packet2()
120  << " p1: " << packet1() << std::endl
121  << "\ttc: " << tc() << " tp: " << tp() << " adcm1: " << adcm1() << " (" << adcm1(false) << ") "
122  << " adc: " << adc() << " (" << adc(false) << ") "
123  << " tot: " << tot() << " (" << tot(false) << ") "
124  << " toa: " << toa() << std::endl;
125  }
126 
127 private:
132  // mask and shift bits
133  const uint32_t masked_word = (word & mask) << shift;
134 
135  //clear to 0 bits which will be set by word
136  value_ &= ~(mask << shift);
137 
138  //now set bits
139  value_ |= (masked_word);
140  }
141 
146  return ((value_ >> shift) & mask);
147  }
148 
149  //det-id for this dataframe
151 
152  // a 32-bit word
153  uint32_t value_;
154 };
155 
156 #endif
void print(std::ostream &out=std::cout)
uint16_t adc(bool charMode=false)
HGCROCChannelDataFrame(const D &id, uint32_t value)
uint16_t tot(bool charMode=false)
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:24
uint64_t word
uint16_t decompressToT(uint16_t totraw)
the 10-bit TOT word is decompressed back to 12 bit word In case truncation occurred the word is shift...
HGCROCChannelDataFrame(uint32_t value)
Definition: value.py:1
void fillFlag2(bool flag)
setters
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:141
void fillPacket(uint16_t word, HGCROCChannelDataFrameMask mask, HGCROCChannelDataFrameShift shift)
wrapper to reset words at a given position
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...
HGCROCChannelDataFrame(const HGCROCChannelDataFrame &o)
uint16_t adcm1(bool charMode=false)
void fillRaw(bool flag2, bool flag1, uint16_t word3, uint16_t word2, uint16_t word1)