CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/RecoCaloTools/Navigation/interface/CaloNavigator.h

Go to the documentation of this file.
00001 #ifndef RECOCALOTOOLS_NAVIGATION_CALONAVIGATOR_H
00002 #define RECOCALOTOOLS_NAVIGATION_CALONAVIGATOR_H 1
00003 
00004 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
00005 
00006 template <class T>
00007 class CaloNavigator {
00008  public:
00009 
00011   CaloNavigator() : myTopology_(0)
00012     {
00013     }
00014 
00015   CaloNavigator(const T& home) : myTopology_(0)
00016     {
00017       setHome(home);
00018     };
00019 
00020 
00021   CaloNavigator(const T& home, const CaloSubdetectorTopology* topology) : myTopology_(topology) 
00022     {
00023       setHome(home);
00024     };
00025 
00027   virtual ~CaloNavigator(){};
00028 
00030   void setHome(const T& startingPoint);
00031 
00033   void setTopology(const CaloSubdetectorTopology*);
00034 
00036   const CaloSubdetectorTopology* getTopology() const
00037     {
00038       return myTopology_;
00039     }
00040 
00042   void home() const ;
00043 
00045   T pos() const { return currentPoint_; }
00046 
00048   T operator*() const { return currentPoint_; } 
00049 
00051   virtual T north() const 
00052     { 
00053       if ((myTopology_->north(currentPoint_)).size()==1)
00054         currentPoint_=(myTopology_->north(currentPoint_))[0];
00055       else
00056         currentPoint_=T(0);
00057       return currentPoint_;
00058     } ;
00059 
00061   virtual T south()  const 
00062     { 
00063       if ((myTopology_->south(currentPoint_)).size()==1)
00064         currentPoint_=(myTopology_->south(currentPoint_))[0];
00065       else
00066         currentPoint_=T(0);
00067       return currentPoint_;
00068     } ;
00069 
00071   virtual T east() const
00072     { 
00073       if ((myTopology_->east(currentPoint_)).size()==1)
00074         currentPoint_=(myTopology_->east(currentPoint_))[0];
00075       else
00076         currentPoint_=T(0);
00077       return currentPoint_;
00078     } ;
00079 
00081   virtual T west() const
00082     { 
00083       if ((myTopology_->west(currentPoint_)).size()==1)
00084         currentPoint_=(myTopology_->west(currentPoint_))[0];
00085       else
00086         currentPoint_=T(0);
00087       return currentPoint_;
00088     } ;
00089 
00091   virtual T up() const
00092     { 
00093       if ((myTopology_->up(currentPoint_)).size()==1)
00094         currentPoint_=(myTopology_->up(currentPoint_))[0];
00095       else
00096         currentPoint_=T(0);
00097       return currentPoint_;
00098     } ;
00099 
00101   virtual T down() const
00102     { 
00103       if ((myTopology_->down(currentPoint_)).size()==1)
00104         currentPoint_=(myTopology_->down(currentPoint_))[0];
00105       else
00106         currentPoint_=T(0);
00107       return currentPoint_;
00108     } ;
00109 
00111   virtual T offsetBy(int deltaX, int deltaY) const
00112     {
00113       for(int x=0; x < abs(deltaX) && currentPoint_ != T(0); x++)
00114         {
00115           if(deltaX > 0) east();
00116           else           west();
00117         }
00118 
00119       for(int y=0; y < abs(deltaY) && currentPoint_ != T(0); y++)
00120         {
00121           if(deltaY > 0) north();
00122           else           south();
00123         }
00124 
00125       return currentPoint_;
00126 
00127     }
00128 
00129  protected:
00130   
00131   const CaloSubdetectorTopology* myTopology_;
00132   mutable T startingPoint_, currentPoint_;
00133 };
00134 
00135 template <class T>
00136 void CaloNavigator<T>::setHome(const T& startingPoint)
00137 {
00138   startingPoint_=startingPoint;
00139   home();
00140 }
00141 
00142 template <class T>
00143 void CaloNavigator<T>::home() const
00144 {
00145   currentPoint_=startingPoint_;
00146 }
00147 
00148 template <class T>
00149 void CaloNavigator<T>::setTopology(const CaloSubdetectorTopology* topology) 
00150 {
00151   if (myTopology_ == 0)
00152     myTopology_=topology;
00153   else
00154     return;
00155 }
00156 
00157 #endif