4 // Class AliMpMotifTypePadIterator
5 // -------------------------------
6 // Class, which defines an iterator over the pads of a given motif type
7 // Included in AliRoot: 2003/05/02
8 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
10 #include "AliMpMotifTypePadIterator.h"
11 #include "AliMpMotifType.h"
13 ClassImp(AliMpMotifTypePadIterator)
15 //______________________________________________________________________________
16 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator():
19 fCurrentPosition(AliMpIntPair::Invalid())
21 // default constructor, set the current position to "invalid"
24 //______________________________________________________________________________
25 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(
26 const AliMpMotifType* motifType)
27 : AliMpVPadIterator(),
28 fMotifType(motifType),
29 fCurrentPosition(AliMpIntPair::Invalid())
31 // normal constructor, let *this to invalid position
34 //______________________________________________________________________________
35 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(
36 const AliMpMotifTypePadIterator& right)
37 : AliMpVPadIterator(right),
38 fMotifType(right.fMotifType),
39 fCurrentPosition(right.fCurrentPosition)
45 //______________________________________________________________________________
46 AliMpMotifTypePadIterator::~AliMpMotifTypePadIterator()
53 //______________________________________________________________________________
54 AliMpMotifTypePadIterator&
55 AliMpMotifTypePadIterator::operator = (const AliMpMotifTypePadIterator& right)
57 // assignement operator
58 // if the right hand iterator isn't of good type
59 // the current operator is invalidated
61 // check assignement to self
62 if (this == &right) return *this;
64 // base class assignement
65 AliMpVPadIterator::operator=(right);
67 fMotifType = right.fMotifType;
68 fCurrentPosition = right.fCurrentPosition;
77 //______________________________________________________________________________
79 AliMpMotifTypePadIterator::FindFirstPadInLine(AliMpIntPair indices) const
81 // Find the indices of the first pad in the same line
82 // as the <indices>, and in column, at least equal, to the
85 if (!fMotifType) return AliMpIntPair::Invalid();
87 while (indices.GetFirst() < fMotifType->GetNofPadsX()) {
88 if (fMotifType->HasPad(indices)) return indices;
89 indices += AliMpIntPair(1,0);
91 return AliMpIntPair::Invalid();
94 //______________________________________________________________________________
95 Bool_t AliMpMotifTypePadIterator::IsValid() const
97 // Is the iterator in a valid position?
99 return fMotifType!=0 && fCurrentPosition.IsValid();
106 //______________________________________________________________________________
107 void AliMpMotifTypePadIterator::First()
109 // Reset the iterator, so that it points to the first available
110 // pad in the motif type
116 fCurrentPosition = AliMpIntPair(0,0);
117 if (fMotifType->HasPad(fCurrentPosition)) return;
120 // if (0,0) is not available
121 // place itself to the first avalable motif after (0,0) (if exists)
128 //______________________________________________________________________________
129 void AliMpMotifTypePadIterator::Next()
131 // Move the iterator to the next valid pad.
133 //if (!IsValid()) return *this;
134 if (!IsValid()) return;
136 while (fCurrentPosition.GetSecond() < fMotifType->GetNofPadsY()){
138 = FindFirstPadInLine(fCurrentPosition + AliMpIntPair(1,0));
139 if (nextTry.IsValid()){
140 fCurrentPosition = nextTry;
143 fCurrentPosition.SetFirst(-1);
144 fCurrentPosition.SetSecond(fCurrentPosition.GetSecond()+1);
147 // if the loop is finished, there's not available pads at all...
152 //______________________________________________________________________________
153 Bool_t AliMpMotifTypePadIterator::IsDone() const
159 //______________________________________________________________________________
160 AliMpPad AliMpMotifTypePadIterator::CurrentItem() const
162 // Returns current pad.
165 return AliMpPad::Invalid();
167 return AliMpPad(AliMpIntPair::Invalid(),
168 fCurrentPosition,TVector2(),TVector2());
171 //______________________________________________________________________________
172 void AliMpMotifTypePadIterator::Invalidate()
174 // Let the iterator points to the invalid position
175 fCurrentPosition = AliMpIntPair::Invalid();