File indexing completed on 2024-04-06 12:04:01
0001 #ifndef CTPPS_CTPPSDigi_CTPPSPixelDigi_h
0002 #define CTPPS_CTPPSDigi_CTPPSPixelDigi_h
0003
0004
0005
0006
0007
0008 #include "FWCore/Utilities/interface/Exception.h"
0009
0010 class CTPPSPixelDigi {
0011 public:
0012 CTPPSPixelDigi(int packed_value) : theData(packed_value) {}
0013
0014 CTPPSPixelDigi(int row, int col, int adc) { init(row, col, adc); }
0015
0016 CTPPSPixelDigi(int chan, int adc) {
0017 std::pair<int, int> rc = channelToPixel(chan);
0018 init(rc.first, rc.second, adc);
0019 }
0020
0021 CTPPSPixelDigi() : theData(0) {}
0022
0023
0024 int row() const { return (theData >> row_shift) & row_mask; }
0025 int column() const { return (theData >> column_shift) & column_mask; }
0026 unsigned short adc() const { return (theData >> adc_shift) & adc_mask; }
0027 uint32_t packedData() const { return theData; }
0028
0029 static std::pair<int, int> channelToPixel(int ch) {
0030 int row = (ch >> column_width_ch) & row_mask_ch;
0031 int col = ch & column_mask_ch;
0032 return std::pair<int, int>(row, col);
0033 }
0034
0035 static int pixelToChannel(int row, int col) { return (row << column_width_ch) | col; }
0036
0037 int channel() const { return pixelToChannel(row(), column()); }
0038
0039
0040 static const uint32_t row_shift, column_shift, adc_shift;
0041 static const uint32_t row_mask, column_mask, adc_mask, rowcol_mask;
0042 static const uint32_t row_width, column_width, adc_width;
0043 static const uint32_t max_row, max_column, max_adc;
0044
0045
0046 static const uint32_t column_width_ch;
0047 static const uint32_t column_mask_ch;
0048 static const uint32_t row_mask_ch;
0049
0050 private:
0051 void init(int row, int col, int adc);
0052 uint32_t theData;
0053 };
0054
0055
0056
0057 inline bool operator<(const CTPPSPixelDigi& one, const CTPPSPixelDigi& other) {
0058 return (one.packedData() & CTPPSPixelDigi::rowcol_mask) < (other.packedData() & CTPPSPixelDigi::rowcol_mask);
0059 }
0060
0061 #include <iostream>
0062 inline std::ostream& operator<<(std::ostream& o, const CTPPSPixelDigi& digi) {
0063 return o << " " << digi.row() << " " << digi.column() << " " << digi.adc();
0064 }
0065
0066 #endif