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 "AliMpPCBPadIterator.h"
28 /// \class AliMpSlatPadIterator
30 /// Implementation of AliMpVPadIterator for slats.
32 /// This class first split the input area (upon which to iterate)
33 /// into a set of areas of constant pad size.
34 /// Then each of those areas is iterated over, using
35 /// AliMpSlatZonePadIterator objects.
37 /// \author L. Aphecetche
41 ClassImp(AliMpSlatPadIterator)
44 //_____________________________________________________________________________
45 AliMpSlatPadIterator::AliMpSlatPadIterator()
46 : AliMpVPadIterator(),
50 fCurrentDelegateIndex(0)
53 // Empty (default) ctor.
57 //_____________________________________________________________________________
58 AliMpSlatPadIterator::AliMpSlatPadIterator(const AliMpSlat* slat,
59 const AliMpArea& area)
60 : AliMpVPadIterator(),
64 fCurrentDelegateIndex(0)
68 // The iteration will occur on the given slat over the specified area.
70 AliDebug(1,Form("this=%p ctor area=(%e,%e,%e,%e)",this,
71 area.LeftBorder(),area.DownBorder(),
72 area.RightBorder(),area.UpBorder()));
75 AliError("Iterator invalidated by improper initialization (e.g. incorrect area given ?)");
77 fDelegates.SetOwner(kTRUE);
80 //_____________________________________________________________________________
81 AliMpSlatPadIterator::~AliMpSlatPadIterator()
86 AliDebug(1,Form("this=%p dtor",this));
90 //_____________________________________________________________________________
92 AliMpSlatPadIterator::Intersect(const AliMpArea& a, const AliMpArea& b) const
95 // Returns the common part of a and b.
97 AliDebug(4,Form("a=(%7.2f,%7.2f;%7.2f,%7.2f) b=(%7.2f,%7.2f;%7.2f,%7.2f)",
98 a.LeftBorder(),a.DownBorder(),a.RightBorder(),a.UpBorder(),
99 b.LeftBorder(),b.DownBorder(),b.RightBorder(),b.UpBorder()));
101 Double_t xmin = TMath::Max(a.LeftBorder(),b.LeftBorder());
102 Double_t xmax = TMath::Min(a.RightBorder(),b.RightBorder());
103 Double_t ymin = TMath::Max(a.DownBorder(),b.DownBorder());
104 Double_t ymax = TMath::Min(a.UpBorder(),b.UpBorder());
105 AliMpArea c( TVector2( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ),
106 TVector2( (xmax-xmin)/2.0, (ymax-ymin)/2.0 ) );
108 AliDebug(4,Form("a intersect b = (%7.2f,%7.2f;%7.2f,%7.2f)",
109 c.LeftBorder(),c.DownBorder(),c.RightBorder(),c.UpBorder()));
113 //_____________________________________________________________________________
115 AliMpSlatPadIterator::Prepare(const AliMpArea& area)
118 // Split area into smaller area intersecting pcbs,
119 // and allocate the corresponding delegate iterators.
121 for ( AliMpSlat::Size_t i = 0; i < fkSlat->GetSize(); ++i )
123 const AliMpPCB* pcb = fkSlat->GetPCB(i);
124 AliMpArea pcbArea(pcb->Area());
125 AliMpArea zone = Intersect(pcbArea,area);
126 AliDebug(3,Form("i=%2d zone is %7.2f,%7.2f->%7.2f,%7.2f %d",i,
127 zone.LeftBorder(),zone.DownBorder(),
128 zone.RightBorder(),zone.UpBorder(),
130 if ( zone.IsValid() )
132 fDelegates.AddLast(new AliMpPCBPadIterator(fkSlat,zone));
135 AliDebug(3,Form("Number of delegates = %d",fDelegates.GetEntries()));
136 // StdoutToAliDebug(3,fDelegates.Print(););
137 return fDelegates.GetLast()>=0;
140 //_____________________________________________________________________________
142 AliMpSlatPadIterator::CurrentItem() const
145 // Returns the current pad of the iteration.
147 if ( fCurrentDelegate )
149 return fCurrentDelegate->CurrentItem();
153 return AliMpPad::Invalid();
157 //_____________________________________________________________________________
159 AliMpSlatPadIterator::First()
162 // (Re)starts the iteration.
164 if ( fDelegates.GetLast() < 0 )
166 AliError("Iterator is not valid, as it gets no delegates at all !");
170 fCurrentDelegateIndex = 0;
171 fCurrentDelegate = static_cast<AliMpVPadIterator*>(fDelegates.At(0));
172 fCurrentDelegate->First();
176 //_____________________________________________________________________________
178 AliMpSlatPadIterator::Invalidate()
181 // Make the iterator invalid.
184 fCurrentDelegate = 0;
185 fCurrentDelegateIndex = 0;
188 //_____________________________________________________________________________
190 AliMpSlatPadIterator::IsDone() const
193 // Returns whether the iteration is ended or not.
195 return ( !fCurrentDelegate ||
196 ( fCurrentDelegateIndex > fDelegates.GetLast() &&
197 fCurrentDelegate->IsDone() ) );
200 //_____________________________________________________________________________
202 AliMpSlatPadIterator::Next()
205 // Next step of the iteration.
207 if (IsDone()) return;
209 fCurrentDelegate->Next();
211 if ( fCurrentDelegate->IsDone() )
213 AliDebug(3,"Moving to next delegate");
214 ++fCurrentDelegateIndex;
215 if ( fCurrentDelegateIndex <= fDelegates.GetLast() )
217 fCurrentDelegate = static_cast<AliMpVPadIterator*>(fDelegates.At(fCurrentDelegateIndex));
218 fCurrentDelegate->First();