1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpSectorAreaHPadIterator.cxx,v 1.7 2006/05/24 13:58:46 ivana Exp $
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
27 #include "AliMpSectorAreaHPadIterator.h"
28 #include "AliMpSectorSegmentation.h"
29 #include "AliMpConstants.h"
31 #include <Riostream.h>
34 ClassImp(AliMpSectorAreaHPadIterator)
37 //______________________________________________________________________________
38 AliMpSectorAreaHPadIterator::AliMpSectorAreaHPadIterator(
39 const AliMpSectorSegmentation* segmentation,
40 const AliMpArea& area)
41 : AliMpVPadIterator(),
42 fkSegmentation(segmentation),
44 fCurrentPad(AliMpPad::Invalid()),
45 fCurrentRowPosition(0.)
47 /// Standard constructor, start in invalid position
50 //______________________________________________________________________________
51 AliMpSectorAreaHPadIterator::AliMpSectorAreaHPadIterator(
52 const AliMpSectorAreaHPadIterator& right)
53 : AliMpVPadIterator(right),
56 fCurrentPad(AliMpPad::Invalid()),
57 fCurrentRowPosition(0.)
64 //______________________________________________________________________________
65 AliMpSectorAreaHPadIterator::AliMpSectorAreaHPadIterator()
66 : AliMpVPadIterator(),
69 fCurrentPad(AliMpPad::Invalid()),
70 fCurrentRowPosition(0.)
72 /// Default constructor.
75 //______________________________________________________________________________
76 AliMpSectorAreaHPadIterator::~AliMpSectorAreaHPadIterator()
85 //______________________________________________________________________________
86 AliMpSectorAreaHPadIterator&
87 AliMpSectorAreaHPadIterator::operator = (const AliMpSectorAreaHPadIterator& right)
89 /// Assignment operator
91 // check assignment to self
92 if (this == &right) return *this;
94 // base class assignment
95 AliMpVPadIterator::operator=(right);
97 fkSegmentation = right.fkSegmentation;
98 fkArea = right.fkArea;
99 fCurrentPad = right.fCurrentPad;
100 fCurrentRowPosition = right.fCurrentRowPosition;
109 //______________________________________________________________________________
110 Bool_t AliMpSectorAreaHPadIterator::IsValid() const
112 /// Is the iterator in a valid position?
114 return fCurrentPad.IsValid() ;
117 //______________________________________________________________________________
118 void AliMpSectorAreaHPadIterator::MoveUp()
120 /// Increase the current row position and searches the first valid pad.
122 Double_t dy = fkSegmentation->GetMinPadDimensions().Y();
124 while ( !fCurrentPad.IsValid() &&
125 fCurrentRowPosition + dy < fkArea.UpBorder())
127 fCurrentRowPosition += 2.*dy;
128 TVector2 position = TVector2(fkArea.LeftBorder(), fCurrentRowPosition);
130 fCurrentPad = fkSegmentation->PadByDirection(position, fkArea.RightBorder());
138 //______________________________________________________________________________
139 void AliMpSectorAreaHPadIterator::First()
141 /// Reset the iterator, so that it points to the first available
144 if (!fkSegmentation) {
145 Fatal("First", "Segmentation is not defined");
149 // Start position = left down corner of the area
151 fCurrentRowPosition = fkArea.DownBorder();
152 TVector2 position(fkArea.LeftDownCorner());
154 fCurrentPad = fkSegmentation->PadByDirection(position, fkArea.RightBorder());
158 // Set the row position to the center of pad
160 if (fCurrentPad.IsValid()) fCurrentRowPosition = fCurrentPad.Position().Y();
163 //______________________________________________________________________________
164 void AliMpSectorAreaHPadIterator::Next()
166 /// Move the iterator to the next valid pad.
168 if (!IsValid()) return;
170 // Start position = right board of current pad + little step
173 = fCurrentPad.Position()
174 + TVector2(fCurrentPad.Dimensions().X() + AliMpConstants::LengthStep(), 0.);
176 fCurrentPad = fkSegmentation->PadByDirection(position, fkArea.RightBorder());
178 if (fCurrentPad.IsValid()) return;
183 //______________________________________________________________________________
184 Bool_t AliMpSectorAreaHPadIterator::IsDone() const
186 /// Is the iterator in the end ?
191 //______________________________________________________________________________
192 AliMpPad AliMpSectorAreaHPadIterator::CurrentItem () const
194 /// Return current pad.
198 //______________________________________________________________________________
199 void AliMpSectorAreaHPadIterator::Invalidate()
201 /// Let the iterator point to the invalid position
203 fCurrentPad = AliMpPad::Invalid();
204 fCurrentRowPosition = 0;