]>
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$ | |
13985652 | 17 | // $MpId: AliMpSlatPadIterator.cxx,v 1.6 2006/05/24 13:58:50 ivana Exp $ |
dee1d5f1 | 18 | |
19 | #include "AliMpSlatPadIterator.h" | |
20 | ||
21 | #include "AliLog.h" | |
22 | #include "AliMpArea.h" | |
23 | #include "AliMpPCB.h" | |
24 | #include "AliMpSlat.h" | |
e37ad718 | 25 | #include "AliMpPCBPadIterator.h" |
dee1d5f1 | 26 | |
3d1463c8 | 27 | |
28 | //----------------------------------------------------------------------------- | |
85fec35d | 29 | /// \class AliMpSlatPadIterator |
30 | /// | |
31 | /// Implementation of AliMpVPadIterator for slats. | |
32 | /// | |
33 | /// This class first split the input area (upon which to iterate) | |
34 | /// into a set of areas of constant pad size. | |
35 | /// Then each of those areas is iterated over, using | |
36 | /// AliMpSlatZonePadIterator objects. | |
37 | /// | |
38 | /// \author L. Aphecetche | |
3d1463c8 | 39 | //----------------------------------------------------------------------------- |
dee1d5f1 | 40 | |
13985652 | 41 | /// \cond CLASSIMP |
85fec35d | 42 | ClassImp(AliMpSlatPadIterator) |
13985652 | 43 | /// \endcond |
dee1d5f1 | 44 | |
dee1d5f1 | 45 | //_____________________________________________________________________________ |
46 | AliMpSlatPadIterator::AliMpSlatPadIterator() | |
47 | : AliMpVPadIterator(), | |
48 | fkSlat(0), | |
ab31db03 | 49 | fDelegates(), |
dee1d5f1 | 50 | fCurrentDelegate(0), |
51 | fCurrentDelegateIndex(0) | |
52 | { | |
71a2d3aa | 53 | /// |
54 | /// Empty (default) ctor. | |
55 | /// | |
dee1d5f1 | 56 | } |
57 | ||
58 | //_____________________________________________________________________________ | |
59 | AliMpSlatPadIterator::AliMpSlatPadIterator(const AliMpSlat* slat, | |
60 | const AliMpArea& area) | |
61 | : AliMpVPadIterator(), | |
62 | fkSlat(slat), | |
ab31db03 | 63 | fDelegates(), |
dee1d5f1 | 64 | fCurrentDelegate(0), |
65 | fCurrentDelegateIndex(0) | |
66 | { | |
71a2d3aa | 67 | /// |
68 | /// Normal ctor. | |
69 | /// The iteration will occur on the given slat over the specified area. | |
70 | /// | |
e37ad718 | 71 | AliDebug(1,Form("this=%p ctor area=(%e,%e,%e,%e)",this, |
72 | area.LeftBorder(),area.DownBorder(), | |
73 | area.RightBorder(),area.UpBorder())); | |
dee1d5f1 | 74 | if (!Prepare(area)) |
75 | { | |
76 | AliError("Iterator invalidated by improper initialization (e.g. incorrect area given ?)"); | |
77 | } | |
e37ad718 | 78 | fDelegates.SetOwner(kTRUE); |
dee1d5f1 | 79 | } |
80 | ||
dee1d5f1 | 81 | //_____________________________________________________________________________ |
82 | AliMpSlatPadIterator::~AliMpSlatPadIterator() | |
83 | { | |
71a2d3aa | 84 | /// |
85 | /// Dtor. | |
86 | /// | |
dee1d5f1 | 87 | AliDebug(1,Form("this=%p dtor",this)); |
88 | Invalidate(); | |
89 | } | |
90 | ||
91 | //_____________________________________________________________________________ | |
92 | AliMpArea | |
93 | AliMpSlatPadIterator::Intersect(const AliMpArea& a, const AliMpArea& b) const | |
94 | { | |
71a2d3aa | 95 | /// |
96 | /// Returns the common part of a and b. | |
97 | /// | |
dee1d5f1 | 98 | AliDebug(4,Form("a=(%7.2f,%7.2f;%7.2f,%7.2f) b=(%7.2f,%7.2f;%7.2f,%7.2f)", |
99 | a.LeftBorder(),a.DownBorder(),a.RightBorder(),a.UpBorder(), | |
100 | b.LeftBorder(),b.DownBorder(),b.RightBorder(),b.UpBorder())); | |
101 | ||
1b36647b | 102 | Double_t xmin = TMath::Max(a.LeftBorder(),b.LeftBorder()); |
103 | Double_t xmax = TMath::Min(a.RightBorder(),b.RightBorder()); | |
104 | Double_t ymin = TMath::Max(a.DownBorder(),b.DownBorder()); | |
105 | Double_t ymax = TMath::Min(a.UpBorder(),b.UpBorder()); | |
6e97fbb8 | 106 | AliMpArea c( (xmin+xmax)/2.0, (ymin+ymax)/2.0 , |
107 | (xmax-xmin)/2.0, (ymax-ymin)/2.0 ); | |
dee1d5f1 | 108 | |
109 | AliDebug(4,Form("a intersect b = (%7.2f,%7.2f;%7.2f,%7.2f)", | |
110 | c.LeftBorder(),c.DownBorder(),c.RightBorder(),c.UpBorder())); | |
111 | return c; | |
112 | } | |
113 | ||
114 | //_____________________________________________________________________________ | |
115 | Bool_t | |
116 | AliMpSlatPadIterator::Prepare(const AliMpArea& area) | |
117 | { | |
71a2d3aa | 118 | /// |
119 | /// Split area into smaller area intersecting pcbs, | |
120 | /// and allocate the corresponding delegate iterators. | |
dee1d5f1 | 121 | |
630711ed | 122 | for ( Int_t i = 0; i < fkSlat->GetSize(); ++i ) |
dee1d5f1 | 123 | { |
124 | const AliMpPCB* pcb = fkSlat->GetPCB(i); | |
e37ad718 | 125 | AliMpArea pcbArea(pcb->Area()); |
dee1d5f1 | 126 | AliMpArea zone = Intersect(pcbArea,area); |
127 | AliDebug(3,Form("i=%2d zone is %7.2f,%7.2f->%7.2f,%7.2f %d",i, | |
128 | zone.LeftBorder(),zone.DownBorder(), | |
129 | zone.RightBorder(),zone.UpBorder(), | |
130 | zone.IsValid())); | |
131 | if ( zone.IsValid() ) | |
132 | { | |
e37ad718 | 133 | fDelegates.AddLast(new AliMpPCBPadIterator(fkSlat,zone)); |
dee1d5f1 | 134 | } |
135 | } | |
e37ad718 | 136 | AliDebug(3,Form("Number of delegates = %d",fDelegates.GetEntries())); |
4cb363de | 137 | // StdoutToAliDebug(3,fDelegates.Print();); |
e37ad718 | 138 | return fDelegates.GetLast()>=0; |
dee1d5f1 | 139 | } |
140 | ||
141 | //_____________________________________________________________________________ | |
142 | AliMpPad | |
143 | AliMpSlatPadIterator::CurrentItem() const | |
144 | { | |
71a2d3aa | 145 | /// |
146 | /// Returns the current pad of the iteration. | |
147 | /// | |
dee1d5f1 | 148 | if ( fCurrentDelegate ) |
149 | { | |
150 | return fCurrentDelegate->CurrentItem(); | |
151 | } | |
152 | else | |
153 | { | |
154 | return AliMpPad::Invalid(); | |
155 | } | |
156 | } | |
157 | ||
158 | //_____________________________________________________________________________ | |
159 | void | |
160 | AliMpSlatPadIterator::First() | |
161 | { | |
71a2d3aa | 162 | /// |
163 | /// (Re)starts the iteration. | |
164 | /// | |
e37ad718 | 165 | if ( fDelegates.GetLast() < 0 ) |
dee1d5f1 | 166 | { |
167 | AliError("Iterator is not valid, as it gets no delegates at all !"); | |
168 | } | |
169 | else | |
170 | { | |
171 | fCurrentDelegateIndex = 0; | |
e37ad718 | 172 | fCurrentDelegate = static_cast<AliMpVPadIterator*>(fDelegates.At(0)); |
dee1d5f1 | 173 | fCurrentDelegate->First(); |
174 | } | |
175 | } | |
176 | ||
177 | //_____________________________________________________________________________ | |
178 | void | |
179 | AliMpSlatPadIterator::Invalidate() | |
180 | { | |
71a2d3aa | 181 | /// |
182 | /// Make the iterator invalid. | |
183 | /// | |
e37ad718 | 184 | fDelegates.Delete(); |
dee1d5f1 | 185 | fCurrentDelegate = 0; |
186 | fCurrentDelegateIndex = 0; | |
187 | } | |
188 | ||
189 | //_____________________________________________________________________________ | |
190 | Bool_t | |
191 | AliMpSlatPadIterator::IsDone() const | |
192 | { | |
71a2d3aa | 193 | /// |
194 | /// Returns whether the iteration is ended or not. | |
195 | /// | |
dee1d5f1 | 196 | return ( !fCurrentDelegate || |
e37ad718 | 197 | ( fCurrentDelegateIndex > fDelegates.GetLast() && |
dee1d5f1 | 198 | fCurrentDelegate->IsDone() ) ); |
199 | } | |
200 | ||
201 | //_____________________________________________________________________________ | |
202 | void | |
203 | AliMpSlatPadIterator::Next() | |
204 | { | |
71a2d3aa | 205 | /// |
206 | /// Next step of the iteration. | |
207 | /// | |
dee1d5f1 | 208 | if (IsDone()) return; |
209 | ||
210 | fCurrentDelegate->Next(); | |
211 | ||
212 | if ( fCurrentDelegate->IsDone() ) | |
213 | { | |
214 | AliDebug(3,"Moving to next delegate"); | |
215 | ++fCurrentDelegateIndex; | |
e37ad718 | 216 | if ( fCurrentDelegateIndex <= fDelegates.GetLast() ) |
dee1d5f1 | 217 | { |
e37ad718 | 218 | fCurrentDelegate = static_cast<AliMpVPadIterator*>(fDelegates.At(fCurrentDelegateIndex)); |
dee1d5f1 | 219 | fCurrentDelegate->First(); |
220 | } | |
221 | } | |
222 | } |