]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSectorAreaHPadIterator.cxx
New class - the factory for building mapping segmentations
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSectorAreaHPadIterator.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: AliMpSectorAreaHPadIterator.cxx,v 1.5 2005/08/26 15:43:36 ivana Exp $
18 // Category: sector
19 //
20 // Class AliMpSectorAreaHPadIterator
21 // ---------------------------------
22 // Class, which defines an iterator over the pads 
23 // inside a given area in a sector in horizontal direction.
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26
27 #include <Riostream.h>
28
29 #include "AliMpSectorAreaHPadIterator.h"
30 #include "AliMpSectorSegmentation.h"
31 #include "AliMpConstants.h"
32
33 ClassImp(AliMpSectorAreaHPadIterator)
34
35 //______________________________________________________________________________
36 AliMpSectorAreaHPadIterator::AliMpSectorAreaHPadIterator(
37                                 const AliMpSectorSegmentation* segmentation,
38                                 const AliMpArea& area) 
39  : AliMpVPadIterator(),
40    fkSegmentation(segmentation),
41    fkArea(area),
42    fCurrentPad(AliMpPad::Invalid()),
43    fCurrentRowPosition(0.)
44 {
45 /// Standard constructor, start in invalid position
46 }
47
48 //______________________________________________________________________________
49 AliMpSectorAreaHPadIterator::AliMpSectorAreaHPadIterator(
50                                 const AliMpSectorAreaHPadIterator& right)
51   : AliMpVPadIterator(right)
52 {
53 /// Protected copy constructor (not provided)
54  
55   Fatal("Copy constructor", "Not implemented");
56 }
57
58 //______________________________________________________________________________
59 AliMpSectorAreaHPadIterator::AliMpSectorAreaHPadIterator()
60  : AliMpVPadIterator(),
61    fkSegmentation(0),
62    fkArea(AliMpArea()),
63    fCurrentPad(AliMpPad::Invalid()),
64    fCurrentRowPosition(0.)
65 {
66 /// Default constructor.
67 }
68
69 //______________________________________________________________________________
70 AliMpSectorAreaHPadIterator::~AliMpSectorAreaHPadIterator()
71 {
72 /// Destructor
73 }
74
75 //
76 // operators
77 //
78
79 //______________________________________________________________________________
80 AliMpSectorAreaHPadIterator& 
81 AliMpSectorAreaHPadIterator::operator = (const AliMpSectorAreaHPadIterator& right)
82 {
83 /// Assignment operator
84
85   // check assignment to self
86   if (this == &right) return *this;
87
88   // base class assignment
89   AliMpVPadIterator::operator=(right);
90
91   fkSegmentation = right.fkSegmentation;
92   fkArea         = right.fkArea;
93   fCurrentPad    = right.fCurrentPad;
94   fCurrentRowPosition = right.fCurrentRowPosition;
95
96   return *this;
97
98
99 // 
100 // private methods
101 //
102
103 //______________________________________________________________________________
104 Bool_t AliMpSectorAreaHPadIterator::IsValid() const
105 {
106 /// Is the iterator in a valid position?
107
108   return fCurrentPad.IsValid() ;
109 }
110
111 //______________________________________________________________________________
112 void AliMpSectorAreaHPadIterator::MoveUp()
113 {
114 /// Increase the current row position and searches the first valid pad.
115
116   Double_t step = 2.* fkSegmentation->GetMinPadDimensions().Y();
117
118   while ( !fCurrentPad.IsValid() && 
119           fCurrentRowPosition + step < fkArea.UpBorder())
120   {
121     //cout << "#########  Move up ##########" << endl;
122   
123     fCurrentRowPosition += step;
124     TVector2 position = TVector2(fkArea.LeftBorder(), fCurrentRowPosition);
125     
126     fCurrentPad = fkSegmentation->PadByDirection(position, fkArea.RightBorder());
127   } 
128 }
129
130 //
131 // public methods
132 //
133
134 //______________________________________________________________________________
135 void AliMpSectorAreaHPadIterator::First()
136 {
137 /// Reset the iterator, so that it points to the first available
138 /// pad in the area
139
140   if (!fkSegmentation) {
141     Fatal("First", "Segmentation is not defined");
142     return;
143   }  
144
145   // Start position = left down corner of the area
146   //
147   fCurrentRowPosition = fkArea.DownBorder();
148   TVector2 position(fkArea.LeftDownCorner()); 
149   
150   fCurrentPad = fkSegmentation->PadByDirection(position, fkArea.RightBorder());
151
152   MoveUp();
153   
154   // Set the row position to the center of pad
155   //
156   if (fCurrentPad.IsValid()) fCurrentRowPosition = fCurrentPad.Position().Y();
157 }
158
159 //______________________________________________________________________________
160 void AliMpSectorAreaHPadIterator::Next()
161 {
162 /// Move the iterator to the next valid pad.
163
164   if (!IsValid()) return;
165   
166   // Start position = right board of current pad + little step
167   //
168   TVector2 position 
169     = fCurrentPad.Position() 
170     + TVector2(fCurrentPad.Dimensions().X() + AliMpConstants::LengthStep(), 0.);
171
172   fCurrentPad = fkSegmentation->PadByDirection(position, fkArea.RightBorder());  
173
174   if (fCurrentPad.IsValid()) return;
175
176   MoveUp();
177 }
178
179 //______________________________________________________________________________
180 Bool_t AliMpSectorAreaHPadIterator::IsDone() const
181 {
182 /// Is the iterator in the end ?
183  
184   return !IsValid();
185 }
186
187 //______________________________________________________________________________
188 AliMpPad AliMpSectorAreaHPadIterator::CurrentItem () const 
189 {
190 /// Return current pad.
191
192   return fCurrentPad;
193 }
194 //______________________________________________________________________________
195 void AliMpSectorAreaHPadIterator::Invalidate()
196 {
197 /// Let the iterator point to the invalid position
198
199   fCurrentPad = AliMpPad::Invalid();
200   fCurrentRowPosition = 0;
201 }
202
203
204