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