]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSectorAreaVPadIterator.cxx
Input list for testSlatPads.C macro (Laurent)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSectorAreaVPadIterator.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 // $Id$
17 // $MpId: AliMpSectorAreaVPadIterator.cxx,v 1.8 2006/05/24 13:58:46 ivana Exp $
18 // Category: sector
19 //
20 // Class AliMpSectorAreaVPadIterator
21 // ---------------------------------
22 // Class, which defines an iterator over the pads 
23 // inside a given area in a sector in vertical direction.
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26
27 #include "AliMpSectorAreaVPadIterator.h"
28 #include "AliMpSectorSegmentation.h"
29 #include "AliMpConstants.h"
30
31 #include <Riostream.h>
32
33 /// \cond CLASSIMP
34 ClassImp(AliMpSectorAreaVPadIterator)
35 /// \endcond
36
37 //______________________________________________________________________________
38 AliMpSectorAreaVPadIterator::AliMpSectorAreaVPadIterator(
39                                 const AliMpSectorSegmentation* segmentation,
40                                 const AliMpArea& area) 
41  : AliMpVPadIterator(),
42    fkSegmentation(segmentation),
43    fkArea(area),
44    fCurrentPad(AliMpPad::Invalid()),
45    fCurrentColumnPosition(0.)
46 {
47 /// Standard constructor, start in invalid position
48 }
49
50 //______________________________________________________________________________
51 AliMpSectorAreaVPadIterator::AliMpSectorAreaVPadIterator(
52                                 const AliMpSectorAreaVPadIterator& right)
53   : AliMpVPadIterator(right),
54     fkSegmentation(0),
55     fkArea(AliMpArea()),
56     fCurrentPad(AliMpPad::Invalid()),
57     fCurrentColumnPosition(0.)
58 {
59 /// Copy constructor
60  
61   *this = right;
62 }
63
64 //______________________________________________________________________________
65 AliMpSectorAreaVPadIterator::AliMpSectorAreaVPadIterator()
66  : AliMpVPadIterator(),
67    fkSegmentation(0),
68    fkArea(AliMpArea()),
69    fCurrentPad(AliMpPad::Invalid()),
70    fCurrentColumnPosition(0.)
71 {
72 /// Default constructor.
73 }
74
75 //______________________________________________________________________________
76 AliMpSectorAreaVPadIterator::~AliMpSectorAreaVPadIterator()
77 {
78 /// Destructor
79 }
80
81 //
82 // operators
83 //
84
85 //______________________________________________________________________________
86 AliMpSectorAreaVPadIterator& 
87 AliMpSectorAreaVPadIterator::operator = (const AliMpSectorAreaVPadIterator& right)
88 {
89 /// Assignment operator
90
91   // check assignment to self
92   if (this == &right) return *this;
93
94   // base class assignment
95   AliMpVPadIterator::operator=(right);
96
97   fkSegmentation = right.fkSegmentation;
98   fkArea         = right.fkArea;
99   fCurrentPad    = right.fCurrentPad;
100   fCurrentColumnPosition = right.fCurrentColumnPosition;
101
102   return *this;
103
104
105 // 
106 // private methods
107 //
108
109 //______________________________________________________________________________
110 Bool_t AliMpSectorAreaVPadIterator::IsValid() const
111 {
112 /// Is the iterator in a valid position?
113
114   return fCurrentPad.IsValid() ;
115 }
116
117 //______________________________________________________________________________
118 void AliMpSectorAreaVPadIterator::MoveRight()
119 {
120 /// Increase the current row position and searches the first valid pad.
121
122   Double_t step = 2.* fkSegmentation->GetMinPadDimensions().X();
123
124   while ( !fCurrentPad.IsValid() && 
125           fCurrentColumnPosition + step < fkArea.RightBorder())
126   {
127     fCurrentColumnPosition += step;
128     TVector2 position = TVector2(fCurrentColumnPosition, fkArea.DownBorder());
129     
130     fCurrentPad = fkSegmentation->PadByDirection(position, fkArea.UpBorder());
131   } 
132 }
133
134 //
135 // public methods
136 //
137
138 //______________________________________________________________________________
139 void AliMpSectorAreaVPadIterator::First()
140 {
141 /// Reset the iterator, so that it points to the first available
142 /// pad in the area
143
144   if (!fkSegmentation) {
145     AliFatal("Segmentation is not defined");
146     return;
147   }  
148
149   // Start position = left down corner of the area
150   //
151   fCurrentColumnPosition = fkArea.LeftBorder();
152   TVector2 position(fkArea.LeftDownCorner()); 
153   
154   fCurrentPad = fkSegmentation->PadByDirection(position, fkArea.UpBorder());
155   
156   MoveRight();
157
158   // Set the column position to the center of pad
159   //
160   if (fCurrentPad.IsValid()) fCurrentColumnPosition = fCurrentPad.Position().X();
161 }
162
163 //______________________________________________________________________________
164 void AliMpSectorAreaVPadIterator::Next()
165 {
166 /// Move the iterator to the next valid pad.
167
168   if (!IsValid()) return;
169   
170   // Start position = up board of current pad + little step
171   //
172   TVector2 position 
173     = fCurrentPad.Position() 
174     + TVector2(0., fCurrentPad.Dimensions().Y() + AliMpConstants::LengthStep());
175
176   fCurrentPad = fkSegmentation->PadByDirection(position, fkArea.UpBorder());  
177   
178   if (fCurrentPad.IsValid()) return;
179
180   MoveRight();
181 }
182
183 //______________________________________________________________________________
184 Bool_t AliMpSectorAreaVPadIterator::IsDone() const
185 {
186 /// Is the iterator in the end ?
187  
188   return !IsValid();
189 }
190
191 //______________________________________________________________________________
192 AliMpPad AliMpSectorAreaVPadIterator::CurrentItem () const 
193 {
194 /// Return current pad.
195
196   return fCurrentPad;
197 }
198 //______________________________________________________________________________
199 void AliMpSectorAreaVPadIterator::Invalidate()
200 {
201 /// Let the iterator point to the invalid position
202  
203   fCurrentPad = AliMpPad::Invalid();
204   fCurrentColumnPosition = 0;
205 }
206
207
208