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.5 2005/08/26 15:43:36 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"
29 ClassImp(AliMpMotifTypePadIterator)
31 //______________________________________________________________________________
32 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator():
35 fCurrentPosition(AliMpIntPair::Invalid())
37 /// Default constructor, set the current position to "invalid"
40 //______________________________________________________________________________
41 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(
42 const AliMpMotifType* motifType)
43 : AliMpVPadIterator(),
44 fMotifType(motifType),
45 fCurrentPosition(AliMpIntPair::Invalid())
47 /// Standard constructor, let *this to invalid position
50 //______________________________________________________________________________
51 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(
52 const AliMpMotifTypePadIterator& right)
53 : AliMpVPadIterator(right),
54 fMotifType(right.fMotifType),
55 fCurrentPosition(right.fCurrentPosition)
61 //______________________________________________________________________________
62 AliMpMotifTypePadIterator::~AliMpMotifTypePadIterator()
69 //______________________________________________________________________________
70 AliMpMotifTypePadIterator&
71 AliMpMotifTypePadIterator::operator = (const AliMpMotifTypePadIterator& right)
73 /// Assignment operator. \n
74 /// If the right hand iterator isn't of good type
75 /// the current operator is invalidated
77 // check assignment to self
78 if (this == &right) return *this;
80 // base class assignment
81 AliMpVPadIterator::operator=(right);
83 fMotifType = right.fMotifType;
84 fCurrentPosition = right.fCurrentPosition;
93 //______________________________________________________________________________
95 AliMpMotifTypePadIterator::FindFirstPadInLine(AliMpIntPair indices) const
97 /// Find the indices of the first pad in the same line
98 /// as the <indices>, and in column, at least equal, to the
101 if (!fMotifType) return AliMpIntPair::Invalid();
103 while (indices.GetFirst() < fMotifType->GetNofPadsX()) {
104 if (fMotifType->HasPad(indices)) return indices;
105 indices += AliMpIntPair(1,0);
107 return AliMpIntPair::Invalid();
110 //______________________________________________________________________________
111 Bool_t AliMpMotifTypePadIterator::IsValid() const
113 /// Is the iterator in a valid position?
115 return fMotifType!=0 && fCurrentPosition.IsValid();
122 //______________________________________________________________________________
123 void AliMpMotifTypePadIterator::First()
125 /// Reset the iterator, so that it points to the first available
126 /// pad in the motif type
132 fCurrentPosition = AliMpIntPair(0,0);
133 if (fMotifType->HasPad(fCurrentPosition)) return;
136 // if (0,0) is not available
137 // place itself to the first avalable motif after (0,0) (if exists)
144 //______________________________________________________________________________
145 void AliMpMotifTypePadIterator::Next()
147 /// Move the iterator to the next valid pad.
149 //if (!IsValid()) return *this;
150 if (!IsValid()) return;
152 while (fCurrentPosition.GetSecond() < fMotifType->GetNofPadsY()){
154 = FindFirstPadInLine(fCurrentPosition + AliMpIntPair(1,0));
155 if (nextTry.IsValid()){
156 fCurrentPosition = nextTry;
159 fCurrentPosition.SetFirst(-1);
160 fCurrentPosition.SetSecond(fCurrentPosition.GetSecond()+1);
163 // if the loop is finished, there's not available pads at all...
168 //______________________________________________________________________________
169 Bool_t AliMpMotifTypePadIterator::IsDone() const
171 /// Is the iterator in the end ?
176 //______________________________________________________________________________
177 AliMpPad AliMpMotifTypePadIterator::CurrentItem() const
179 /// Return current pad.
182 return AliMpPad::Invalid();
184 return AliMpPad(AliMpIntPair::Invalid(),
185 fCurrentPosition,TVector2(),TVector2());
188 //______________________________________________________________________________
189 void AliMpMotifTypePadIterator::Invalidate()
191 /// Let the iterator point to the invalid position
193 fCurrentPosition = AliMpIntPair::Invalid();