CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloNavigator.h
Go to the documentation of this file.
1 #ifndef RECOCALOTOOLS_NAVIGATION_CALONAVIGATOR_H
2 #define RECOCALOTOOLS_NAVIGATION_CALONAVIGATOR_H 1
3 
6 
7 template <class T, class TOPO=CaloSubdetectorTopology>
8 class CaloNavigator GCC11_FINAL {
9  public:
10 
11  CaloNavigator(const T& home, const TOPO * topology) : myTopology_(topology)
12  {
13  setHome(home);
14  }
15 
17  inline void setHome(const T& startingPoint);
18 
20  inline void setTopology(const TOPO *);
21 
23  const TOPO * getTopology() const
24  {
25  return myTopology_;
26  }
27 
29  inline void home() const ;
30 
32  T pos() const { return currentPoint_; }
33 
35  T operator*() const { return currentPoint_; }
36 
38  T north() const
39  {
40  currentPoint_=myTopology_->goNorth(currentPoint_);
41  return currentPoint_;
42  } ;
43 
45  T south() const
46  {
47  currentPoint_=myTopology_->goSouth(currentPoint_);
48  return currentPoint_;
49  } ;
50 
52  T east() const
53  {
54  currentPoint_=myTopology_->goEast(currentPoint_);
55  return currentPoint_;
56  } ;
57 
59  T west() const
60  {
61  currentPoint_=myTopology_->goWest(currentPoint_);
62  return currentPoint_;
63  } ;
64 
66  T up() const
67  {
68  currentPoint_=myTopology_->goUp(currentPoint_);
69  return currentPoint_;
70  } ;
71 
73  T down() const
74  {
75  currentPoint_=myTopology_->goDown(currentPoint_);
76  return currentPoint_;
77  } ;
78 
80  T offsetBy(int deltaX, int deltaY) const
81  {
82  for(int x=0; x < abs(deltaX) && currentPoint_ != T(0); x++)
83  {
84  if(deltaX > 0) east();
85  else west();
86  }
87 
88  for(int y=0; y < abs(deltaY) && currentPoint_ != T(0); y++)
89  {
90  if(deltaY > 0) north();
91  else south();
92  }
93 
94  return currentPoint_;
95 
96  }
97 
98  protected:
99 
100  const TOPO * myTopology_;
101  mutable T startingPoint_, currentPoint_;
102 };
103 
104 template <class T, class TOPO>
105 inline
106 void CaloNavigator<T,TOPO>::setHome(const T& startingPoint)
107 {
108  startingPoint_=startingPoint;
109  home();
110 }
111 
112 template <class T, class TOPO>
113 inline
114 void CaloNavigator<T,TOPO>::home() const
115 {
116  currentPoint_=startingPoint_;
117 }
118 
119 template <class T, class TOPO>
120 inline
122 {
123  if (myTopology_ == 0)
124  myTopology_=topology;
125  else
126  return;
127 }
128 
129 #endif
T operator*() const
get the current position
Definition: CaloNavigator.h:35
T pos() const
get the current position
Definition: CaloNavigator.h:32
CaloTopology const * topology(0)
T down() const
move the navigator west
Definition: CaloNavigator.h:73
const TOPO * getTopology() const
set the starting position
Definition: CaloNavigator.h:23
T up() const
move the navigator west
Definition: CaloNavigator.h:66
CaloNavigator(const T &home, const TOPO *topology)
Definition: CaloNavigator.h:11
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T east() const
move the navigator east
Definition: CaloNavigator.h:52
T west() const
move the navigator west
Definition: CaloNavigator.h:59
const TOPO * myTopology_
void setTopology(CaloTopology const *)
T offsetBy(int deltaX, int deltaY) const
Free movement of arbitray steps.
Definition: CaloNavigator.h:80
T north() const
move the navigator north
Definition: CaloNavigator.h:38
Definition: DDAxes.h:10
long double T
T south() const
move the navigator south
Definition: CaloNavigator.h:45
Unlimited (trivial) bounds.