1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpRow.cxx,v 1.9 2006/05/24 13:58:46 ivana Exp $
20 //-----------------------------------------------------------------------------
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 //-----------------------------------------------------------------------------
29 #include "AliMpVRowSegment.h"
30 #include "AliMpVRowSegmentSpecial.h"
31 #include "AliMpRowSegmentRSpecial.h"
32 #include "AliMpVMotif.h"
33 #include "AliMpMotifType.h"
34 #include "AliMpMotifPosition.h"
35 #include "AliMpMotifMap.h"
36 #include "AliMpConstants.h"
41 #include <Riostream.h>
48 //_____________________________________________________________________________
49 AliMpRow::AliMpRow(Int_t id, AliMpMotifMap* motifMap)
56 /// Standard constructor
59 //_____________________________________________________________________________
67 /// Default constructor
70 //_____________________________________________________________________________
82 //_____________________________________________________________________________
83 AliMpVRowSegment* AliMpRow::FindRowSegment(Int_t ix) const
85 /// Find first normal row segment with low indices limit >= ix.
87 for (Int_t i=0; i<GetNofRowSegments(); i++) {
88 AliMpVRowSegment* segment = GetRowSegment(i);
90 if (!dynamic_cast<AliMpVRowSegmentSpecial*>(segment) &&
91 segment->GetHighLimitIx() >= ix)
99 //_____________________________________________________________________________
101 AliMpRow::FindMotifPosition(AliMpVRowSegment* segment, Int_t ix) const
103 /// Find first motif position in the specified row segment
104 /// with high indices limit >= ix.
106 if (!segment) return 0;
108 for (Int_t i=0; i<segment->GetNofMotifs(); i++){
109 AliMpMotifPosition* motifPosition
110 = GetMotifMap()->FindMotifPosition(segment->GetMotifPositionId(i));
113 Fatal("FindMotifPosition", "Not found.");
117 if (motifPosition->GetHighLimitIx()>=ix)
118 return motifPosition;
125 //_____________________________________________________________________________
126 void AliMpRow::SetHighIndicesLimits(Int_t iy)
128 /// Set the global indices high limit to its row segments,
129 /// motif positions with a given value.
130 /// Keep ix unmodified.
132 for (Int_t j=0; j<GetNofRowSegments(); j++) {
133 AliMpVRowSegment* rowSegment = GetRowSegment(j);
135 ->SetHighIndicesLimit(rowSegment->GetHighLimitIx(),iy);
137 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
139 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
140 AliMpMotifPosition* motifPosition
141 = GetMotifMap()->FindMotifPosition(motifPositionId);
144 ->SetHighIndicesLimit(motifPosition->GetHighLimitIx(), iy);
150 //_____________________________________________________________________________
151 void AliMpRow::CheckEmpty() const
153 /// Give a fatal if the row is empty.
155 if (GetNofRowSegments() == 0)
156 Fatal("CheckEmpty", "Empty row");
163 //_____________________________________________________________________________
164 void AliMpRow::AddRowSegment(AliMpVRowSegment* rowSegment)
166 /// Add row segment at the end.
168 fSegments.Add(rowSegment);
171 //_____________________________________________________________________________
172 void AliMpRow::AddRowSegmentInFront(AliMpVRowSegment* rowSegment)
174 /// Insert row segment in the first vector position.
176 fSegments.AddFirst(rowSegment);
179 //_____________________________________________________________________________
180 AliMpVRowSegment* AliMpRow::FindRowSegment(Double_t x) const
182 /// Find the row segment for the specified x position;
183 /// return 0 if no row segment is found.
185 for (Int_t i=0; i<GetNofRowSegments(); i++) {
187 AliMpVRowSegment* rs = (AliMpVRowSegment*)fSegments.At(i);
189 if (x >= rs->LeftBorderX() && x <= rs->RightBorderX())
196 //_____________________________________________________________________________
197 Double_t AliMpRow::LowBorderY() const
199 /// Return the lowest row offset (the Y coordinate of the position of the
200 /// low border of motif).
204 return fOffsetY - GetRowSegment(0)->HalfSizeY();
207 //_____________________________________________________________________________
208 Double_t AliMpRow::UpperBorderY() const
210 /// Return the uppermost row offset (the Y coordinate of the position of the
211 /// upper border of motif).
215 return fOffsetY + GetRowSegment(0)->HalfSizeY();
218 //_____________________________________________________________________________
219 AliMpVPadIterator* AliMpRow::CreateIterator() const
221 /// Iterator is not implemented.
223 Fatal("CreateIterator", "Iterator is not implemented.");
228 //_____________________________________________________________________________
229 void AliMpRow::SetMotifPositions()
231 /// Create motif positions objects and fills them in the motif map.
235 for (Int_t j=0; j<GetNofRowSegments(); j++) {
236 AliMpVRowSegment* rowSegment = GetRowSegment(j);
238 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
240 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
241 AliMpVMotif* motif = rowSegment->GetMotif(k);
244 rowSegment->MotifCenter(motifPositionId, posx, posy);
246 AliMpMotifPosition* motifPosition
247 = new AliMpMotifPosition(motifPositionId, motif, posx, posy);
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);
254 //Bool_t warn = (rowSegment->GetNofMotifs()==1);
256 if (dynamic_cast<AliMpVRowSegmentSpecial*>(rowSegment)) warn = false;
257 // supress warnings for special row segments
258 // which motifs can overlap the row borders
260 Bool_t added = GetMotifMap()->AddMotifPosition(motifPosition, warn);
262 if (!added) delete motifPosition;
267 //_____________________________________________________________________________
268 void AliMpRow::SetGlobalIndices(AliMp::Direction constPadSizeDirection,
271 /// Set the global indices limits to its row segments, motif positions
274 Int_t ix = AliMpConstants::StartPadIndex();
275 Int_t iy = AliMpConstants::StartPadIndex();
277 for (Int_t j=0; j<GetNofRowSegments(); j++) {
278 AliMpVRowSegment* rowSegment = GetRowSegment(j);
280 ix += rowSegment->GetLowLimitIx();
282 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
284 // Find the y index value of the low edge
286 if (constPadSizeDirection == AliMp::kY) {
287 iy = rowBefore->GetHighLimitIy()+1;
290 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ix);
291 AliMpMotifPosition* motPos = FindMotifPosition(seg, ix);
292 if (!dynamic_cast<AliMpRowSegmentRSpecial*>(rowSegment)) {
294 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
298 iy = motPos->GetHighLimitIy()+1;
303 // Set (ix, iy) to k-th motif position and update ix
304 ix = rowSegment->SetIndicesToMotifPosition(k, AliMp::Pair(ix, iy));
306 rowSegment->SetGlobalIndices(rowBefore);
309 // The low/high indices limits has to be taken as the highest/lowest from all
313 Int_t ixh = AliMpConstants::StartPadIndex();
314 Int_t iyh = AliMpConstants::StartPadIndex();
316 for (Int_t i=0; i<GetNofRowSegments(); i++) {
318 AliMpVRowSegment* rowSegment = GetRowSegment(i);
320 if ( rowSegment->GetLowLimitIx() < ixl )
321 ixl = rowSegment->GetLowLimitIx();
323 if ( rowSegment->GetLowLimitIy() < iyl )
324 iyl = rowSegment->GetLowLimitIy();
326 if ( rowSegment->GetHighLimitIx() > ixh )
327 ixh = rowSegment->GetHighLimitIx();
329 if ( rowSegment->GetHighLimitIy() > iyh )
330 iyh = rowSegment->GetHighLimitIy();
333 SetLowIndicesLimit(ixl, iyl);
334 SetHighIndicesLimit(ixh, iyh);
337 //_____________________________________________________________________________
338 Double_t AliMpRow::GetPositionX() const
340 /// Return the position of the row centre.
342 return ( GetRowSegment(0)->LeftBorderX() +
343 GetRowSegment(GetNofRowSegments()-1)->RightBorderX() )/2.;
346 //_____________________________________________________________________________
347 Double_t AliMpRow::GetPositionY() const
349 /// Return the position of the row centre.
354 //_____________________________________________________________________________
355 Double_t AliMpRow::GetDimensionX() const
357 /// Return the maximum halflengths of the row in x, y.
359 return ( GetRowSegment(GetNofRowSegments()-1)->RightBorderX() -
360 GetRowSegment(0)->LeftBorderX() )/2.;
363 //_____________________________________________________________________________
364 Double_t AliMpRow::GetDimensionY() const
366 /// Return the maximum halflengths of the row in x, y.
368 return GetRowSegment(0)->HalfSizeY();
371 //_____________________________________________________________________________
372 void AliMpRow::SetRowSegmentOffsets(Double_t offsetx)
374 /// Set the row segments offsets in X .
378 AliMpVRowSegment* previous = 0;
380 for (Int_t j=0; j<GetNofRowSegments(); j++) {
381 AliMpVRowSegment* rowSegment = GetRowSegment(j);
385 offsetX = previous->RightBorderX();
389 rowSegment->SetOffset(offsetX, 0.);
390 previous = rowSegment;
395 //_____________________________________________________________________________
396 Double_t AliMpRow::SetOffsetY(Double_t offsetY)
398 /// Set the row offset (the Y coordinate of the position of the
399 /// center of motif) and returns the offset of the top border.
403 AliMpVRowSegment* first = GetRowSegment(0);
404 Double_t rowSizeY = first->HalfSizeY();
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();
411 if (TMath::Abs(sizeY - rowSizeY) >= AliMpConstants::LengthTolerance()) {
412 Fatal("SetOffsetY", "Motif with different Y size in one row");
417 offsetY += rowSizeY ;
421 return offsetY += rowSizeY;
424 //_____________________________________________________________________________
425 Int_t AliMpRow::GetNofRowSegments() const
427 /// Return number of row segments.
429 return fSegments.GetSize();
432 //_____________________________________________________________________________
433 AliMpVRowSegment* AliMpRow::GetRowSegment(Int_t i) const
435 /// Return i-th row segment.
437 if (i<0 || i>=GetNofRowSegments()) {
438 AliWarningStream() << "Index outside range" << endl;
442 return (AliMpVRowSegment*)fSegments.At(i);