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: AliMpMotifTypePadIterator.cxx,v 1.6 2006/05/24 13:58:41 ivana Exp $
20 // Class AliMpMotifTypePadIterator
21 // -------------------------------
22 // Class, which defines an iterator over the pads of a given motif type
23 // Included in AliRoot: 2003/05/02
24 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26 #include "AliMpMotifTypePadIterator.h"
27 #include "AliMpMotifType.h"
30 ClassImp(AliMpMotifTypePadIterator)
33 //______________________________________________________________________________
34 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator():
37 fCurrentPosition(AliMpIntPair::Invalid())
39 /// Default constructor, set the current position to "invalid"
42 //______________________________________________________________________________
43 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(
44 const AliMpMotifType* motifType)
45 : AliMpVPadIterator(),
46 fMotifType(motifType),
47 fCurrentPosition(AliMpIntPair::Invalid())
49 /// Standard constructor, let *this to invalid position
52 //______________________________________________________________________________
53 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(
54 const AliMpMotifTypePadIterator& right)
55 : AliMpVPadIterator(right),
56 fMotifType(right.fMotifType),
57 fCurrentPosition(right.fCurrentPosition)
63 //______________________________________________________________________________
64 AliMpMotifTypePadIterator::~AliMpMotifTypePadIterator()
71 //______________________________________________________________________________
72 AliMpMotifTypePadIterator&
73 AliMpMotifTypePadIterator::operator = (const AliMpMotifTypePadIterator& right)
75 /// Assignment operator. \n
76 /// If the right hand iterator isn't of good type
77 /// the current operator is invalidated
79 // check assignment to self
80 if (this == &right) return *this;
82 // base class assignment
83 AliMpVPadIterator::operator=(right);
85 fMotifType = right.fMotifType;
86 fCurrentPosition = right.fCurrentPosition;
95 //______________________________________________________________________________
97 AliMpMotifTypePadIterator::FindFirstPadInLine(AliMpIntPair indices) const
99 /// Find the indices of the first pad in the same line
100 /// as the \a indices, and in column, at least equal, to the
101 /// one of \a indices
103 if (!fMotifType) return AliMpIntPair::Invalid();
105 while (indices.GetFirst() < fMotifType->GetNofPadsX()) {
106 if (fMotifType->HasPad(indices)) return indices;
107 indices += AliMpIntPair(1,0);
109 return AliMpIntPair::Invalid();
112 //______________________________________________________________________________
113 Bool_t AliMpMotifTypePadIterator::IsValid() const
115 /// Is the iterator in a valid position?
117 return fMotifType!=0 && fCurrentPosition.IsValid();
124 //______________________________________________________________________________
125 void AliMpMotifTypePadIterator::First()
127 /// Reset the iterator, so that it points to the first available
128 /// pad in the motif type
134 fCurrentPosition = AliMpIntPair(0,0);
135 if (fMotifType->HasPad(fCurrentPosition)) return;
138 // if (0,0) is not available
139 // place itself to the first avalable motif after (0,0) (if exists)
146 //______________________________________________________________________________
147 void AliMpMotifTypePadIterator::Next()
149 /// Move the iterator to the next valid pad.
151 //if (!IsValid()) return *this;
152 if (!IsValid()) return;
154 while (fCurrentPosition.GetSecond() < fMotifType->GetNofPadsY()){
156 = FindFirstPadInLine(fCurrentPosition + AliMpIntPair(1,0));
157 if (nextTry.IsValid()){
158 fCurrentPosition = nextTry;
161 fCurrentPosition.SetFirst(-1);
162 fCurrentPosition.SetSecond(fCurrentPosition.GetSecond()+1);
165 // if the loop is finished, there's not available pads at all...
170 //______________________________________________________________________________
171 Bool_t AliMpMotifTypePadIterator::IsDone() const
173 /// Is the iterator in the end ?
178 //______________________________________________________________________________
179 AliMpPad AliMpMotifTypePadIterator::CurrentItem() const
181 /// Return current pad.
184 return AliMpPad::Invalid();
186 return AliMpPad(AliMpIntPair::Invalid(),
187 fCurrentPosition,TVector2(),TVector2());
190 //______________________________________________________________________________
191 void AliMpMotifTypePadIterator::Invalidate()
193 /// Let the iterator point to the invalid position
195 fCurrentPosition = AliMpIntPair::Invalid();