CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
23  HGCSample() : value_(0) { }
24  HGCSample(uint32_t value) : value_(value) { }
25 
29  void setThreshold(bool thr) { setWord(thr, kThreshMask, kThreshShift); }
30  void setMode(bool mode) { setWord(mode, kModeMask, kModeShift); }
31  void setToA(uint16_t toa) { setWord(toa, kToAMask, kToAShift); }
32  void setData(uint16_t data) { setWord(data, kDataMask, kDataShift); }
33  void set(bool thr, bool mode,uint16_t toa, uint16_t data)
34  {
35  setThreshold(thr);
36  setMode(mode);
37  setToA(toa);
38  setData(data);
39  }
40  void print(std::ostream &out=std::cout)
41  {
42  out << "THR: " << threshold()
43  << " Mode: " << mode()
44  << " ToA: " << toa()
45  << " Data: " << data()
46  << " Raw=0x" << std::hex << raw() << std::dec << std::endl;
47  }
48 
52  uint32_t raw() const { return value_; }
53  bool threshold() const { return ((value_ >> 31) & 0x1 ); }
54  bool mode() const { return ((value_ >> 30) & 0x1 ); }
55  uint32_t toa() const { return ((value_ >> 16) & 0x3ff); }
56  uint32_t data() const { return ((value_ >> 0) & 0xfff); }
57  uint32_t operator()() { return value_; }
58 
59 private:
60 
64  void setWord(uint32_t word, uint32_t mask, uint32_t pos)
65  {
66  //clear required bits
67  value_ &= ~((word & mask) << pos);
68  //now set the new value
69  value_ |= ((word & mask) << pos);
70  }
71 
72  // a 32-bit word
73  uint32_t value_;
74 };
75 
76 
77 #endif
uint32_t data() const
Definition: HGCSample.h:56
bool mode() const
Definition: HGCSample.h:54
void print(std::ostream &out=std::cout)
Definition: HGCSample.h:40
uint32_t value_
Definition: HGCSample.h:73
void setMode(bool mode)
Definition: HGCSample.h:30
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:29
bool threshold() const
Definition: HGCSample.h:53
HGCSampleShifts
Definition: HGCSample.h:18
HGCSampleMasks
Definition: HGCSample.h:17
void setToA(uint16_t toa)
Definition: HGCSample.h:31
void setWord(uint32_t word, uint32_t mask, uint32_t pos)
wrapper to reset words at a given position
Definition: HGCSample.h:64
uint32_t raw() const
getters
Definition: HGCSample.h:52
uint32_t toa() const
Definition: HGCSample.h:55
tuple cout
Definition: gather_cfg.py:145
void set(bool thr, bool mode, uint16_t toa, uint16_t data)
Definition: HGCSample.h:33
uint32_t operator()()
Definition: HGCSample.h:57
void setData(uint16_t data)
Definition: HGCSample.h:32