Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:08

0001 #ifndef DATAFORMATS_MTDCHANNELIDENTIFIER_H
0002 #define DATAFORMATS_MTDCHANNELIDENTIFIER_H
0003 
0004 #include <utility>
0005 
0006 class MTDChannelIdentifier {
0007 public:
0008   static const MTDChannelIdentifier& GetInstance() {
0009     static const MTDChannelIdentifier instance(6, 5, 12, 9);
0010     return instance;
0011   }
0012 
0013   typedef unsigned int PackedDigiType;
0014   typedef unsigned int ChannelType;
0015 
0016   static std::pair<int, int> channelToPixel(int ch) {
0017     int row = (ch >> GetInstance().column_width) & GetInstance().row_mask;
0018     int col = ch & GetInstance().column_mask;
0019     return std::pair<int, int>(row, col);
0020   }
0021 
0022   static int pixelToChannel(int row, int col) { return (row << GetInstance().column_width) | col; }
0023 
0024   MTDChannelIdentifier(const MTDChannelIdentifier&) = delete;
0025   MTDChannelIdentifier& operator=(const MTDChannelIdentifier&) = delete;
0026   MTDChannelIdentifier(MTDChannelIdentifier&&) = delete;
0027   MTDChannelIdentifier& operator=(MTDChannelIdentifier&&) = delete;
0028 
0029 private:
0030   MTDChannelIdentifier(unsigned int row_w, unsigned int column_w, unsigned int time_w, unsigned int adc_w)
0031       : row_width(row_w),
0032         column_width(column_w),
0033         adc_width(adc_w),
0034         row_shift(0),
0035         column_shift(row_shift + row_w),
0036         time_shift(column_shift + column_w),
0037         adc_shift(time_shift + time_w),
0038         row_mask(~(~0U << row_w)),
0039         column_mask(~(~0U << column_w)),
0040         time_mask(~(~0U << time_w)),
0041         adc_mask(~(~0U << adc_w)),
0042         rowcol_mask(~(~0U << (column_w + row_w))),
0043         max_row(row_mask),
0044         max_column(column_mask),
0045         max_adc(adc_mask) {}
0046 
0047   ~MTDChannelIdentifier() = default;
0048 
0049   const int row_width;
0050   const int column_width;
0051   const int adc_width;
0052 
0053   const int row_shift;
0054   const int column_shift;
0055   const int time_shift;
0056   const int adc_shift;
0057 
0058   const PackedDigiType row_mask;
0059   const PackedDigiType column_mask;
0060   const PackedDigiType time_mask;
0061   const PackedDigiType adc_mask;
0062   const PackedDigiType rowcol_mask;
0063 
0064   const int max_row;
0065   const int max_column;
0066   const int max_adc;
0067 };
0068 
0069 #endif