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 //-----------------------------------------------------------------------------
21 // Class AliMpMotifTypePadIterator
22 // -------------------------------
23 // Class, which defines an iterator over the pads of a given motif type
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26 //-----------------------------------------------------------------------------
28 #include "AliMpMotifTypePadIterator.h"
29 #include "AliMpMotifType.h"
32 ClassImp(AliMpMotifTypePadIterator)
35 //______________________________________________________________________________
36 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator():
39 fCurrentPosition(AliMpIntPair::Invalid())
41 /// Default constructor, set the current position to "invalid"
44 //______________________________________________________________________________
45 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(
46 const AliMpMotifType* motifType)
47 : AliMpVPadIterator(),
48 fkMotifType(motifType),
49 fCurrentPosition(AliMpIntPair::Invalid())
51 /// Standard constructor, let *this to invalid position
54 //______________________________________________________________________________
55 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(
56 const AliMpMotifTypePadIterator& right)
57 : AliMpVPadIterator(right),
58 fkMotifType(right.fkMotifType),
59 fCurrentPosition(right.fCurrentPosition)
65 //______________________________________________________________________________
66 AliMpMotifTypePadIterator::~AliMpMotifTypePadIterator()
73 //______________________________________________________________________________
74 AliMpMotifTypePadIterator&
75 AliMpMotifTypePadIterator::operator = (const AliMpMotifTypePadIterator& right)
77 /// Assignment operator. \n
78 /// If the right hand iterator isn't of good type
79 /// the current operator is invalidated
81 // check assignment to self
82 if (this == &right) return *this;
84 // base class assignment
85 AliMpVPadIterator::operator=(right);
87 fkMotifType = right.fkMotifType;
88 fCurrentPosition = right.fCurrentPosition;
97 //______________________________________________________________________________
99 AliMpMotifTypePadIterator::FindFirstPadInLine(AliMpIntPair indices) const
101 /// Find the indices of the first pad in the same line
102 /// as the \a indices, and in column, at least equal, to the
103 /// one of \a indices
105 if (!fkMotifType) return AliMpIntPair::Invalid();
107 while (indices.GetFirst() < fkMotifType->GetNofPadsX()) {
108 if (fkMotifType->HasPad(indices)) return indices;
109 indices += AliMpIntPair(1,0);
111 return AliMpIntPair::Invalid();
114 //______________________________________________________________________________
115 Bool_t AliMpMotifTypePadIterator::IsValid() const
117 /// Is the iterator in a valid position?
119 return fkMotifType!=0 && fCurrentPosition.IsValid();
126 //______________________________________________________________________________
127 void AliMpMotifTypePadIterator::First()
129 /// Reset the iterator, so that it points to the first available
130 /// pad in the motif type
136 fCurrentPosition = AliMpIntPair(0,0);
137 if (fkMotifType->HasPad(fCurrentPosition)) return;
140 // if (0,0) is not available
141 // place itself to the first avalable motif after (0,0) (if exists)
148 //______________________________________________________________________________
149 void AliMpMotifTypePadIterator::Next()
151 /// Move the iterator to the next valid pad.
153 //if (!IsValid()) return *this;
154 if (!IsValid()) return;
156 while (fCurrentPosition.GetSecond() < fkMotifType->GetNofPadsY()){
158 = FindFirstPadInLine(fCurrentPosition + AliMpIntPair(1,0));
159 if (nextTry.IsValid()){
160 fCurrentPosition = nextTry;
163 fCurrentPosition.SetFirst(-1);
164 fCurrentPosition.SetSecond(fCurrentPosition.GetSecond()+1);
167 // if the loop is finished, there's not available pads at all...
172 //______________________________________________________________________________
173 Bool_t AliMpMotifTypePadIterator::IsDone() const
175 /// Is the iterator in the end ?
180 //______________________________________________________________________________
181 AliMpPad AliMpMotifTypePadIterator::CurrentItem() const
183 /// Return current pad.
186 return AliMpPad::Invalid();
188 return AliMpPad(AliMpIntPair::Invalid(),
189 fCurrentPosition,TVector2(),TVector2());
192 //______________________________________________________________________________
193 void AliMpMotifTypePadIterator::Invalidate()
195 /// Let the iterator point to the invalid position
197 fCurrentPosition = AliMpIntPair::Invalid();