Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:23

0001 #ifndef DIGIFTL_FTLSAMPLE_H
0002 #define DIGIFTL_FTLSAMPLE_H
0003 
0004 #include <iostream>
0005 #include <ostream>
0006 #include <cstdint>
0007 
0008 /**
0009    @class FTLSample
0010    @short wrapper for a data word
0011  */
0012 
0013 class FTLSample {
0014 public:
0015   enum FTLSampleMasks { kThreshMask = 0x1, kModeMask = 0x1, kToAMask = 0xfff, kDataMask = 0xfff };
0016   enum FTLSampleShifts { kThreshShift = 31, kModeShift = 30, kToAShift = 13, kDataShift = 0 };
0017 
0018   /**
0019      @short CTOR
0020    */
0021   FTLSample() : value_(0) {}
0022   FTLSample(uint32_t value) : value_(value) {}
0023   FTLSample(const FTLSample& o) : value_(o.value_) {}
0024 
0025   /**
0026      @short setters
0027    */
0028   void setThreshold(bool thr) { setWord(thr, kThreshMask, kThreshShift); }
0029   void setMode(bool mode) { setWord(mode, kModeMask, kModeShift); }
0030   void setToA(uint16_t toa) { setWord(toa, kToAMask, kToAShift); }
0031   void setData(uint16_t data) { setWord(data, kDataMask, kDataShift); }
0032   void set(bool thr, bool mode, uint16_t toa, uint16_t data) {
0033     value_ = (((uint32_t)thr & kThreshMask) << kThreshShift | ((uint32_t)mode & kModeMask) << kModeShift |
0034               ((uint32_t)toa & kToAMask) << kToAShift | ((uint32_t)data & kDataMask) << kDataShift);
0035   }
0036   void print(std::ostream& out = std::cout) {
0037     out << "THR: " << threshold() << " Mode: " << mode() << " ToA: " << toa() << " Data: " << data() << " Raw=0x"
0038         << std::hex << raw() << std::dec << std::endl;
0039   }
0040 
0041   /**
0042      @short getters
0043   */
0044   uint32_t raw() const { return value_; }
0045   bool threshold() const { return ((value_ >> kThreshShift) & kThreshMask); }
0046   bool mode() const { return ((value_ >> kModeShift) & kModeMask); }
0047   uint32_t toa() const { return ((value_ >> kToAShift) & kToAMask); }
0048   uint32_t data() const { return ((value_ >> kDataShift) & kDataMask); }
0049   uint32_t operator()() { return value_; }
0050 
0051 private:
0052   /**
0053      @short wrapper to reset words at a given position
0054    */
0055   void setWord(uint32_t word, uint32_t mask, uint32_t pos) {
0056     //clear required bits
0057     const uint32_t masked_word = (word & mask) << pos;
0058     value_ &= ~(masked_word);
0059     //now set the new value
0060     value_ |= (masked_word);
0061   }
0062 
0063   // a 32-bit word
0064   uint32_t value_;
0065 };
0066 
0067 #endif