CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DataFormats/SiPixelDigi/interface/PixelDigi.h

Go to the documentation of this file.
00001 #ifndef TRACKINGOBJECTS_PIXELDIGI_H
00002 #define TRACKINGOBJECTS_PIXELDIGI_H
00003 
00004 // 25/06/06 - get rid of time(), change adc() from int to undigned short. d.k.
00005 
00006 #include <utility>
00007 #include "DataFormats/SiPixelDetId/interface/PixelChannelIdentifier.h"
00008 
00013 class PixelDigi {
00014 public:
00015 
00016   typedef unsigned int PackedDigiType;
00017   typedef unsigned int ChannelType;
00018 
00019   PixelDigi( int packed_value) : theData(packed_value) {}
00020 
00021   PixelDigi( int row, int col, int adc) {
00022     init( row, col, adc);
00023   }
00024 
00025   PixelDigi( int chan, int adc) {
00026     std::pair<int,int> rc = channelToPixel(chan);
00027     init( rc.first, rc.second, adc);
00028   }
00029 
00030   PixelDigi() : theData(0)  {}
00031 
00032   void init( int row, int col, int adc);
00033 
00034   // Access to digi information
00035   int row() const     {return (theData >> PixelChannelIdentifier::thePacking.row_shift) & PixelChannelIdentifier::thePacking.row_mask;}
00036   int column() const  {return (theData >> PixelChannelIdentifier::thePacking.column_shift) & PixelChannelIdentifier::thePacking.column_mask;}
00037   //int time() const    {return (theData >> PixelChannelIdentifier::thePacking.time_shift) & PixelChannelIdentifier::thePacking.time_mask;}
00038   unsigned short adc() const  {return (theData >> PixelChannelIdentifier::thePacking.adc_shift) & PixelChannelIdentifier::thePacking.adc_mask;}
00039   PackedDigiType packedData() const {return theData;}
00040 
00041   static std::pair<int,int> channelToPixel( int ch) {
00042     int row = ( ch >> PixelChannelIdentifier::thePacking.column_width) & PixelChannelIdentifier::thePacking.row_mask;
00043     int col = ch & PixelChannelIdentifier::thePacking.column_mask;
00044     return std::pair<int,int>(row,col);
00045   }
00046 
00047   static int pixelToChannel( int row, int col) {
00048     return (row << PixelChannelIdentifier::thePacking.column_width) | col;
00049   }
00050 
00051   int channel() const {return PixelChannelIdentifier::pixelToChannel( row(), column());}
00052 
00053  private:
00054   PackedDigiType theData;
00055 };  
00056 
00057 // Comparison operators
00058 inline bool operator<( const PixelDigi& one, const PixelDigi& other) {
00059   return one.channel() < other.channel();
00060 }
00061 
00062 #include<iostream>
00063 inline std::ostream & operator<<(std::ostream & o, const PixelDigi& digi) {
00064   return o << " " << digi.channel()
00065            << " " << digi.adc();
00066 }
00067 
00068 #endif