]>
Commit | Line | Data |
---|---|---|
dee1d5f1 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | **************************************************************************/ | |
15 | ||
5f91c9e8 | 16 | // $Id$ |
dee1d5f1 | 17 | // $MpId: AliMpMotifTypePadIterator.cxx,v 1.5 2005/08/26 15:43:36 ivana Exp $ |
5f91c9e8 | 18 | // Category: motif |
19 | // | |
20 | // Class AliMpMotifTypePadIterator | |
21 | // ------------------------------- | |
22 | // Class, which defines an iterator over the pads of a given motif type | |
dbe945cc | 23 | // Included in AliRoot: 2003/05/02 |
5f91c9e8 | 24 | // Authors: David Guez, Ivana Hrivnacova; IPN Orsay |
25 | ||
26 | #include "AliMpMotifTypePadIterator.h" | |
27 | #include "AliMpMotifType.h" | |
28 | ||
29 | ClassImp(AliMpMotifTypePadIterator) | |
30 | ||
31 | //______________________________________________________________________________ | |
32 | AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(): | |
33 | AliMpVPadIterator(), | |
34 | fMotifType(0), | |
35 | fCurrentPosition(AliMpIntPair::Invalid()) | |
36 | { | |
dee1d5f1 | 37 | /// Default constructor, set the current position to "invalid" |
5f91c9e8 | 38 | } |
39 | ||
40 | //______________________________________________________________________________ | |
41 | AliMpMotifTypePadIterator::AliMpMotifTypePadIterator( | |
42 | const AliMpMotifType* motifType) | |
43 | : AliMpVPadIterator(), | |
44 | fMotifType(motifType), | |
45 | fCurrentPosition(AliMpIntPair::Invalid()) | |
46 | { | |
dee1d5f1 | 47 | /// Standard constructor, let *this to invalid position |
5f91c9e8 | 48 | } |
49 | ||
50 | //______________________________________________________________________________ | |
51 | AliMpMotifTypePadIterator::AliMpMotifTypePadIterator( | |
52 | const AliMpMotifTypePadIterator& right) | |
53 | : AliMpVPadIterator(right), | |
54 | fMotifType(right.fMotifType), | |
55 | fCurrentPosition(right.fCurrentPosition) | |
56 | ||
57 | { | |
dee1d5f1 | 58 | /// Copy constructor |
5f91c9e8 | 59 | } |
60 | ||
61 | //______________________________________________________________________________ | |
62 | AliMpMotifTypePadIterator::~AliMpMotifTypePadIterator() | |
63 | { | |
dee1d5f1 | 64 | /// Destructor |
5f91c9e8 | 65 | } |
66 | ||
67 | // operators | |
68 | ||
69 | //______________________________________________________________________________ | |
70 | AliMpMotifTypePadIterator& | |
71 | AliMpMotifTypePadIterator::operator = (const AliMpMotifTypePadIterator& right) | |
72 | { | |
dee1d5f1 | 73 | /// Assignment operator. \n |
74 | /// If the right hand iterator isn't of good type | |
75 | /// the current operator is invalidated | |
5f91c9e8 | 76 | |
dee1d5f1 | 77 | // check assignment to self |
5f91c9e8 | 78 | if (this == &right) return *this; |
79 | ||
dee1d5f1 | 80 | // base class assignment |
5f91c9e8 | 81 | AliMpVPadIterator::operator=(right); |
82 | ||
83 | fMotifType = right.fMotifType; | |
84 | fCurrentPosition = right.fCurrentPosition; | |
85 | ||
86 | return *this; | |
87 | } | |
88 | ||
89 | // | |
90 | //private methods | |
91 | // | |
92 | ||
93 | //______________________________________________________________________________ | |
94 | AliMpIntPair | |
95 | AliMpMotifTypePadIterator::FindFirstPadInLine(AliMpIntPair indices) const | |
96 | { | |
dee1d5f1 | 97 | /// Find the indices of the first pad in the same line |
98 | /// as the <indices>, and in column, at least equal, to the | |
99 | /// one of <indices> | |
5f91c9e8 | 100 | |
101 | if (!fMotifType) return AliMpIntPair::Invalid(); | |
102 | ||
103 | while (indices.GetFirst() < fMotifType->GetNofPadsX()) { | |
104 | if (fMotifType->HasPad(indices)) return indices; | |
105 | indices += AliMpIntPair(1,0); | |
106 | } | |
107 | return AliMpIntPair::Invalid(); | |
108 | } | |
109 | ||
110 | //______________________________________________________________________________ | |
111 | Bool_t AliMpMotifTypePadIterator::IsValid() const | |
112 | { | |
dee1d5f1 | 113 | /// Is the iterator in a valid position? |
5f91c9e8 | 114 | |
115 | return fMotifType!=0 && fCurrentPosition.IsValid(); | |
116 | } | |
117 | ||
118 | // | |
119 | //public methods | |
120 | // | |
121 | ||
122 | //______________________________________________________________________________ | |
123 | void AliMpMotifTypePadIterator::First() | |
124 | { | |
dee1d5f1 | 125 | /// Reset the iterator, so that it points to the first available |
126 | /// pad in the motif type | |
5f91c9e8 | 127 | |
128 | if (!fMotifType) { | |
129 | Invalidate(); | |
130 | return ; | |
131 | } | |
132 | fCurrentPosition = AliMpIntPair(0,0); | |
133 | if (fMotifType->HasPad(fCurrentPosition)) return; | |
134 | ||
135 | ||
136 | // if (0,0) is not available | |
137 | // place itself to the first avalable motif after (0,0) (if exists) | |
138 | // ++(*this); | |
139 | Next(); | |
140 | ||
141 | return; | |
142 | } | |
143 | ||
144 | //______________________________________________________________________________ | |
145 | void AliMpMotifTypePadIterator::Next() | |
146 | { | |
dee1d5f1 | 147 | /// Move the iterator to the next valid pad. |
5f91c9e8 | 148 | |
149 | //if (!IsValid()) return *this; | |
150 | if (!IsValid()) return; | |
151 | ||
152 | while (fCurrentPosition.GetSecond() < fMotifType->GetNofPadsY()){ | |
153 | AliMpIntPair nextTry | |
154 | = FindFirstPadInLine(fCurrentPosition + AliMpIntPair(1,0)); | |
155 | if (nextTry.IsValid()){ | |
156 | fCurrentPosition = nextTry; | |
157 | return; | |
158 | } | |
159 | fCurrentPosition.SetFirst(-1); | |
160 | fCurrentPosition.SetSecond(fCurrentPosition.GetSecond()+1); | |
161 | } | |
162 | ||
163 | // if the loop is finished, there's not available pads at all... | |
164 | Invalidate(); | |
165 | return; | |
166 | } | |
167 | ||
168 | //______________________________________________________________________________ | |
169 | Bool_t AliMpMotifTypePadIterator::IsDone() const | |
170 | { | |
dee1d5f1 | 171 | /// Is the iterator in the end ? |
172 | ||
5f91c9e8 | 173 | return !IsValid(); |
174 | } | |
175 | ||
176 | //______________________________________________________________________________ | |
177 | AliMpPad AliMpMotifTypePadIterator::CurrentItem() const | |
178 | { | |
dee1d5f1 | 179 | /// Return current pad. |
5f91c9e8 | 180 | |
181 | if (!fMotifType) | |
182 | return AliMpPad::Invalid(); | |
183 | else | |
184 | return AliMpPad(AliMpIntPair::Invalid(), | |
185 | fCurrentPosition,TVector2(),TVector2()); | |
186 | } | |
187 | ||
188 | //______________________________________________________________________________ | |
189 | void AliMpMotifTypePadIterator::Invalidate() | |
190 | { | |
dee1d5f1 | 191 | /// Let the iterator point to the invalid position |
192 | ||
5f91c9e8 | 193 | fCurrentPosition = AliMpIntPair::Invalid(); |
194 | ||
195 | } | |
196 |