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: AliMpSlatPadIterator.cxx,v 1.4 2005/09/19 19:01:31 ivana Exp $
19 #include "AliMpSlatPadIterator.h"
22 #include "AliMpArea.h"
24 #include "AliMpSlat.h"
25 #include "AliMpSlatZonePadIterator.h"
31 ClassImp(AliMpSlatPadIterator)
36 Double_t DMAX(std::numeric_limits<Double_t>::max());
39 //_____________________________________________________________________________
40 AliMpSlatPadIterator::AliMpSlatPadIterator()
41 : AliMpVPadIterator(),
44 fCurrentDelegateIndex(0)
47 // Empty (default) ctor.
51 //_____________________________________________________________________________
52 AliMpSlatPadIterator::AliMpSlatPadIterator(const AliMpSlat* slat,
53 const AliMpArea& area)
54 : AliMpVPadIterator(),
57 fCurrentDelegateIndex(0)
61 // The iteration will occur on the given slat over the specified area.
63 AliDebug(1,Form("this=%p ctor",this));
66 AliError("Iterator invalidated by improper initialization (e.g. incorrect area given ?)");
70 //_____________________________________________________________________________
71 AliMpSlatPadIterator::AliMpSlatPadIterator(const AliMpSlatPadIterator& o)
72 : AliMpVPadIterator(),
74 fCurrentDelegate(o.fCurrentDelegate),
75 fCurrentDelegateIndex(o.fCurrentDelegateIndex)
80 AliFatal("Not implemented");
83 //_____________________________________________________________________________
84 AliMpSlatPadIterator& AliMpSlatPadIterator::operator=(const AliMpSlatPadIterator&)
87 // Assignement operator
89 AliFatal("Not implemented");
93 //_____________________________________________________________________________
94 AliMpSlatPadIterator::~AliMpSlatPadIterator()
99 AliDebug(1,Form("this=%p dtor",this));
103 //_____________________________________________________________________________
105 AliMpSlatPadIterator::Intersect(const AliMpArea& a, const AliMpArea& b) const
108 // Returns the common part of a and b.
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()));
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 ) );
121 AliDebug(4,Form("a intersect b = (%7.2f,%7.2f;%7.2f,%7.2f)",
122 c.LeftBorder(),c.DownBorder(),c.RightBorder(),c.UpBorder()));
126 //_____________________________________________________________________________
128 AliMpSlatPadIterator::Prepare(const AliMpArea& area)
131 // Split area into smaller area intersecting pcbs,
132 // and allocate the corresponding delegate iterators.
134 for ( AliMpSlat::Size_t i = 0; i < fkSlat->GetSize(); ++i )
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(),
144 if ( zone.IsValid() )
146 fDelegates.push_back(new AliMpSlatZonePadIterator(fkSlat,zone));
149 return !fDelegates.empty();
152 //_____________________________________________________________________________
154 AliMpSlatPadIterator::CurrentItem() const
157 // Returns the current pad of the iteration.
159 if ( fCurrentDelegate )
161 return fCurrentDelegate->CurrentItem();
165 return AliMpPad::Invalid();
169 //_____________________________________________________________________________
171 AliMpSlatPadIterator::First()
174 // (Re)starts the iteration.
176 if ( fDelegates.empty() )
178 AliError("Iterator is not valid, as it gets no delegates at all !");
182 fCurrentDelegateIndex = 0;
183 fCurrentDelegate = fDelegates[0];
184 fCurrentDelegate->First();
188 //_____________________________________________________________________________
190 AliMpSlatPadIterator::Invalidate()
193 // Make the iterator invalid.
195 for ( size_t i = 0; i < fDelegates.size(); ++i )
197 delete fDelegates[i];
201 fCurrentDelegate = 0;
202 fCurrentDelegateIndex = 0;
205 //_____________________________________________________________________________
207 AliMpSlatPadIterator::IsDone() const
210 // Returns whether the iteration is ended or not.
212 return ( !fCurrentDelegate ||
213 ( fCurrentDelegateIndex >= fDelegates.size() &&
214 fCurrentDelegate->IsDone() ) );
217 //_____________________________________________________________________________
219 AliMpSlatPadIterator::Next()
222 // Next step of the iteration.
224 if (IsDone()) return;
226 fCurrentDelegate->Next();
228 if ( fCurrentDelegate->IsDone() )
230 AliDebug(3,"Moving to next delegate");
231 ++fCurrentDelegateIndex;
232 if ( fCurrentDelegateIndex < fDelegates.size() )
234 fCurrentDelegate = fDelegates[fCurrentDelegateIndex];
235 fCurrentDelegate->First();