Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DIGIFTL_ETLSAMPLE_H
0002 #define DIGIFTL_ETLSAMPLE_H
0003 
0004 #include <iostream>
0005 #include <ostream>
0006 #include <cstdint>
0007 
0008 /**
0009    @class ETLSample
0010    @short wrapper for a data word
0011  */
0012 
0013 class ETLSample {
0014 public:
0015   enum ETLSampleMasks {
0016     kThreshMask = 0x1,
0017     kModeMask = 0x1,
0018     kColumnMask = 0x1f,
0019     kRowMask = 0x3f,
0020     kToAMask = 0x7ff,
0021     kDataMask = 0xff
0022   };
0023   enum ETLSampleShifts {
0024     kThreshShift = 31,
0025     kModeShift = 30,
0026     kColumnShift = 25,
0027     kRowShift = 19,
0028     kToAShift = 8,
0029     kDataShift = 0
0030   };
0031 
0032   /**
0033      @short CTOR
0034    */
0035   ETLSample() : value_(0) {}
0036   ETLSample(uint32_t value) : value_(value) {}
0037   ETLSample(const ETLSample& o) : value_(o.value_) {}
0038 
0039   /**
0040      @short setters
0041    */
0042   void setThreshold(bool thr) { setWord(thr, kThreshMask, kThreshShift); }
0043   void setMode(bool mode) { setWord(mode, kModeMask, kModeShift); }
0044   void setColumn(uint8_t col) { setWord(col, kColumnMask, kColumnShift); }
0045   void setRow(uint8_t row) { setWord(row, kRowMask, kRowShift); }
0046   void setToA(uint16_t toa) { setWord(toa, kToAMask, kToAShift); }
0047   void setData(uint16_t data) { setWord(data, kDataMask, kDataShift); }
0048   void set(bool thr, bool mode, uint16_t toa, uint16_t data, uint8_t row, uint8_t col) {
0049     value_ = (((uint32_t)thr & kThreshMask) << kThreshShift | ((uint32_t)mode & kModeMask) << kModeShift |
0050               ((uint32_t)col & kColumnMask) << kColumnShift | ((uint32_t)row & kRowMask) << kRowShift |
0051               ((uint32_t)toa & kToAMask) << kToAShift | ((uint32_t)data & kDataMask) << kDataShift);
0052   }
0053   void print(std::ostream& out = std::cout) {
0054     out << "(row,col) : (" << row() << ',' << column() << ") "
0055         << "THR: " << threshold() << " Mode: " << mode() << " ToA: " << toa() << " Data: " << data() << " Raw=0x"
0056         << std::hex << raw() << std::dec << std::endl;
0057   }
0058 
0059   /**
0060      @short getters
0061   */
0062   uint32_t raw() const { return value_; }
0063   bool threshold() const { return ((value_ >> kThreshShift) & kThreshMask); }
0064   bool mode() const { return ((value_ >> kModeShift) & kModeMask); }
0065   uint32_t column() const { return ((value_ >> kColumnShift) & kColumnMask); }
0066   uint32_t row() const { return ((value_ >> kRowShift) & kRowMask); }
0067   uint32_t toa() const { return ((value_ >> kToAShift) & kToAMask); }
0068   uint32_t data() const { return ((value_ >> kDataShift) & kDataMask); }
0069   uint32_t operator()() { return value_; }
0070 
0071 private:
0072   /**
0073      @short wrapper to reset words at a given position
0074    */
0075   void setWord(uint32_t word, uint32_t mask, uint32_t pos) {
0076     //clear required bits
0077     value_ &= ~(mask << pos);
0078     //now set the new value
0079     value_ |= ((word & mask) << pos);
0080   }
0081 
0082   // a 32-bit word
0083   uint32_t value_;
0084 };
0085 
0086 #endif