Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-12-05 03:11:44

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   ETLSample& operator=(const ETLSample&) = default;
0039 
0040   /**
0041      @short setters
0042    */
0043   void setThreshold(bool thr) { setWord(thr, kThreshMask, kThreshShift); }
0044   void setMode(bool mode) { setWord(mode, kModeMask, kModeShift); }
0045   void setColumn(uint8_t col) { setWord(col, kColumnMask, kColumnShift); }
0046   void setRow(uint8_t row) { setWord(row, kRowMask, kRowShift); }
0047   void setToA(uint16_t toa) { setWord(toa, kToAMask, kToAShift); }
0048   void setData(uint16_t data) { setWord(data, kDataMask, kDataShift); }
0049   void set(bool thr, bool mode, uint16_t toa, uint16_t data, uint8_t row, uint8_t col) {
0050     value_ = (((uint32_t)thr & kThreshMask) << kThreshShift | ((uint32_t)mode & kModeMask) << kModeShift |
0051               ((uint32_t)col & kColumnMask) << kColumnShift | ((uint32_t)row & kRowMask) << kRowShift |
0052               ((uint32_t)toa & kToAMask) << kToAShift | ((uint32_t)data & kDataMask) << kDataShift);
0053   }
0054   void print(std::ostream& out = std::cout) {
0055     out << "(row,col) : (" << row() << ',' << column() << ") "
0056         << "THR: " << threshold() << " Mode: " << mode() << " ToA: " << toa() << " Data: " << data() << " Raw=0x"
0057         << std::hex << raw() << std::dec << std::endl;
0058   }
0059 
0060   /**
0061      @short getters
0062   */
0063   uint32_t raw() const { return value_; }
0064   bool threshold() const { return ((value_ >> kThreshShift) & kThreshMask); }
0065   bool mode() const { return ((value_ >> kModeShift) & kModeMask); }
0066   uint32_t column() const { return ((value_ >> kColumnShift) & kColumnMask); }
0067   uint32_t row() const { return ((value_ >> kRowShift) & kRowMask); }
0068   uint32_t toa() const { return ((value_ >> kToAShift) & kToAMask); }
0069   uint32_t data() const { return ((value_ >> kDataShift) & kDataMask); }
0070   uint32_t operator()() { return value_; }
0071 
0072 private:
0073   /**
0074      @short wrapper to reset words at a given position
0075    */
0076   void setWord(uint32_t word, uint32_t mask, uint32_t pos) {
0077     //clear required bits
0078     value_ &= ~(mask << pos);
0079     //now set the new value
0080     value_ |= ((word & mask) << pos);
0081   }
0082 
0083   // a 32-bit word
0084   uint32_t value_;
0085 };
0086 
0087 #endif