AliRoot Core  3abf5b4 (3abf5b4)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMpPCBPadIterator.cxx
Go to the documentation of this file.
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$
18 
19 #include "AliMpPCBPadIterator.h"
20 
21 #include "AliMpArea.h"
22 #include "AliMpConstants.h"
23 #include "AliLog.h"
24 #include "AliMpPCB.h"
25 #include "AliMpSlat.h"
26 #include "AliMpSlatSegmentation.h"
27 #include "AliMpEncodePair.h"
28 
29 #include "Riostream.h"
30 #include "TMath.h"
31 
32 
33 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
40 
41 using std::cout;
42 using std::endl;
46 
47 //_____________________________________________________________________________
49  const AliMpArea& area)
51 fkSlat(slat),
52 fSlatSegmentation(new AliMpSlatSegmentation(slat)),
53 fMinIndices(0),
54 fMaxIndices(0),
55 fOffset(0),
56 fCurrentPad(),
57 fIsDone(kTRUE)
58 {
63  if (!CropArea(area))
64  {
65  AliError(Form("Could not crop area : (x,y)min=(%e,%e) ; max=(%e,%e) for slat %s",
66  area.LeftBorder(),area.DownBorder(),
67  area.RightBorder(),area.UpBorder(),fkSlat->GetID()));
68  }
69  Invalidate();
70 }
71 
72 //_____________________________________________________________________________
74 {
78  delete fSlatSegmentation;
79 }
80 
81 //_____________________________________________________________________________
82 Bool_t
84 {
88 
89  AliDebug(3,Form("Input area (%7.2f,%7.2f)->(%7.2f,%7.2f)",
90  area.LeftBorder(),area.DownBorder(),
91  area.RightBorder(),area.UpBorder()));
92 
93  const Double_t kEpsilon = AliMpConstants::LengthTolerance();
94 
95  // Left and right x-limits have to come from first and last pcbs
96  // to deal with short and rounded pcbs cases.
97  AliMpPCB* first = fkSlat->FindPCB(area.LeftBorder(),area.DownBorder());
98  AliMpPCB* last = fkSlat->FindPCB(area.RightBorder()-kEpsilon,
99  area.DownBorder());
100 
101  // Check we're indeed dealing with only one pcb
102  if ( first != last )
103  {
104  AliError("This iterator supposed to work on a single PCB. Please check");
105  return kFALSE;
106  }
107 
108  AliDebug(3,Form("PCB %s Ixmin %2d Ixmax %2d",
109  first->GetID(),first->Ixmin(),first->Ixmax()));
110 
111  Double_t xleft = first->ActiveXmin();
112  Double_t xright = first->ActiveXmax() - kEpsilon;
113 
114  AliDebug(3,Form("xleft,xright=%e,%e",xleft,xright));
115 
116  Double_t xmin = TMath::Max(area.LeftBorder(),xleft);
117  Double_t xmax = TMath::Min(area.RightBorder(),xright);
118  Double_t ymin = TMath::Max(area.DownBorder(),0.0);
119  Double_t ymax = TMath::Min(area.UpBorder(),first->DY()*2.0-kEpsilon);
120 
121  AliDebug(3,Form("Cropped area (%e,%e)->(%e,%e)",
122  xmin,ymin,xmax,ymax));
123 
124  // At this point (xmin,ymin)->(xmax,ymax) should be a zone completely included
125  // inside the slat.
126  // We now try to convert this into a couple of indices pair indicating the
127  // region to iterate over, using integer values, not floating point ones.
128  // For this, we must find out the 4 pads that intersect the (xmin,ymin;xmax,ymax)
129  // area.
130 
131  Int_t ixmin = first->Ixmin() + TMath::FloorNint((xmin-first->ActiveXmin())/first->PadSizeX());
132  Int_t ixmax = first->Ixmin() + TMath::CeilNint((xmax-first->ActiveXmin())/first->PadSizeX()) - 1;
133  Int_t iymin = first->Iymin() + TMath::FloorNint((ymin-first->Ymin())/first->PadSizeY());
134  Int_t iymax = first->Iymin() + TMath::CeilNint((ymax-first->Ymin())/first->PadSizeY()) - 1;
135 
136 
137  fMinIndices = AliMp::Pair(ixmin,iymin);
138  fMaxIndices = AliMp::Pair(ixmax,iymax);
139 
140  AliDebug(3,Form("Paddified cropped area (%d,%d)->(%d,%d) %d,%d ; %d,%d",
141  ixmin,iymin,ixmax,iymax,
142  AliMp::PairFirst(fMinIndices),AliMp::PairSecond(fMinIndices),
144 
145  return fMinIndices >= 0 && fMaxIndices >= 0;
146 }
147 
148 //_____________________________________________________________________________
149 AliMpPad
151 {
155  return fCurrentPad;
156 }
157 
158 //_____________________________________________________________________________
159 void
161 {
165 
166  AliDebug(3,Form("area = (%d,%d)->(%d,%d)",
170  fIsDone = kFALSE;
172  if ( ! fCurrentPad.IsValid() ) Next();
173  if ( ! fCurrentPad.IsValid() )
174  {
175  // did not find any valid pad in there, bailing out.
176  fIsDone = kTRUE;
177  AliError(Form("Could not initiate iterator for slat %s. "
178  " Please check the area you gave : %d,%d to %d,%d",
179  fkSlat->GetName(),
182  return;
183  }
184 }
185 
186 //_____________________________________________________________________________
187 Bool_t
188 AliMpPCBPadIterator::GetNextPosition(Int_t& ix, Int_t& iy) const
189 {
193 
194  ++ix;
195 
196  if ( ix > AliMp::PairFirst(fMaxIndices) )
197  {
198  // Go back leftmost position...
200  // ... and up
201  ++iy;
202  if ( iy > AliMp::PairSecond(fMaxIndices) )
203  {
204  return false;
205  }
206  }
207  return true;
208 }
209 
210 
211 //_____________________________________________________________________________
212 void
214 {
218  fOffset = 0;
220  fIsDone = kTRUE;
221 }
222 
223 //_____________________________________________________________________________
224 Bool_t
226 {
230  return fIsDone;
231 }
232 
233 //_____________________________________________________________________________
234 void
236 {
244 
245  if (IsDone()) return;
246 
247  AliMpPad pad(fCurrentPad);
248  int n = 0;
249  Int_t ix(AliMp::PairFirst(fOffset));
250  Int_t iy(AliMp::PairSecond(fOffset));
251 
252  while ( ( pad == fCurrentPad || ! pad.IsValid() ) && n<100 )
253  {
254  ++n;
255  if (GetNextPosition(ix,iy)==kFALSE)
256  {
257  Invalidate();
258  return;
259  }
260  SetPad(pad,ix,iy);
261  }
262  if ( n>=100 )
263  {
264  AliFatal("This should not happen!");
265  }
266  fCurrentPad = pad;
267 }
268 
269 //_____________________________________________________________________________
270 void
272 {
274  cout << Form("fkSlat=%p fSlatSegmentation=%p (%s)",fkSlat,fSlatSegmentation,
275  fkSlat->GetName()) << endl
276  << Form("minIndices=(%d,%d) maxIndices=(%d,%d)",
279  << Form("currentOffset=(%d,%d) isdone=%d currentpad=",
281  fCurrentPad.Print();
282 }
283 
284 //_____________________________________________________________________________
285 void
286 AliMpPCBPadIterator::SetPad(AliMpPad& pad, Int_t ix, Int_t iy)
287 {
291  pad = fSlatSegmentation->PadByIndices(ix, iy,kFALSE);
292  if (pad.IsValid())
293  {
294  fOffset = AliMp::Pair(ix,iy);
295  }
296 }
void First()
Set iterator to the first pad.
const Double_t kEpsilon
AliMpPad fCurrentPad
! current pad
void SetPad(AliMpPad &pad, Int_t ix, Int_t iy)
AliMpPCB * FindPCB(Int_t ix) const
Find the PCB containing the pad at location (ix,any iy).
Definition: AliMpSlat.cxx:228
Int_t Ixmin() const
Definition: AliMpPCB.cxx:615
Double_t LeftBorder() const
Definition: AliMpArea.cxx:124
Int_t Ixmax() const
Definition: AliMpPCB.cxx:626
A PCB for station 3,4 or 5.
Definition: AliMpPCB.h:46
virtual AliMpPad PadByIndices(Int_t ix, Int_t iy, Bool_t warning) const
Find pad by indices.
MpPair_t Pair(Int_t first, Int_t second)
Encode the pair of integers to another integer.
Double_t Ymin() const
Definition: AliMpPCB.cxx:800
A rectangle area positioned in plane..
Definition: AliMpArea.h:20
MpPair_t fOffset
! current position
Double_t PadSizeX() const
Definition: AliMpPCB.cxx:659
A slat (building block of stations 3, 4 and 5)
Definition: AliMpSlat.h:51
Iterates over slat pads within a region of constant pad size.
static AliMpPad Invalid()
Return invalid pad.
Definition: AliMpPad.h:57
void Next()
Set iterator to the next pad.
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
static Double_t LengthTolerance()
Return the length precision for tests.
Int_t Iymin() const
Definition: AliMpPCB.cxx:637
void Print(Option_t *opt="") const
const char * GetID() const
Definition: AliMpPCB.cxx:542
Bool_t fIsDone
! whether we've finished or not
Double_t ActiveXmin() const
Definition: AliMpPCB.cxx:207
const char * GetName() const
Definition: AliMpSlat.cxx:391
An interface for an iterator over pads.
const AliMpSlat * fkSlat
! the slat we're iterating over
Double_t ActiveXmax() const
Definition: AliMpPCB.cxx:219
Double_t UpBorder() const
Definition: AliMpArea.cxx:140
void Print(const char *="") const
Definition: AliMpPad.cxx:316
MpPair_t fMinIndices
! indices of bottom left of region to iterate over
Implementation of AliMpVSegmentation for St345 slats.
Double_t DownBorder() const
Definition: AliMpArea.cxx:148
Bool_t IsValid() const
Return validity.
Definition: AliMpPad.h:89
Double_t DY() const
Definition: AliMpPCB.cxx:480
Bool_t GetNextPosition(Int_t &ix, Int_t &iy) const
void Invalidate()
Invalidate iterator (.
Int_t PairFirst(MpPair_t pair)
Decode the first integer from encoded pair.
Bool_t CropArea(const AliMpArea &area)
Class which encapsuate all information about a pad.
Definition: AliMpPad.h:22
AliMpSlatSegmentation * fSlatSegmentation
! segmentation pointer
AliMpPad CurrentItem() const
Return current pad.
MpPair_t fMaxIndices
! indices of top right of region to iterate over
Int_t PairSecond(MpPair_t pair)
Decode the second integer from encoded pair.
Double_t PadSizeY() const
Definition: AliMpPCB.cxx:670
Bool_t IsDone() const
Is iterator done.
Double_t RightBorder() const
Definition: AliMpArea.cxx:132