AliRoot Core  edcc906 (edcc906)
AliMpRow.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: AliMpRow.cxx,v 1.9 2006/05/24 13:58:46 ivana Exp $
18 // Category: sector
19 
20 //-----------------------------------------------------------------------------
21 // Class AliMpRow
22 // --------------
23 // Class describing a row composed of the row segments.
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26 //-----------------------------------------------------------------------------
27 
28 #include "AliMpRow.h"
29 #include "AliMpVRowSegment.h"
32 #include "AliMpVMotif.h"
33 #include "AliMpMotifType.h"
34 #include "AliMpMotifPosition.h"
35 #include "AliMpMotifMap.h"
36 #include "AliMpConstants.h"
37 
38 #include "AliLog.h"
39 
40 #include <TMath.h>
41 #include <Riostream.h>
42 
43 using std::endl;
45 ClassImp(AliMpRow)
47 
48 //_____________________________________________________________________________
49 AliMpRow::AliMpRow(Int_t id, AliMpMotifMap* motifMap)
50  : AliMpVIndexed(),
51  fID(id),
52  fOffsetY(0.),
53  fSegments(),
54  fMotifMap(motifMap)
55 {
57 }
58 
59 //_____________________________________________________________________________
61  : AliMpVIndexed(),
62  fID(0),
63  fOffsetY(0.),
64  fSegments(),
65  fMotifMap(0)
66 {
68 }
69 
70 //_____________________________________________________________________________
72 {
74 
75  fSegments.Delete();
76 }
77 
78 //
79 // private methods
80 //
81 
82 //_____________________________________________________________________________
84 {
86 
87  for (Int_t i=0; i<GetNofRowSegments(); i++) {
88  AliMpVRowSegment* segment = GetRowSegment(i);
89 
90  if (!dynamic_cast<AliMpVRowSegmentSpecial*>(segment) &&
91  segment->GetHighLimitIx() >= ix)
92 
93  return segment;
94  }
95 
96  return 0;
97 }
98 
99 //_____________________________________________________________________________
102 {
105 
106  if (!segment) return 0;
107 
108  for (Int_t i=0; i<segment->GetNofMotifs(); i++){
109  AliMpMotifPosition* motifPosition
111 
112  if(!motifPosition) {
113  Fatal("FindMotifPosition", "Not found.");
114  return 0;
115  }
116 
117  if (motifPosition->GetHighLimitIx()>=ix)
118  return motifPosition;
119  }
120 
121  return 0;
122 }
123 
124 
125 //_____________________________________________________________________________
127 {
131 
132  for (Int_t j=0; j<GetNofRowSegments(); j++) {
133  AliMpVRowSegment* rowSegment = GetRowSegment(j);
134  rowSegment
135  ->SetHighIndicesLimit(rowSegment->GetHighLimitIx(),iy);
136 
137  for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
138 
139  Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
140  AliMpMotifPosition* motifPosition
141  = GetMotifMap()->FindMotifPosition(motifPositionId);
142 
143  motifPosition
144  ->SetHighIndicesLimit(motifPosition->GetHighLimitIx(), iy);
145 
146  }
147  }
148 }
149 
150 //_____________________________________________________________________________
152 {
154 
155  if (GetNofRowSegments() == 0)
156  Fatal("CheckEmpty", "Empty row");
157 }
158 
159 //
160 // public methods
161 //
162 
163 //_____________________________________________________________________________
165 {
167 
168  fSegments.Add(rowSegment);
169 }
170 
171 //_____________________________________________________________________________
173 {
175 
176  fSegments.AddFirst(rowSegment);
177 }
178 
179 //_____________________________________________________________________________
181 {
184 
185  for (Int_t i=0; i<GetNofRowSegments(); i++) {
186 
188 
189  if (x >= rs->LeftBorderX() && x <= rs->RightBorderX())
190  return rs;
191  }
192 
193  return 0;
194 }
195 
196 //_____________________________________________________________________________
197 Double_t AliMpRow::LowBorderY() const
198 {
201 
202  CheckEmpty();
203 
204  return fOffsetY - GetRowSegment(0)->HalfSizeY();
205 }
206 
207 //_____________________________________________________________________________
208 Double_t AliMpRow::UpperBorderY() const
209 {
212 \
213  CheckEmpty();
214 
215  return fOffsetY + GetRowSegment(0)->HalfSizeY();
216 }
217 
218 //_____________________________________________________________________________
220 {
222 
223  Fatal("CreateIterator", "Iterator is not implemented.");
224 
225  return 0;
226 }
227 
228 //_____________________________________________________________________________
230 {
232 
233  CheckEmpty();
234 
235  for (Int_t j=0; j<GetNofRowSegments(); j++) {
236  AliMpVRowSegment* rowSegment = GetRowSegment(j);
237 
238  for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
239  // Get values
240  Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
241  AliMpVMotif* motif = rowSegment->GetMotif(k);
242 
243  Double_t posx, posy;
244  rowSegment->MotifCenter(motifPositionId, posx, posy);
245 
246  AliMpMotifPosition* motifPosition
247  = new AliMpMotifPosition(motifPositionId, motif, posx, posy);
248 
249  // set the initial value to of HighIndicesLimit() Invalid()
250  // (this is used for calculation of indices in case of
251  // special row segments)
252  motifPosition->SetHighIndicesLimit(0, 0, false);
253 
254  //Bool_t warn = (rowSegment->GetNofMotifs()==1);
255  Bool_t warn = true;
256  if (dynamic_cast<AliMpVRowSegmentSpecial*>(rowSegment)) warn = false;
257  // supress warnings for special row segments
258  // which motifs can overlap the row borders
259 
260  Bool_t added = GetMotifMap()->AddMotifPosition(motifPosition, warn);
261 
262  if (!added) delete motifPosition;
263  }
264  }
265 }
266 
267 //_____________________________________________________________________________
268 void AliMpRow::SetGlobalIndices(AliMp::Direction constPadSizeDirection,
269  AliMpRow* rowBefore)
270 {
273 
274  Int_t ix = AliMpConstants::StartPadIndex();
275  Int_t iy = AliMpConstants::StartPadIndex();
276 
277  for (Int_t j=0; j<GetNofRowSegments(); j++) {
278  AliMpVRowSegment* rowSegment = GetRowSegment(j);
279 
280  ix += rowSegment->GetLowLimitIx();
281 
282  for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
283 
284  // Find the y index value of the low edge
285  if (rowBefore) {
286  if (constPadSizeDirection == AliMp::kY) {
287  iy = rowBefore->GetHighLimitIy()+1;
288  }
289  else {
290  AliMpVRowSegment* seg = rowBefore->FindRowSegment(ix);
291  AliMpMotifPosition* motPos = FindMotifPosition(seg, ix);
292  if (!dynamic_cast<AliMpRowSegmentRSpecial*>(rowSegment)) {
293  if (!motPos) {
294  Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
295  return;
296  }
297 
298  iy = motPos->GetHighLimitIy()+1;
299  }
300  }
301  }
302 
303  // Set (ix, iy) to k-th motif position and update ix
304  ix = rowSegment->SetIndicesToMotifPosition(k, AliMp::Pair(ix, iy));
305  }
306  rowSegment->SetGlobalIndices(rowBefore);
307  }
308 
309  // The low/high indices limits has to be taken as the highest/lowest from all
310  // row segments
311  Int_t ixl = 9999;
312  Int_t iyl = 9999;
313  Int_t ixh = AliMpConstants::StartPadIndex();
314  Int_t iyh = AliMpConstants::StartPadIndex();
315 
316  for (Int_t i=0; i<GetNofRowSegments(); i++) {
317 
318  AliMpVRowSegment* rowSegment = GetRowSegment(i);
319 
320  if ( rowSegment->GetLowLimitIx() < ixl )
321  ixl = rowSegment->GetLowLimitIx();
322 
323  if ( rowSegment->GetLowLimitIy() < iyl )
324  iyl = rowSegment->GetLowLimitIy();
325 
326  if ( rowSegment->GetHighLimitIx() > ixh )
327  ixh = rowSegment->GetHighLimitIx();
328 
329  if ( rowSegment->GetHighLimitIy() > iyh )
330  iyh = rowSegment->GetHighLimitIy();
331  }
332 
333  SetLowIndicesLimit(ixl, iyl);
334  SetHighIndicesLimit(ixh, iyh);
335 }
336 
337 //_____________________________________________________________________________
338 Double_t AliMpRow::GetPositionX() const
339 {
341 
342  return ( GetRowSegment(0)->LeftBorderX() +
343  GetRowSegment(GetNofRowSegments()-1)->RightBorderX() )/2.;
344 }
345 
346 //_____________________________________________________________________________
347 Double_t AliMpRow::GetPositionY() const
348 {
350 
351  return fOffsetY;
352 }
353 
354 //_____________________________________________________________________________
355 Double_t AliMpRow::GetDimensionX() const
356 {
358 
359  return ( GetRowSegment(GetNofRowSegments()-1)->RightBorderX() -
360  GetRowSegment(0)->LeftBorderX() )/2.;
361 }
362 
363 //_____________________________________________________________________________
364 Double_t AliMpRow::GetDimensionY() const
365 {
367 
368  return GetRowSegment(0)->HalfSizeY();
369 }
370 
371 //_____________________________________________________________________________
372 void AliMpRow::SetRowSegmentOffsets(Double_t offsetx)
373 {
375 
376  CheckEmpty();
377 
378  AliMpVRowSegment* previous = 0;
379 
380  for (Int_t j=0; j<GetNofRowSegments(); j++) {
381  AliMpVRowSegment* rowSegment = GetRowSegment(j);
382 
383  Double_t offsetX;
384  if (previous)
385  offsetX = previous->RightBorderX();
386  else
387  offsetX = offsetx;
388 
389  rowSegment->SetOffset(offsetX, 0.);
390  previous = rowSegment;
391  }
392 }
393 
394 
395 //_____________________________________________________________________________
396 Double_t AliMpRow::SetOffsetY(Double_t offsetY)
397 {
400 
401  CheckEmpty();
402 
403  AliMpVRowSegment* first = GetRowSegment(0);
404  Double_t rowSizeY = first->HalfSizeY();
405 
406  // Check if all next row segments have motif of
407  // the same size in y
408  for (Int_t i=1; i<GetNofRowSegments(); i++) {
409  Double_t sizeY = GetRowSegment(i)->HalfSizeY();
410 
411  if (TMath::Abs(sizeY - rowSizeY) >= AliMpConstants::LengthTolerance()) {
412  Fatal("SetOffsetY", "Motif with different Y size in one row");
413  return 0.;
414  }
415  }
416 
417  offsetY += rowSizeY ;
418 
419  fOffsetY = offsetY;
420 
421  return offsetY += rowSizeY;
422 }
423 
424 //_____________________________________________________________________________
426 {
428 
429  return fSegments.GetSize();
430 }
431 
432 //_____________________________________________________________________________
434 {
436 
437  if (i<0 || i>=GetNofRowSegments()) {
438  AliWarningStream() << "Index outside range" << endl;
439  return 0;
440  }
441 
442  return (AliMpVRowSegment*)fSegments.At(i);
443 }
444 
445 //_____________________________________________________________________________
446 void AliMpRow::Print(Option_t* opt) const
447 {
448  std::cout << opt << Form("AliMpRow %2d ",GetID());
449  std::cout << Form("left,right=(%7.2f,%7.2f) bottom,top=(%7.2f,%7.2f)",
454  std::cout << Form(" has %2d row segments",GetNofRowSegments()) << std::endl;
455  std::string sopt(opt);
456  sopt += " ";
457  for ( int i = 0; i < GetNofRowSegments(); ++i )
458  {
460  rs->Print(sopt.c_str());
461  }
462 }
void SetLowIndicesLimit(MpPair_t limit, Bool_t valid=true)
AliMpMotifPosition * FindMotifPosition(AliMpVRowSegment *segment, Int_t ix) const
Definition: AliMpRow.cxx:101
Bool_t AddMotifPosition(AliMpMotifPosition *motifType, Bool_t warn=true)
UInt_t GetID() const
Return row ID.
Definition: AliMpRow.h:85
Int_t GetLowLimitIx() const
virtual void SetGlobalIndices(AliMpRow *rowBefore)=0
Set global indices limits.
Double_t GetPositionX() const
Definition: AliMpRow.cxx:338
Double_t GetPositionY() const
Definition: AliMpRow.cxx:347
Double_t fOffsetY
the y position of the centre of motifs
Definition: AliMpRow.h:75
void SetRowSegmentOffsets(Double_t offsetx)
Definition: AliMpRow.cxx:372
MpPair_t Pair(Int_t first, Int_t second)
Encode the pair of integers to another integer.
Int_t GetLowLimitIy() const
Int_t GetHighLimitIy() const
virtual ~AliMpRow()
Definition: AliMpRow.cxx:71
virtual Int_t SetIndicesToMotifPosition(Int_t i, MpPair_t indices)=0
Set global indices to i-th motif position and returns next index in x.
Double_t LowBorderY() const
Definition: AliMpRow.cxx:197
void Print(Option_t *opt) const
virtual void MotifCenter(Int_t motifPositionId, Double_t &x, Double_t &y) const =0
Fill the coordinates of the motif specified with the given motif position Id.
Double_t UpperBorderY() const
Definition: AliMpRow.cxx:208
Double_t GetDimensionY() const
Definition: AliMpRow.cxx:364
Base class that defines the limits of global pad indices.
Definition: AliMpVIndexed.h:22
AliMpRow()
Definition: AliMpRow.cxx:60
static Double_t LengthTolerance()
Return the length precision for tests.
virtual AliMpVPadIterator * CreateIterator() const
Create iterator over this element.
Definition: AliMpRow.cxx:219
An interface for a row segment.
void SetHighIndicesLimit(MpPair_t limit, Bool_t valid=true)
virtual void Print(Option_t *opt="") const
Definition: AliMpRow.cxx:446
Double_t GetDimensionX() const
Definition: AliMpRow.cxx:355
AliMpVRowSegment * GetRowSegment(Int_t i) const
Definition: AliMpRow.cxx:433
A placed motif.
AliMpVRowSegment * FindRowSegment(Double_t x) const
Definition: AliMpRow.cxx:180
Motif map containers.
Definition: AliMpMotifMap.h:34
TList fSegments
row segments
Definition: AliMpRow.h:76
An interface for an iterator over pads.
void AddRowSegment(AliMpVRowSegment *rowSegment)
Definition: AliMpRow.cxx:164
A row composed of the row segments.
Definition: AliMpRow.h:26
virtual Int_t GetMotifPositionId(Int_t i) const =0
Return the i-th motif position Id of this row segment.
void SetGlobalIndices(AliMp::Direction constPadSizeDirection, AliMpRow *rowBefore)
Definition: AliMpRow.cxx:268
virtual void SetOffset(Double_t x, Double_t y)=0
Calculate offset.
void SetHighIndicesLimits(Int_t iy)
Definition: AliMpRow.cxx:126
static Int_t StartPadIndex()
Return global pad indices start value.
Abstract base class for a motif with its unique ID and the motif type.
Definition: AliMpVMotif.h:24
Double_t SetOffsetY(Double_t offsetY)
Definition: AliMpRow.cxx:396
virtual Double_t HalfSizeY() const =0
Return the half size in y of this row segment.
AliMpMotifPosition * FindMotifPosition(Int_t motifPositionID) const
void AddRowSegmentInFront(AliMpVRowSegment *rowSegment)
Definition: AliMpRow.cxx:172
#define AliWarningStream()
Definition: AliLog.h:581
virtual Double_t LeftBorderX() const =0
Return the x coordinate of the left border in the global coordinate system.
Int_t GetNofRowSegments() const
Definition: AliMpRow.cxx:425
Int_t GetHighLimitIx() const
virtual Double_t RightBorderX() const =0
Return the x coordinate of the right border in the global coordinate system.
virtual Int_t GetNofMotifs() const =0
Return the number of motifs in this this row segment.
virtual AliMpVMotif * GetMotif(Int_t i) const =0
Return the i-th motif of this row segment.
AliMpMotifMap * GetMotifMap() const
Return the motif map associated with its sector.
Definition: AliMpRow.h:88
void CheckEmpty() const
Definition: AliMpRow.cxx:151
direction in y
void SetMotifPositions()
Definition: AliMpRow.cxx:229