]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpSlatPadIterator.cxx
Introduced new DE names unique to each det element;
[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"
25#include "AliMpSlatZonePadIterator.h"
26
27#include <algorithm>
28#include <limits>
29#include <cassert>
30
85fec35d 31///
32/// \class AliMpSlatPadIterator
33///
34/// Implementation of AliMpVPadIterator for slats.
35///
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.
40///
41/// \author L. Aphecetche
42///
dee1d5f1 43
13985652 44/// \cond CLASSIMP
85fec35d 45ClassImp(AliMpSlatPadIterator)
13985652 46/// \endcond
dee1d5f1 47
85fec35d 48//const Double_t
49//AliMpSlatPadIterator::fgkDmax = std::numeric_limits<Double_t>::max();
dee1d5f1 50
51//_____________________________________________________________________________
52AliMpSlatPadIterator::AliMpSlatPadIterator()
53: AliMpVPadIterator(),
54fkSlat(0),
ab31db03 55fDelegates(),
dee1d5f1 56fCurrentDelegate(0),
57fCurrentDelegateIndex(0)
58{
59 //
60 // Empty (default) ctor.
61 //
62}
63
64//_____________________________________________________________________________
65AliMpSlatPadIterator::AliMpSlatPadIterator(const AliMpSlat* slat,
66 const AliMpArea& area)
67: AliMpVPadIterator(),
68fkSlat(slat),
ab31db03 69fDelegates(),
dee1d5f1 70fCurrentDelegate(0),
71fCurrentDelegateIndex(0)
72{
73 //
74 // Normal ctor.
75 // The iteration will occur on the given slat over the specified area.
76 //
77 AliDebug(1,Form("this=%p ctor",this));
78 if (!Prepare(area))
79 {
80 AliError("Iterator invalidated by improper initialization (e.g. incorrect area given ?)");
81 }
82}
83
dee1d5f1 84//_____________________________________________________________________________
85AliMpSlatPadIterator::~AliMpSlatPadIterator()
86{
87 //
88 // Dtor.
89 //
90 AliDebug(1,Form("this=%p dtor",this));
91 Invalidate();
92}
93
94//_____________________________________________________________________________
95AliMpArea
96AliMpSlatPadIterator::Intersect(const AliMpArea& a, const AliMpArea& b) const
97{
98 //
99 // Returns the common part of a and b.
100 //
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()));
104
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 ) );
111
112 AliDebug(4,Form("a intersect b = (%7.2f,%7.2f;%7.2f,%7.2f)",
113 c.LeftBorder(),c.DownBorder(),c.RightBorder(),c.UpBorder()));
114 return c;
115}
116
117//_____________________________________________________________________________
118Bool_t
119AliMpSlatPadIterator::Prepare(const AliMpArea& area)
120{
121 //
122 // Split area into smaller area intersecting pcbs,
123 // and allocate the corresponding delegate iterators.
124
125 for ( AliMpSlat::Size_t i = 0; i < fkSlat->GetSize(); ++i )
126 {
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(),
134 zone.IsValid()));
135 if ( zone.IsValid() )
136 {
137 fDelegates.push_back(new AliMpSlatZonePadIterator(fkSlat,zone));
138 }
139 }
140 return !fDelegates.empty();
141}
142
143//_____________________________________________________________________________
144AliMpPad
145AliMpSlatPadIterator::CurrentItem() const
146{
147 //
148 // Returns the current pad of the iteration.
149 //
150 if ( fCurrentDelegate )
151 {
152 return fCurrentDelegate->CurrentItem();
153 }
154 else
155 {
156 return AliMpPad::Invalid();
157 }
158}
159
160//_____________________________________________________________________________
161void
162AliMpSlatPadIterator::First()
163{
164 //
165 // (Re)starts the iteration.
166 //
167 if ( fDelegates.empty() )
168 {
169 AliError("Iterator is not valid, as it gets no delegates at all !");
170 }
171 else
172 {
173 fCurrentDelegateIndex = 0;
174 fCurrentDelegate = fDelegates[0];
175 fCurrentDelegate->First();
176 }
177}
178
179//_____________________________________________________________________________
180void
181AliMpSlatPadIterator::Invalidate()
182{
183 //
184 // Make the iterator invalid.
185 //
186 for ( size_t i = 0; i < fDelegates.size(); ++i )
187 {
188 delete fDelegates[i];
189 fDelegates[i] = 0;
190 }
191 fDelegates.clear();
192 fCurrentDelegate = 0;
193 fCurrentDelegateIndex = 0;
194}
195
196//_____________________________________________________________________________
197Bool_t
198AliMpSlatPadIterator::IsDone() const
199{
200 //
201 // Returns whether the iteration is ended or not.
202 //
203 return ( !fCurrentDelegate ||
204 ( fCurrentDelegateIndex >= fDelegates.size() &&
205 fCurrentDelegate->IsDone() ) );
206}
207
208//_____________________________________________________________________________
209void
210AliMpSlatPadIterator::Next()
211{
212 //
213 // Next step of the iteration.
214 //
215 if (IsDone()) return;
216
217 fCurrentDelegate->Next();
218
219 if ( fCurrentDelegate->IsDone() )
220 {
221 AliDebug(3,"Moving to next delegate");
222 ++fCurrentDelegateIndex;
223 if ( fCurrentDelegateIndex < fDelegates.size() )
224 {
225 fCurrentDelegate = fDelegates[fCurrentDelegateIndex];
226 fCurrentDelegate->First();
227 }
228 }
229}