File indexing completed on 2024-04-06 12:05:12
0001 #ifndef TRACKINGOBJECTS_PIXELDIGI_H
0002 #define TRACKINGOBJECTS_PIXELDIGI_H
0003
0004
0005
0006 #include <utility>
0007 #include <algorithm>
0008 #include "DataFormats/SiPixelDetId/interface/PixelChannelIdentifier.h"
0009
0010
0011
0012
0013
0014 class PixelDigi {
0015 public:
0016 typedef unsigned int PackedDigiType;
0017 typedef unsigned int ChannelType;
0018
0019 explicit PixelDigi(PackedDigiType packed_value) : theData(packed_value) {}
0020
0021 PixelDigi(int row, int col, int adc) { init(row, col, adc); }
0022 PixelDigi(int row, int col, int adc, int flag) { init(row, col, adc, flag); }
0023
0024 PixelDigi(int chan, int adc) {
0025 std::pair<int, int> rc = channelToPixel(chan);
0026 init(rc.first, rc.second, adc);
0027 }
0028
0029 PixelDigi() : theData(0) {}
0030
0031 void init(int row, int col, int adc, int flag = 0) {
0032 #ifdef FIXME_DEBUG
0033
0034
0035
0036
0037 if (row < 0 || row > PixelChannelIdentifier::thePacking.max_row || col < 0 ||
0038 col > PixelChannelIdentifier::thePacking.max_column) {
0039 std::cout << "PixelDigi constructor: row or column out packing range " << row << ' ' << col << std::endl;
0040 }
0041 #endif
0042
0043
0044 adc = (adc > PixelChannelIdentifier::thePacking.max_adc) ? PixelChannelIdentifier::thePacking.max_adc
0045 : std::max(adc, 0);
0046
0047 theData = (row << PixelChannelIdentifier::thePacking.row_shift) |
0048 (col << PixelChannelIdentifier::thePacking.column_shift) |
0049 (adc << PixelChannelIdentifier::thePacking.adc_shift) |
0050 (flag << PixelChannelIdentifier::thePacking.flag_shift);
0051 }
0052
0053
0054 int row() const {
0055 return (theData >> PixelChannelIdentifier::thePacking.row_shift) & PixelChannelIdentifier::thePacking.row_mask;
0056 }
0057 int column() const {
0058 return (theData >> PixelChannelIdentifier::thePacking.column_shift) &
0059 PixelChannelIdentifier::thePacking.column_mask;
0060 }
0061 int flag() const {
0062 return (theData >> PixelChannelIdentifier::thePacking.flag_shift) & PixelChannelIdentifier::thePacking.flag_mask;
0063 }
0064 unsigned short adc() const {
0065 return (theData >> PixelChannelIdentifier::thePacking.adc_shift) & PixelChannelIdentifier::thePacking.adc_mask;
0066 }
0067 PackedDigiType packedData() const { return theData; }
0068
0069 static std::pair<int, int> channelToPixel(int ch) {
0070 int row = (ch >> PixelChannelIdentifier::thePacking.column_width) & PixelChannelIdentifier::thePacking.row_mask;
0071 int col = ch & PixelChannelIdentifier::thePacking.column_mask;
0072 return std::pair<int, int>(row, col);
0073 }
0074
0075 static int pixelToChannel(int row, int col) { return (row << PixelChannelIdentifier::thePacking.column_width) | col; }
0076
0077 int channel() const { return PixelChannelIdentifier::pixelToChannel(row(), column()); }
0078
0079 private:
0080 PackedDigiType theData;
0081 };
0082
0083
0084
0085
0086
0087
0088
0089 inline bool operator<(const PixelDigi& one, const PixelDigi& other) {
0090 return (one.packedData() & PixelChannelIdentifier::thePacking.rowcol_mask) <
0091 (other.packedData() & PixelChannelIdentifier::thePacking.rowcol_mask);
0092 }
0093
0094 #include <iostream>
0095 inline std::ostream& operator<<(std::ostream& o, const PixelDigi& digi) {
0096 return o << " " << digi.channel() << " " << digi.adc();
0097 }
0098
0099 #endif