Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-18 02:24:53

0001 #ifndef DataFormats_SiPixelDetId_interface_PixelChannelIdentifier_h
0002 #define DataFormats_SiPixelDetId_interface_PixelChannelIdentifier_h
0003 
0004 #include <utility>
0005 #include <cstdint>
0006 
0007 namespace pixelchannelidentifierimpl {
0008   /**
0009    * Pack the pixel information to use less memory
0010    */
0011 
0012   class Packing {
0013   public:
0014     using PackedDigiType = uint32_t;
0015 
0016     // Constructor: pre-computes masks and shifts from field widths
0017     constexpr Packing(unsigned int row_w, unsigned int column_w, unsigned int flag_w, unsigned int adc_w)
0018         : row_width(row_w),
0019           column_width(column_w),
0020           adc_width(adc_w),
0021           row_shift(0),
0022           column_shift(row_shift + row_w),
0023           flag_shift(column_shift + column_w),
0024           adc_shift(flag_shift + flag_w),
0025           row_mask(~(~0U << row_w)),
0026           column_mask(~(~0U << column_w)),
0027           flag_mask(~(~0U << flag_w)),
0028           adc_mask(~(~0U << adc_w)),
0029           rowcol_mask(~(~0U << (column_w + row_w))),
0030           max_row(row_mask),
0031           max_column(column_mask),
0032           max_adc(adc_mask) {}
0033 
0034     const uint32_t row_width;
0035     const uint32_t column_width;
0036     const uint32_t adc_width;
0037 
0038     const uint32_t row_shift;
0039     const uint32_t column_shift;
0040     const uint32_t flag_shift;
0041     const uint32_t adc_shift;
0042 
0043     const PackedDigiType row_mask;
0044     const PackedDigiType column_mask;
0045     const PackedDigiType flag_mask;
0046     const PackedDigiType adc_mask;
0047     const PackedDigiType rowcol_mask;
0048 
0049     const int max_row;
0050     const int max_column;
0051     const int max_adc;
0052   };
0053 }  // namespace pixelchannelidentifierimpl
0054 
0055 class PixelChannelIdentifier {
0056 public:
0057   typedef unsigned int PackedDigiType;
0058   typedef unsigned int ChannelType;
0059 
0060   static std::pair<int, int> channelToPixel(int ch) {
0061     int row = (ch >> thePacking.column_width) & thePacking.row_mask;
0062     int col = ch & thePacking.column_mask;
0063     return std::pair<int, int>(row, col);
0064   }
0065 
0066   static int pixelToChannel(int row, int col) { return (row << thePacking.column_width) | col; }
0067 
0068   using Packing = pixelchannelidentifierimpl::Packing;
0069 
0070 public:
0071   constexpr static Packing packing() { return Packing(8, 9, 4, 11); }
0072 
0073   constexpr static Packing thePacking = {11, 10, 1, 10};
0074 };
0075 
0076 #endif  // DataFormats_SiPixelDetId_interface_PixelChannelIdentifier_h