CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/RecoLocalTracker/SiPixelClusterizer/interface/SiPixelArrayBuffer.h

Go to the documentation of this file.
00001 #ifndef RecoLocalTracker_SiPixelClusterizer_SiPixelArrayBuffer_H
00002 #define RecoLocalTracker_SiPixelClusterizer_SiPixelArrayBuffer_H
00003 
00004 //----------------------------------------------------------------------------
00017 //----------------------------------------------------------------------------
00018 
00019 // We use PixelPos which is an inner class of SiPixelCluster:
00020 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
00021 
00022 #include <vector>
00023 #include <iostream>
00024 
00025 
00026 
00027 class SiPixelArrayBuffer 
00028 {
00029  public:
00030   inline SiPixelArrayBuffer( int rows, int cols);
00031   inline SiPixelArrayBuffer( ){}
00032   
00033   inline void setSize( int rows, int cols);
00034   inline int operator()( int row, int col) const;
00035   inline int operator()( const SiPixelCluster::PixelPos&) const;
00036   inline int rows() const { return nrows;}
00037   inline int columns() const { return ncols;}
00038 
00039   inline bool inside(int row, int col) const;
00040   inline void set_adc( int row, int col, int adc);
00041   inline void set_adc( const SiPixelCluster::PixelPos&, int adc);
00042   int size() const { return pixel_vec.size();}
00043 
00045   int index( int row, int col) const {return col*nrows+row;}
00046   int index( const SiPixelCluster::PixelPos& pix) const { return index(pix.row(), pix.col()); }
00047 
00048  private:
00049   int nrows;
00050   int ncols;
00051   std::vector<int> pixel_vec;   // TO DO: any benefit in using shorts instead?
00052 };
00053 
00054 
00055 
00056 SiPixelArrayBuffer::SiPixelArrayBuffer( int rows, int cols) 
00057   :  nrows(rows), ncols(cols) 
00058 {
00059   pixel_vec.resize(rows*cols);
00060 
00061   // TO DO: check this now:
00062   // Some STL implementations have problems with default values 
00063   // so a initialization loop is used instead
00064   std::vector<int>::iterator i=pixel_vec.begin(), iend=pixel_vec.end();
00065   for ( ; i!=iend; ++i) {
00066     *i = 0;
00067   }
00068 }
00069 
00070 
00071 void SiPixelArrayBuffer::setSize( int rows, int cols) 
00072 {
00073   nrows = rows;
00074   ncols = cols;
00075   pixel_vec.resize(rows*cols);
00076   //std::cout << " Resize the clusterize pixel buffer " << (rows*cols) 
00077   //    << std::endl;
00078 
00079   // TO DO: check this now:
00080   // Some STL implementations have problems with default values 
00081   // so a initialization loop is used instead
00082   std::vector<int>::iterator i=pixel_vec.begin(), iend=pixel_vec.end();
00083   for ( ; i!=iend; ++i) {
00084     *i = 0;
00085   }
00086 }
00087 
00088 
00089 bool SiPixelArrayBuffer::inside(int row, int col) const 
00090 {
00091   return ( row >= 0 && row < nrows && col >= 0 && col < ncols);
00092 }
00093 
00094 
00095 int SiPixelArrayBuffer::operator()(int row, int col) const 
00096 {
00097   if (inside(row,col))  return pixel_vec[index(row,col)];
00098   else  return 0;
00099 }
00100 
00101 
00102 int SiPixelArrayBuffer::operator()(const SiPixelCluster::PixelPos& pix) const 
00103 {
00104   if (inside( pix.row(), pix.col())) return pixel_vec[index(pix)];
00105   else return 0;
00106 }
00107 
00108 
00109 // unchecked!
00110 void SiPixelArrayBuffer::set_adc( int row, int col, int adc) 
00111 {
00112   pixel_vec[index(row,col)] = adc;
00113 }
00114 
00115 
00116 void SiPixelArrayBuffer::set_adc( const SiPixelCluster::PixelPos& pix, int adc)
00117 {
00118   pixel_vec[index(pix)] = adc;
00119 }
00120 
00121 
00122 #endif