]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSlatPadIterator.cxx
Coding conventions (Laurent)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSlatPadIterator.cxx
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$
17 // $MpId: AliMpSlatPadIterator.cxx,v 1.4 2005/09/19 19:01:31 ivana Exp $
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
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 ///
43
44 ClassImp(AliMpSlatPadIterator)
45
46 //const Double_t
47 //AliMpSlatPadIterator::fgkDmax = std::numeric_limits<Double_t>::max();
48
49 //_____________________________________________________________________________
50 AliMpSlatPadIterator::AliMpSlatPadIterator()
51 : AliMpVPadIterator(),
52 fkSlat(0),
53 fCurrentDelegate(0),
54 fCurrentDelegateIndex(0)
55 {
56   //
57   // Empty (default) ctor.
58   //
59 }
60
61 //_____________________________________________________________________________
62 AliMpSlatPadIterator::AliMpSlatPadIterator(const AliMpSlat* slat,
63                                                                                                                                                                          const AliMpArea& area)
64 : AliMpVPadIterator(),
65 fkSlat(slat),
66 fCurrentDelegate(0),
67 fCurrentDelegateIndex(0)
68 {
69   //
70   // Normal ctor.
71   // The iteration will occur on the given slat over the specified area.
72   //
73   AliDebug(1,Form("this=%p ctor",this));
74   if (!Prepare(area)) 
75         {
76                 AliError("Iterator invalidated by improper initialization (e.g. incorrect area given ?)");
77         }
78 }
79
80 //_____________________________________________________________________________
81 AliMpSlatPadIterator::AliMpSlatPadIterator(const AliMpSlatPadIterator& o) 
82 : AliMpVPadIterator(),
83 fkSlat(o.fkSlat),
84 fCurrentDelegate(o.fCurrentDelegate),
85 fCurrentDelegateIndex(o.fCurrentDelegateIndex)
86 {
87   //
88   // Copy ctor. 
89   //
90         AliFatal("Not implemented");
91 }
92
93 //_____________________________________________________________________________
94 AliMpSlatPadIterator& AliMpSlatPadIterator::operator=(const AliMpSlatPadIterator&)
95 {
96   //
97   // Assignement operator
98   //
99         AliFatal("Not implemented");
100         return *this;
101 }
102
103 //_____________________________________________________________________________
104 AliMpSlatPadIterator::~AliMpSlatPadIterator()
105
106   //
107   // Dtor.
108   //
109   AliDebug(1,Form("this=%p dtor",this));
110   Invalidate();
111 }
112
113 //_____________________________________________________________________________
114 AliMpArea
115 AliMpSlatPadIterator::Intersect(const AliMpArea& a, const AliMpArea& b) const
116
117   //
118   // Returns the common part of a and b.
119   //
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()));
123         
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 ) );
130         
131   AliDebug(4,Form("a intersect b = (%7.2f,%7.2f;%7.2f,%7.2f)",
132                                                                         c.LeftBorder(),c.DownBorder(),c.RightBorder(),c.UpBorder()));
133   return c;
134 }
135
136 //_____________________________________________________________________________
137 Bool_t
138 AliMpSlatPadIterator::Prepare(const AliMpArea& area)
139 {
140   //
141   // Split area into smaller area intersecting pcbs,
142   // and allocate the corresponding delegate iterators.
143         
144   for ( AliMpSlat::Size_t i = 0; i < fkSlat->GetSize(); ++i )
145         {
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(),
153                                                                                 zone.IsValid()));
154                 if ( zone.IsValid() )
155                 {
156                         fDelegates.push_back(new AliMpSlatZonePadIterator(fkSlat,zone));
157                 }
158         }
159   return !fDelegates.empty();
160 }
161
162 //_____________________________________________________________________________
163 AliMpPad
164 AliMpSlatPadIterator::CurrentItem() const
165 {
166   //
167   // Returns the current pad of the iteration.
168   //
169   if ( fCurrentDelegate )
170         {
171                 return fCurrentDelegate->CurrentItem();
172         }
173   else
174         {
175                 return AliMpPad::Invalid();
176         }
177 }
178
179 //_____________________________________________________________________________
180 void
181 AliMpSlatPadIterator::First()
182 {
183   //
184   // (Re)starts the iteration.
185   //
186   if ( fDelegates.empty() )
187         {
188                 AliError("Iterator is not valid, as it gets no delegates at all !");
189         }
190   else
191         {
192                 fCurrentDelegateIndex = 0;
193                 fCurrentDelegate = fDelegates[0];
194                 fCurrentDelegate->First();
195         }
196 }
197
198 //_____________________________________________________________________________
199 void
200 AliMpSlatPadIterator::Invalidate()
201 {
202   //
203   // Make the iterator invalid.
204   //
205   for ( size_t i = 0; i < fDelegates.size(); ++i )
206         {
207                 delete fDelegates[i];
208                 fDelegates[i] = 0;
209         }
210   fDelegates.clear();
211   fCurrentDelegate = 0;
212   fCurrentDelegateIndex = 0;
213 }
214
215 //_____________________________________________________________________________
216 Bool_t
217 AliMpSlatPadIterator::IsDone() const
218 {
219   //
220   // Returns whether the iteration is ended or not.
221   //
222   return ( !fCurrentDelegate ||
223                                          ( fCurrentDelegateIndex >= fDelegates.size() && 
224                                                  fCurrentDelegate->IsDone() ) );
225 }
226
227 //_____________________________________________________________________________
228 void
229 AliMpSlatPadIterator::Next()
230 {
231   //
232   // Next step of the iteration.
233   //
234   if (IsDone()) return;
235         
236   fCurrentDelegate->Next();
237         
238   if ( fCurrentDelegate->IsDone() )
239         {
240                 AliDebug(3,"Moving to next delegate");
241                 ++fCurrentDelegateIndex;
242                 if ( fCurrentDelegateIndex < fDelegates.size() )
243                 {
244                         fCurrentDelegate = fDelegates[fCurrentDelegateIndex];
245                         fCurrentDelegate->First();
246                 }
247         }
248 }