CMS 3D CMS Logo

FTLSample.h
Go to the documentation of this file.
1 #ifndef DIGIFTL_FTLSAMPLE_H
2 #define DIGIFTL_FTLSAMPLE_H
3 
4 #include <iostream>
5 #include <ostream>
6 #include <boost/cstdint.hpp>
7 
13 class FTLSample {
14 
15 public:
16 
17  enum FTLSampleMasks { kThreshMask = 0x1, kModeMask = 0x1, kToAMask = 0xfff, kDataMask = 0xfff};
19 
23  FTLSample() : value_(0) { }
24  FTLSample(uint32_t value) : value_(value) { }
25  FTLSample( const FTLSample& o ) : value_(o.value_) { }
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 setData(uint16_t data) { setWord(data, kDataMask, kDataShift); }
34  void set(bool thr, bool mode,uint16_t toa, uint16_t data)
35  {
36  value_ = ( ( (uint32_t)thr & kThreshMask ) << kThreshShift |
37  ( (uint32_t)mode & kModeMask ) << kModeShift |
38  ( (uint32_t)toa & kToAMask ) << kToAShift |
39  ( (uint32_t)data & kDataMask ) << kDataShift );
40  }
41  void print(std::ostream &out=std::cout)
42  {
43  out << "THR: " << threshold()
44  << " Mode: " << mode()
45  << " ToA: " << toa()
46  << " Data: " << data()
47  << " Raw=0x" << std::hex << raw() << std::dec << std::endl;
48  }
49 
53  uint32_t raw() const { return value_; }
54  bool threshold() const { return ( (value_ >> kThreshShift) & kThreshMask ); }
55  bool mode() const { return ( (value_ >> kModeShift) & kModeMask ); }
56  uint32_t toa() const { return ( (value_ >> kToAShift) & kToAMask ); }
57  uint32_t data() const { return ( (value_ >> kDataShift) & kDataMask ); }
58  uint32_t operator()() { return value_; }
59 
60 private:
61 
65  void setWord(uint32_t word, uint32_t mask, uint32_t pos)
66  {
67  //clear required bits
68  const uint32_t masked_word = (word & mask) << pos;
69  value_ &= ~(masked_word);
70  //now set the new value
71  value_ |= (masked_word);
72  }
73 
74  // a 32-bit word
75  uint32_t value_;
76 };
77 
78 
79 #endif
bool mode() const
Definition: FTLSample.h:55
uint32_t raw() const
getters
Definition: FTLSample.h:53
FTLSample(uint32_t value)
Definition: FTLSample.h:24
FTLSampleMasks
Definition: FTLSample.h:17
void setMode(bool mode)
Definition: FTLSample.h:31
uint32_t value_
Definition: FTLSample.h:75
uint32_t operator()()
Definition: FTLSample.h:58
FTLSampleShifts
Definition: FTLSample.h:18
FTLSample()
CTOR.
Definition: FTLSample.h:23
void setToA(uint16_t toa)
Definition: FTLSample.h:32
wrapper for a data word
Definition: FTLSample.h:13
void setData(uint16_t data)
Definition: FTLSample.h:33
void setThreshold(bool thr)
setters
Definition: FTLSample.h:30
FTLSample(const FTLSample &o)
Definition: FTLSample.h:25
Definition: value.py:1
void print(std::ostream &out=std::cout)
Definition: FTLSample.h:41
bool threshold() const
Definition: FTLSample.h:54
uint32_t toa() const
Definition: FTLSample.h:56
void setWord(uint32_t word, uint32_t mask, uint32_t pos)
wrapper to reset words at a given position
Definition: FTLSample.h:65
uint32_t data() const
Definition: FTLSample.h:57