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 <boost/cstdint.hpp>
7 
13 class HGCSample {
14 
15 public:
16 
17  enum HGCSampleMasks { kThreshMask = 0x1, kModeMask = 0x1, kToAMask = 0x3ff, kDataMask = 0xfff};
19 
24  HGCSample(uint32_t value) : value_(value), toaFired_(false) { }
26 
30  void setThreshold(bool thr) { setWord(thr, kThreshMask, kThreshShift); }
31  void setMode(bool mode) { setWord(mode, kModeMask, kModeShift); }
32  void setToA(uint16_t toa) { setWord(toa, kToAMask, kToAShift); }
33  void setToAValid(bool toaFired) { toaFired_ = toaFired; }
34  void setData(uint16_t data) { setWord(data, kDataMask, kDataShift); }
35  void set(bool thr, bool mode,uint16_t toa, uint16_t data)
36  {
37  toa = ( toa > kToAMask ? kToAMask : toa );
38  data = ( data > kDataMask ? kDataMask : data);
39 
40  value_ = ( ( (uint32_t)thr & kThreshMask ) << kThreshShift |
41  ( (uint32_t)mode & kModeMask ) << kModeShift |
42  ( (uint32_t)toa & kToAMask ) << kToAShift |
43  ( (uint32_t)data & kDataMask ) << kDataShift );
44  }
45  void print(std::ostream &out=std::cout)
46  {
47  out << "THR: " << threshold()
48  << " Mode: " << mode()
49  << " ToA: " << toa()
50  << " Data: " << data()
51  << " Raw=0x" << std::hex << raw() << std::dec << std::endl;
52  }
53 
57  uint32_t raw() const { return value_; }
58  bool threshold() const { return ( (value_ >> kThreshShift) & kThreshMask ); }
59  bool mode() const { return ( (value_ >> kModeShift) & kModeMask ); }
60  bool getToAValid() const { return toaFired_; }
61  uint32_t toa() const { return ( (value_ >> kToAShift) & kToAMask ); }
62  uint32_t data() const { return ( (value_ >> kDataShift) & kDataMask ); }
63  uint32_t operator()() { return value_; }
64 
65 private:
66 
70  void setWord(uint32_t word, uint32_t mask, uint32_t pos)
71  {
72  if( word > mask ) word = mask; // deal with saturation
73  //clear required bits
74  const uint32_t masked_word = (word & mask) << pos;
75  value_ &= ~(masked_word);
76  //now set the new value
77  value_ |= (masked_word);
78  }
79 
80  // a 32-bit word
81  uint32_t value_;
82  bool toaFired_;
83 };
84 
85 
86 #endif
uint32_t data() const
Definition: HGCSample.h:62
bool mode() const
Definition: HGCSample.h:59
HGCSample(const HGCSample &o)
Definition: HGCSample.h:25
void print(std::ostream &out=std::cout)
Definition: HGCSample.h:45
uint32_t value_
Definition: HGCSample.h:81
void setMode(bool mode)
Definition: HGCSample.h:31
bool getToAValid() const
Definition: HGCSample.h:60
wrapper for a data word
Definition: HGCSample.h:13
HGCSample()
CTOR.
Definition: HGCSample.h:23
HGCSample(uint32_t value)
Definition: HGCSample.h:24
void setThreshold(bool thr)
setters
Definition: HGCSample.h:30
bool threshold() const
Definition: HGCSample.h:58
HGCSampleShifts
Definition: HGCSample.h:18
HGCSampleMasks
Definition: HGCSample.h:17
void setToA(uint16_t toa)
Definition: HGCSample.h:32
void setWord(uint32_t word, uint32_t mask, uint32_t pos)
wrapper to reset words at a given position
Definition: HGCSample.h:70
Definition: value.py:1
uint32_t raw() const
getters
Definition: HGCSample.h:57
void setToAValid(bool toaFired)
Definition: HGCSample.h:33
uint32_t toa() const
Definition: HGCSample.h:61
bool toaFired_
Definition: HGCSample.h:82
uint32_t operator()()
Definition: HGCSample.h:63
void setData(uint16_t data)
Definition: HGCSample.h:34