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"
32 /// \class AliMpSlatPadIterator
34 /// Implementation of AliMpVPadIterator for slats.
36 /// This class first split the input area (upon which to iterate)
37 /// into a set of areas of constant pad size.
38 /// Then each of those areas is iterated over, using
39 /// AliMpSlatZonePadIterator objects.
41 /// \author L. Aphecetche
44 ClassImp(AliMpSlatPadIterator)
47 //AliMpSlatPadIterator::fgkDmax = std::numeric_limits<Double_t>::max();
49 //_____________________________________________________________________________
50 AliMpSlatPadIterator::AliMpSlatPadIterator()
51 : AliMpVPadIterator(),
54 fCurrentDelegateIndex(0)
57 // Empty (default) ctor.
61 //_____________________________________________________________________________
62 AliMpSlatPadIterator::AliMpSlatPadIterator(const AliMpSlat* slat,
63 const AliMpArea& area)
64 : AliMpVPadIterator(),
67 fCurrentDelegateIndex(0)
71 // The iteration will occur on the given slat over the specified area.
73 AliDebug(1,Form("this=%p ctor",this));
76 AliError("Iterator invalidated by improper initialization (e.g. incorrect area given ?)");
80 //_____________________________________________________________________________
81 AliMpSlatPadIterator::AliMpSlatPadIterator(const AliMpSlatPadIterator& o)
82 : AliMpVPadIterator(),
84 fCurrentDelegate(o.fCurrentDelegate),
85 fCurrentDelegateIndex(o.fCurrentDelegateIndex)
90 AliFatal("Not implemented");
93 //_____________________________________________________________________________
94 AliMpSlatPadIterator& AliMpSlatPadIterator::operator=(const AliMpSlatPadIterator&)
97 // Assignement operator
99 AliFatal("Not implemented");
103 //_____________________________________________________________________________
104 AliMpSlatPadIterator::~AliMpSlatPadIterator()
109 AliDebug(1,Form("this=%p dtor",this));
113 //_____________________________________________________________________________
115 AliMpSlatPadIterator::Intersect(const AliMpArea& a, const AliMpArea& b) const
118 // Returns the common part of a and b.
120 AliDebug(4,Form("a=(%7.2f,%7.2f;%7.2f,%7.2f) b=(%7.2f,%7.2f;%7.2f,%7.2f)",
121 a.LeftBorder(),a.DownBorder(),a.RightBorder(),a.UpBorder(),
122 b.LeftBorder(),b.DownBorder(),b.RightBorder(),b.UpBorder()));
124 Double_t xmin = std::max(a.LeftBorder(),b.LeftBorder());
125 Double_t xmax = std::min(a.RightBorder(),b.RightBorder());
126 Double_t ymin = std::max(a.DownBorder(),b.DownBorder());
127 Double_t ymax = std::min(a.UpBorder(),b.UpBorder());
128 AliMpArea c( TVector2( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ),
129 TVector2( (xmax-xmin)/2.0, (ymax-ymin)/2.0 ) );
131 AliDebug(4,Form("a intersect b = (%7.2f,%7.2f;%7.2f,%7.2f)",
132 c.LeftBorder(),c.DownBorder(),c.RightBorder(),c.UpBorder()));
136 //_____________________________________________________________________________
138 AliMpSlatPadIterator::Prepare(const AliMpArea& area)
141 // Split area into smaller area intersecting pcbs,
142 // and allocate the corresponding delegate iterators.
144 for ( AliMpSlat::Size_t i = 0; i < fkSlat->GetSize(); ++i )
146 const AliMpPCB* pcb = fkSlat->GetPCB(i);
147 AliMpArea pcbArea( TVector2( (pcb->Xmin()+pcb->Xmax())/2.0,fkSlat->DY()),
148 TVector2( pcb->DX(), pcb->DY() ) );
149 AliMpArea zone = Intersect(pcbArea,area);
150 AliDebug(3,Form("i=%2d zone is %7.2f,%7.2f->%7.2f,%7.2f %d",i,
151 zone.LeftBorder(),zone.DownBorder(),
152 zone.RightBorder(),zone.UpBorder(),
154 if ( zone.IsValid() )
156 fDelegates.push_back(new AliMpSlatZonePadIterator(fkSlat,zone));
159 return !fDelegates.empty();
162 //_____________________________________________________________________________
164 AliMpSlatPadIterator::CurrentItem() const
167 // Returns the current pad of the iteration.
169 if ( fCurrentDelegate )
171 return fCurrentDelegate->CurrentItem();
175 return AliMpPad::Invalid();
179 //_____________________________________________________________________________
181 AliMpSlatPadIterator::First()
184 // (Re)starts the iteration.
186 if ( fDelegates.empty() )
188 AliError("Iterator is not valid, as it gets no delegates at all !");
192 fCurrentDelegateIndex = 0;
193 fCurrentDelegate = fDelegates[0];
194 fCurrentDelegate->First();
198 //_____________________________________________________________________________
200 AliMpSlatPadIterator::Invalidate()
203 // Make the iterator invalid.
205 for ( size_t i = 0; i < fDelegates.size(); ++i )
207 delete fDelegates[i];
211 fCurrentDelegate = 0;
212 fCurrentDelegateIndex = 0;
215 //_____________________________________________________________________________
217 AliMpSlatPadIterator::IsDone() const
220 // Returns whether the iteration is ended or not.
222 return ( !fCurrentDelegate ||
223 ( fCurrentDelegateIndex >= fDelegates.size() &&
224 fCurrentDelegate->IsDone() ) );
227 //_____________________________________________________________________________
229 AliMpSlatPadIterator::Next()
232 // Next step of the iteration.
234 if (IsDone()) return;
236 fCurrentDelegate->Next();
238 if ( fCurrentDelegate->IsDone() )
240 AliDebug(3,"Moving to next delegate");
241 ++fCurrentDelegateIndex;
242 if ( fCurrentDelegateIndex < fDelegates.size() )
244 fCurrentDelegate = fDelegates[fCurrentDelegateIndex];
245 fCurrentDelegate->First();