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 #include "FWCore/Utilities/interface/GCC11Compatibility.h"
00006
00007 template <class T, class TOPO=CaloSubdetectorTopology>
00008 class CaloNavigator GCC11_FINAL {
00009 public:
00010
00011 CaloNavigator(const T& home, const TOPO * topology) : myTopology_(topology)
00012 {
00013 setHome(home);
00014 }
00015
00017 inline void setHome(const T& startingPoint);
00018
00020 inline void setTopology(const TOPO *);
00021
00023 const TOPO * getTopology() const
00024 {
00025 return myTopology_;
00026 }
00027
00029 inline void home() const ;
00030
00032 T pos() const { return currentPoint_; }
00033
00035 T operator*() const { return currentPoint_; }
00036
00038 T north() const
00039 {
00040 currentPoint_=myTopology_->goNorth(currentPoint_);
00041 return currentPoint_;
00042 } ;
00043
00045 T south() const
00046 {
00047 currentPoint_=myTopology_->goSouth(currentPoint_);
00048 return currentPoint_;
00049 } ;
00050
00052 T east() const
00053 {
00054 currentPoint_=myTopology_->goEast(currentPoint_);
00055 return currentPoint_;
00056 } ;
00057
00059 T west() const
00060 {
00061 currentPoint_=myTopology_->goWest(currentPoint_);
00062 return currentPoint_;
00063 } ;
00064
00066 T up() const
00067 {
00068 currentPoint_=myTopology_->goUp(currentPoint_);
00069 return currentPoint_;
00070 } ;
00071
00073 T down() const
00074 {
00075 currentPoint_=myTopology_->goDown(currentPoint_);
00076 return currentPoint_;
00077 } ;
00078
00080 T offsetBy(int deltaX, int deltaY) const
00081 {
00082 for(int x=0; x < abs(deltaX) && currentPoint_ != T(0); x++)
00083 {
00084 if(deltaX > 0) east();
00085 else west();
00086 }
00087
00088 for(int y=0; y < abs(deltaY) && currentPoint_ != T(0); y++)
00089 {
00090 if(deltaY > 0) north();
00091 else south();
00092 }
00093
00094 return currentPoint_;
00095
00096 }
00097
00098 protected:
00099
00100 const TOPO * myTopology_;
00101 mutable T startingPoint_, currentPoint_;
00102 };
00103
00104 template <class T, class TOPO>
00105 inline
00106 void CaloNavigator<T,TOPO>::setHome(const T& startingPoint)
00107 {
00108 startingPoint_=startingPoint;
00109 home();
00110 }
00111
00112 template <class T, class TOPO>
00113 inline
00114 void CaloNavigator<T,TOPO>::home() const
00115 {
00116 currentPoint_=startingPoint_;
00117 }
00118
00119 template <class T, class TOPO>
00120 inline
00121 void CaloNavigator<T,TOPO>::setTopology(const TOPO * topology)
00122 {
00123 if (myTopology_ == 0)
00124 myTopology_=topology;
00125 else
00126 return;
00127 }
00128
00129 #endif