Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DIGIFTL_BTLSAMPLE_H
0002 #define DIGIFTL_BTLSAMPLE_H
0003 
0004 #include <iostream>
0005 #include <ostream>
0006 #include <cstdint>
0007 
0008 /**
0009    @class BTLSample
0010    @short wrapper for a data word
0011  */
0012 
0013 class BTLSample {
0014 public:
0015   enum BTLSampleDataMasks { kToA2Mask = 0x3ff, kToAMask = 0x3ff, kDataMask = 0x3ff };
0016   enum BTLSampleDataShifts { kToA2Shift = 20, kToAShift = 10, kDataShift = 0 };
0017 
0018   enum BTLSampleFlagMasks { kThreshMask = 0x1, kModeMask = 0x1 };
0019   enum BTLSampleFlagShifts { kThreshShift = 1, kModeShift = 0 };
0020 
0021   /**
0022      @short CTOR
0023   */
0024   BTLSample() : value_(0), flag_(0), row_(0), col_(0) {}
0025   BTLSample(uint32_t value, uint16_t flag, uint8_t row, uint8_t col)
0026       : value_(value), flag_(flag), row_(row), col_(col) {}
0027   BTLSample(const BTLSample& o) : value_(o.value_), flag_(o.flag_), row_(o.row_), col_(o.col_) {}
0028 
0029   /**
0030      @short setters
0031   */
0032   void setThreshold(bool thr) { setFlagWord(thr, kThreshMask, kThreshShift); }
0033   void setMode(bool mode) { setFlagWord(mode, kModeMask, kModeShift); }
0034   void setToA(uint16_t toa) { setDataWord(toa, kToAMask, kToAShift); }
0035   void setToA2(uint16_t toa2) { setDataWord(toa2, kToA2Mask, kToA2Shift); }
0036   void setData(uint16_t data) { setDataWord(data, kDataMask, kDataShift); }
0037   void set(bool thr, bool mode, uint16_t toa2, uint16_t toa, uint16_t data, uint8_t row, uint8_t col) {
0038     flag_ = (((uint16_t)thr & kThreshMask) << kThreshShift | ((uint16_t)mode & kModeMask) << kModeShift);
0039 
0040     value_ = (((uint32_t)toa2 & kToA2Mask) << kToA2Shift | ((uint32_t)toa & kToAMask) << kToAShift |
0041               ((uint32_t)data & kDataMask) << kDataShift);
0042     row_ = row;
0043     col_ = col;
0044   }
0045   void print(std::ostream& out = std::cout) {
0046     out << "THR: " << threshold() << " Mode: " << mode() << " ToA2: " << toa2() << " ToA: " << toa()
0047         << " Data: " << data() << " Row: " << (uint32_t)row() << " Column: " << (uint32_t)column() << " Raw Flag=0x"
0048         << std::hex << raw_flag() << std::dec << " Raw Data=0x" << std::hex << raw_data() << std::dec << std::endl;
0049   }
0050 
0051   /**
0052      @short getters
0053   */
0054   uint32_t raw_data() const { return value_; }
0055   uint16_t raw_flag() const { return flag_; }
0056   bool threshold() const { return ((flag_ >> kThreshShift) & kThreshMask); }
0057   bool mode() const { return ((flag_ >> kModeShift) & kModeMask); }
0058   uint32_t toa() const { return ((value_ >> kToAShift) & kToAMask); }
0059   uint32_t toa2() const { return ((value_ >> kToA2Shift) & kToA2Mask); }
0060   uint32_t data() const { return ((value_ >> kDataShift) & kDataMask); }
0061   uint8_t row() const { return row_; }
0062   uint8_t column() const { return col_; }
0063 
0064 private:
0065   /**
0066      @short wrapper to reset words at a given position
0067    */
0068   void setDataWord(uint32_t word, uint32_t mask, uint32_t pos) {
0069     //clear required bits
0070     value_ &= ~(mask << pos);
0071     //now set the new value
0072     value_ |= ((word & mask) << pos);
0073   }
0074   void setFlagWord(uint16_t word, uint16_t mask, uint16_t pos) {
0075     //clear required bits
0076     flag_ &= ~(mask << pos);
0077     //now set the new value
0078     flag_ |= ((word & mask) << pos);
0079   }
0080 
0081   // bit-words for data and flags
0082   uint32_t value_;
0083   uint16_t flag_;
0084   uint8_t row_, col_;
0085 };
0086 
0087 #endif