]>
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 | ||
16 | // $Id$ | |
17 | // $MpId: AliMpSlatPadIterator.cxx,v 1.4 2005/09/19 19:01:31 ivana Exp $ | |
18 | ||
19 | #include "AliMpSlatPadIterator.h" | |
20 | ||
21 | #include "AliLog.h" | |
22 | #include "AliMpArea.h" | |
23 | #include "AliMpPCB.h" | |
24 | #include "AliMpSlat.h" | |
25 | #include "AliMpSlatZonePadIterator.h" | |
26 | ||
27 | #include <algorithm> | |
28 | #include <limits> | |
29 | #include <cassert> | |
30 | ||
31 | ClassImp(AliMpSlatPadIterator) | |
32 | ||
33 | ||
34 | namespace | |
35 | { | |
36 | Double_t DMAX(std::numeric_limits<Double_t>::max()); | |
37 | } | |
38 | ||
39 | //_____________________________________________________________________________ | |
40 | AliMpSlatPadIterator::AliMpSlatPadIterator() | |
41 | : AliMpVPadIterator(), | |
42 | fkSlat(0), | |
43 | fCurrentDelegate(0), | |
44 | fCurrentDelegateIndex(0) | |
45 | { | |
46 | // | |
47 | // Empty (default) ctor. | |
48 | // | |
49 | } | |
50 | ||
51 | //_____________________________________________________________________________ | |
52 | AliMpSlatPadIterator::AliMpSlatPadIterator(const AliMpSlat* slat, | |
53 | const AliMpArea& area) | |
54 | : AliMpVPadIterator(), | |
55 | fkSlat(slat), | |
56 | fCurrentDelegate(0), | |
57 | fCurrentDelegateIndex(0) | |
58 | { | |
59 | // | |
60 | // Normal ctor. | |
61 | // The iteration will occur on the given slat over the specified area. | |
62 | // | |
63 | AliDebug(1,Form("this=%p ctor",this)); | |
64 | if (!Prepare(area)) | |
65 | { | |
66 | AliError("Iterator invalidated by improper initialization (e.g. incorrect area given ?)"); | |
67 | } | |
68 | } | |
69 | ||
70 | //_____________________________________________________________________________ | |
71 | AliMpSlatPadIterator::AliMpSlatPadIterator(const AliMpSlatPadIterator& o) | |
72 | : AliMpVPadIterator(), | |
73 | fkSlat(o.fkSlat), | |
74 | fCurrentDelegate(o.fCurrentDelegate), | |
75 | fCurrentDelegateIndex(o.fCurrentDelegateIndex) | |
76 | { | |
77 | // | |
78 | // Copy ctor. | |
79 | // | |
80 | AliFatal("Not implemented"); | |
81 | } | |
82 | ||
83 | //_____________________________________________________________________________ | |
84 | AliMpSlatPadIterator& AliMpSlatPadIterator::operator=(const AliMpSlatPadIterator&) | |
85 | { | |
86 | // | |
87 | // Assignement operator | |
88 | // | |
89 | AliFatal("Not implemented"); | |
90 | return *this; | |
91 | } | |
92 | ||
93 | //_____________________________________________________________________________ | |
94 | AliMpSlatPadIterator::~AliMpSlatPadIterator() | |
95 | { | |
96 | // | |
97 | // Dtor. | |
98 | // | |
99 | AliDebug(1,Form("this=%p dtor",this)); | |
100 | Invalidate(); | |
101 | } | |
102 | ||
103 | //_____________________________________________________________________________ | |
104 | AliMpArea | |
105 | AliMpSlatPadIterator::Intersect(const AliMpArea& a, const AliMpArea& b) const | |
106 | { | |
107 | // | |
108 | // Returns the common part of a and b. | |
109 | // | |
110 | AliDebug(4,Form("a=(%7.2f,%7.2f;%7.2f,%7.2f) b=(%7.2f,%7.2f;%7.2f,%7.2f)", | |
111 | a.LeftBorder(),a.DownBorder(),a.RightBorder(),a.UpBorder(), | |
112 | b.LeftBorder(),b.DownBorder(),b.RightBorder(),b.UpBorder())); | |
113 | ||
114 | Double_t xmin = std::max(a.LeftBorder(),b.LeftBorder()); | |
115 | Double_t xmax = std::min(a.RightBorder(),b.RightBorder()); | |
116 | Double_t ymin = std::max(a.DownBorder(),b.DownBorder()); | |
117 | Double_t ymax = std::min(a.UpBorder(),b.UpBorder()); | |
118 | AliMpArea c( TVector2( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ), | |
119 | TVector2( (xmax-xmin)/2.0, (ymax-ymin)/2.0 ) ); | |
120 | ||
121 | AliDebug(4,Form("a intersect b = (%7.2f,%7.2f;%7.2f,%7.2f)", | |
122 | c.LeftBorder(),c.DownBorder(),c.RightBorder(),c.UpBorder())); | |
123 | return c; | |
124 | } | |
125 | ||
126 | //_____________________________________________________________________________ | |
127 | Bool_t | |
128 | AliMpSlatPadIterator::Prepare(const AliMpArea& area) | |
129 | { | |
130 | // | |
131 | // Split area into smaller area intersecting pcbs, | |
132 | // and allocate the corresponding delegate iterators. | |
133 | ||
134 | for ( AliMpSlat::Size_t i = 0; i < fkSlat->GetSize(); ++i ) | |
135 | { | |
136 | const AliMpPCB* pcb = fkSlat->GetPCB(i); | |
137 | AliMpArea pcbArea( TVector2( (pcb->Xmin()+pcb->Xmax())/2.0,fkSlat->DY()), | |
138 | TVector2( pcb->DX(), pcb->DY() ) ); | |
139 | AliMpArea zone = Intersect(pcbArea,area); | |
140 | AliDebug(3,Form("i=%2d zone is %7.2f,%7.2f->%7.2f,%7.2f %d",i, | |
141 | zone.LeftBorder(),zone.DownBorder(), | |
142 | zone.RightBorder(),zone.UpBorder(), | |
143 | zone.IsValid())); | |
144 | if ( zone.IsValid() ) | |
145 | { | |
146 | fDelegates.push_back(new AliMpSlatZonePadIterator(fkSlat,zone)); | |
147 | } | |
148 | } | |
149 | return !fDelegates.empty(); | |
150 | } | |
151 | ||
152 | //_____________________________________________________________________________ | |
153 | AliMpPad | |
154 | AliMpSlatPadIterator::CurrentItem() const | |
155 | { | |
156 | // | |
157 | // Returns the current pad of the iteration. | |
158 | // | |
159 | if ( fCurrentDelegate ) | |
160 | { | |
161 | return fCurrentDelegate->CurrentItem(); | |
162 | } | |
163 | else | |
164 | { | |
165 | return AliMpPad::Invalid(); | |
166 | } | |
167 | } | |
168 | ||
169 | //_____________________________________________________________________________ | |
170 | void | |
171 | AliMpSlatPadIterator::First() | |
172 | { | |
173 | // | |
174 | // (Re)starts the iteration. | |
175 | // | |
176 | if ( fDelegates.empty() ) | |
177 | { | |
178 | AliError("Iterator is not valid, as it gets no delegates at all !"); | |
179 | } | |
180 | else | |
181 | { | |
182 | fCurrentDelegateIndex = 0; | |
183 | fCurrentDelegate = fDelegates[0]; | |
184 | fCurrentDelegate->First(); | |
185 | } | |
186 | } | |
187 | ||
188 | //_____________________________________________________________________________ | |
189 | void | |
190 | AliMpSlatPadIterator::Invalidate() | |
191 | { | |
192 | // | |
193 | // Make the iterator invalid. | |
194 | // | |
195 | for ( size_t i = 0; i < fDelegates.size(); ++i ) | |
196 | { | |
197 | delete fDelegates[i]; | |
198 | fDelegates[i] = 0; | |
199 | } | |
200 | fDelegates.clear(); | |
201 | fCurrentDelegate = 0; | |
202 | fCurrentDelegateIndex = 0; | |
203 | } | |
204 | ||
205 | //_____________________________________________________________________________ | |
206 | Bool_t | |
207 | AliMpSlatPadIterator::IsDone() const | |
208 | { | |
209 | // | |
210 | // Returns whether the iteration is ended or not. | |
211 | // | |
212 | return ( !fCurrentDelegate || | |
213 | ( fCurrentDelegateIndex >= fDelegates.size() && | |
214 | fCurrentDelegate->IsDone() ) ); | |
215 | } | |
216 | ||
217 | //_____________________________________________________________________________ | |
218 | void | |
219 | AliMpSlatPadIterator::Next() | |
220 | { | |
221 | // | |
222 | // Next step of the iteration. | |
223 | // | |
224 | if (IsDone()) return; | |
225 | ||
226 | fCurrentDelegate->Next(); | |
227 | ||
228 | if ( fCurrentDelegate->IsDone() ) | |
229 | { | |
230 | AliDebug(3,"Moving to next delegate"); | |
231 | ++fCurrentDelegateIndex; | |
232 | if ( fCurrentDelegateIndex < fDelegates.size() ) | |
233 | { | |
234 | fCurrentDelegate = fDelegates[fCurrentDelegateIndex]; | |
235 | fCurrentDelegate->First(); | |
236 | } | |
237 | } | |
238 | } |