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.6 2006/05/24 13:58:50 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
45 ClassImp(AliMpSlatPadIterator)
49 //AliMpSlatPadIterator::fgkDmax = std::numeric_limits<Double_t>::max();
51 //_____________________________________________________________________________
52 AliMpSlatPadIterator::AliMpSlatPadIterator()
53 : AliMpVPadIterator(),
57 fCurrentDelegateIndex(0)
60 // Empty (default) ctor.
64 //_____________________________________________________________________________
65 AliMpSlatPadIterator::AliMpSlatPadIterator(const AliMpSlat* slat,
66 const AliMpArea& area)
67 : AliMpVPadIterator(),
71 fCurrentDelegateIndex(0)
75 // The iteration will occur on the given slat over the specified area.
77 AliDebug(1,Form("this=%p ctor",this));
80 AliError("Iterator invalidated by improper initialization (e.g. incorrect area given ?)");
84 //_____________________________________________________________________________
85 AliMpSlatPadIterator::~AliMpSlatPadIterator()
90 AliDebug(1,Form("this=%p dtor",this));
94 //_____________________________________________________________________________
96 AliMpSlatPadIterator::Intersect(const AliMpArea& a, const AliMpArea& b) const
99 // Returns the common part of a and b.
101 AliDebug(4,Form("a=(%7.2f,%7.2f;%7.2f,%7.2f) b=(%7.2f,%7.2f;%7.2f,%7.2f)",
102 a.LeftBorder(),a.DownBorder(),a.RightBorder(),a.UpBorder(),
103 b.LeftBorder(),b.DownBorder(),b.RightBorder(),b.UpBorder()));
105 Double_t xmin = std::max(a.LeftBorder(),b.LeftBorder());
106 Double_t xmax = std::min(a.RightBorder(),b.RightBorder());
107 Double_t ymin = std::max(a.DownBorder(),b.DownBorder());
108 Double_t ymax = std::min(a.UpBorder(),b.UpBorder());
109 AliMpArea c( TVector2( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ),
110 TVector2( (xmax-xmin)/2.0, (ymax-ymin)/2.0 ) );
112 AliDebug(4,Form("a intersect b = (%7.2f,%7.2f;%7.2f,%7.2f)",
113 c.LeftBorder(),c.DownBorder(),c.RightBorder(),c.UpBorder()));
117 //_____________________________________________________________________________
119 AliMpSlatPadIterator::Prepare(const AliMpArea& area)
122 // Split area into smaller area intersecting pcbs,
123 // and allocate the corresponding delegate iterators.
125 for ( AliMpSlat::Size_t i = 0; i < fkSlat->GetSize(); ++i )
127 const AliMpPCB* pcb = fkSlat->GetPCB(i);
128 AliMpArea pcbArea( TVector2( (pcb->Xmin()+pcb->Xmax())/2.0,fkSlat->DY()),
129 TVector2( pcb->DX(), pcb->DY() ) );
130 AliMpArea zone = Intersect(pcbArea,area);
131 AliDebug(3,Form("i=%2d zone is %7.2f,%7.2f->%7.2f,%7.2f %d",i,
132 zone.LeftBorder(),zone.DownBorder(),
133 zone.RightBorder(),zone.UpBorder(),
135 if ( zone.IsValid() )
137 fDelegates.push_back(new AliMpSlatZonePadIterator(fkSlat,zone));
140 return !fDelegates.empty();
143 //_____________________________________________________________________________
145 AliMpSlatPadIterator::CurrentItem() const
148 // Returns the current pad of the iteration.
150 if ( fCurrentDelegate )
152 return fCurrentDelegate->CurrentItem();
156 return AliMpPad::Invalid();
160 //_____________________________________________________________________________
162 AliMpSlatPadIterator::First()
165 // (Re)starts the iteration.
167 if ( fDelegates.empty() )
169 AliError("Iterator is not valid, as it gets no delegates at all !");
173 fCurrentDelegateIndex = 0;
174 fCurrentDelegate = fDelegates[0];
175 fCurrentDelegate->First();
179 //_____________________________________________________________________________
181 AliMpSlatPadIterator::Invalidate()
184 // Make the iterator invalid.
186 for ( size_t i = 0; i < fDelegates.size(); ++i )
188 delete fDelegates[i];
192 fCurrentDelegate = 0;
193 fCurrentDelegateIndex = 0;
196 //_____________________________________________________________________________
198 AliMpSlatPadIterator::IsDone() const
201 // Returns whether the iteration is ended or not.
203 return ( !fCurrentDelegate ||
204 ( fCurrentDelegateIndex >= fDelegates.size() &&
205 fCurrentDelegate->IsDone() ) );
208 //_____________________________________________________________________________
210 AliMpSlatPadIterator::Next()
213 // Next step of the iteration.
215 if (IsDone()) return;
217 fCurrentDelegate->Next();
219 if ( fCurrentDelegate->IsDone() )
221 AliDebug(3,"Moving to next delegate");
222 ++fCurrentDelegateIndex;
223 if ( fCurrentDelegateIndex < fDelegates.size() )
225 fCurrentDelegate = fDelegates[fCurrentDelegateIndex];
226 fCurrentDelegate->First();