6 // Class describing a row composed of the row segments.
8 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
10 #include <Riostream.h>
15 #include "AliMpVRowSegment.h"
16 #include "AliMpVRowSegmentSpecial.h"
17 #include "AliMpRowSegmentRSpecial.h"
18 #include "AliMpVMotif.h"
19 #include "AliMpMotifType.h"
20 #include "AliMpMotifPosition.h"
21 #include "AliMpMotifMap.h"
22 #include "AliMpConstants.h"
26 //_____________________________________________________________________________
27 AliMpRow::AliMpRow(Int_t id, AliMpMotifMap* motifMap)
37 //_____________________________________________________________________________
48 //_____________________________________________________________________________
49 AliMpRow::~AliMpRow() {
53 for (Int_t i=0; i<GetNofRowSegments(); i++)
66 //_____________________________________________________________________________
67 AliMpVRowSegment* AliMpRow::FindRowSegment(Int_t ix) const
69 // Finds first normal row segment with low indices limit >= ix.
72 for (Int_t i=0; i<GetNofRowSegments(); i++) {
73 AliMpVRowSegment* segment = GetRowSegment(i);
75 if (!dynamic_cast<AliMpVRowSegmentSpecial*>(segment) &&
76 segment->GetHighIndicesLimit().GetFirst() >= ix)
84 //_____________________________________________________________________________
86 AliMpRow::FindMotifPosition(AliMpVRowSegment* segment, Int_t ix) const
88 // Finds first motif position in the specified row segment
89 // with high indices limit >= ix.
92 if (!segment) return 0;
94 for (Int_t i=0; i<segment->GetNofMotifs(); i++){
95 AliMpMotifPosition* motifPosition
96 = GetMotifMap()->FindMotifPosition(segment->GetMotifPositionId(i));
99 Fatal("FindMotifPosition", "Not found.");
103 if (motifPosition->GetHighIndicesLimit().GetFirst()>=ix)
104 return motifPosition;
111 //_____________________________________________________________________________
112 void AliMpRow::SetHighIndicesLimits(Int_t iy)
114 // Sets the global indices high limit to its row segments,
115 // motif positions with a given value.
116 // Keeps ix unmodified.
119 for (Int_t j=0; j<GetNofRowSegments(); j++) {
120 AliMpVRowSegment* rowSegment = GetRowSegment(j);
122 ->SetHighIndicesLimit(
123 AliMpIntPair(rowSegment->GetHighIndicesLimit().GetFirst(),iy));
125 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
127 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
128 AliMpMotifPosition* motifPosition
129 = GetMotifMap()->FindMotifPosition(motifPositionId);
132 ->SetHighIndicesLimit(
133 AliMpIntPair(motifPosition->GetHighIndicesLimit().GetFirst(), iy));
139 //_____________________________________________________________________________
140 void AliMpRow::CheckEmpty() const
142 // Give a fatal if row is empty.
145 if (GetNofRowSegments() == 0)
146 Fatal("CheckEmpty", "Empty row");
153 //_____________________________________________________________________________
154 void AliMpRow::AddRowSegment(AliMpVRowSegment* rowSegment)
156 // Adds row segment at the end.
160 fSegments.push_back(rowSegment);
164 fSegments.Add(rowSegment);
168 //_____________________________________________________________________________
169 void AliMpRow::AddRowSegmentInFront(AliMpVRowSegment* rowSegment)
171 // Inserts row segment in the first vector position.
175 fSegments.insert(fSegments.begin(), rowSegment);
179 fSegments.AddFirst(rowSegment);
183 //_____________________________________________________________________________
184 AliMpVRowSegment* AliMpRow::FindRowSegment(Double_t x) const
186 // Finds the row segment for the specified x position;
187 // returns 0 if no row segment is found.
190 for (Int_t i=0; i<GetNofRowSegments(); i++) {
193 AliMpVRowSegment* rs = fSegments[i];
196 AliMpVRowSegment* rs = (AliMpVRowSegment*)fSegments.At(i);
199 if (x >= rs->LeftBorderX() && x <= rs->RightBorderX())
206 //_____________________________________________________________________________
207 Double_t AliMpRow::LowBorderY() const
209 // Returns the lowest row offset (the Y coordinate of the position of the
210 // low border of motif).
215 return fOffsetY - GetRowSegment(0)->HalfSizeY();
218 //_____________________________________________________________________________
219 Double_t AliMpRow::UpperBorderY() const
221 // Returns the uppermost row offset (the Y coordinate of the position of the
222 // upper border of motif).
227 return fOffsetY + GetRowSegment(0)->HalfSizeY();
230 //_____________________________________________________________________________
231 AliMpVPadIterator* AliMpRow::CreateIterator() const
233 // Iterator is not yet implemented.
236 Fatal("CreateIterator", "Iterator is not yet implemented.");
241 //_____________________________________________________________________________
242 void AliMpRow::SetMotifPositions()
244 // Creates motif positions objects and fills them in the motif map.
249 for (Int_t j=0; j<GetNofRowSegments(); j++) {
250 AliMpVRowSegment* rowSegment = GetRowSegment(j);
252 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
254 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
255 AliMpVMotif* motif = rowSegment->GetMotif(k);
256 TVector2 position = rowSegment->MotifCenter(motifPositionId);
258 AliMpMotifPosition* motifPosition
259 = new AliMpMotifPosition(motifPositionId, motif, position);
260 // set the initial value to of HighIndicesLimit() Invalid()
261 // (this is used for calculation of indices in case of
262 // special row segments)
263 motifPosition->SetHighIndicesLimit(AliMpIntPair::Invalid());
265 //Bool_t warn = (rowSegment->GetNofMotifs()==1);
267 if (dynamic_cast<AliMpVRowSegmentSpecial*>(rowSegment)) warn = false;
268 // supress warnings for special row segments
269 // which motifs can overlap the row borders
271 Bool_t added = GetMotifMap()->AddMotifPosition(motifPosition, warn);
273 if (!added) delete motifPosition;
278 //_____________________________________________________________________________
279 void AliMpRow::SetGlobalIndices(AliMpDirection constPadSizeDirection,
282 // Sets the global indices limits to its row segments,
286 Int_t ix = AliMpConstants::StartPadIndex();
287 Int_t iy = AliMpConstants::StartPadIndex();
289 for (Int_t j=0; j<GetNofRowSegments(); j++) {
290 AliMpVRowSegment* rowSegment = GetRowSegment(j);
292 ix += rowSegment->GetLowIndicesLimit().GetFirst();
294 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
296 // Find the y index value of the low edge
298 if (constPadSizeDirection == kY) {
299 iy = rowBefore->GetHighIndicesLimit().GetSecond()+1;
302 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ix);
303 AliMpMotifPosition* motPos = FindMotifPosition(seg, ix);
304 if (!dynamic_cast<AliMpRowSegmentRSpecial*>(rowSegment)) {
306 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
308 iy = motPos->GetHighIndicesLimit().GetSecond()+1;
313 // Set (ix, iy) to k-th motif position and update ix
314 ix = rowSegment->SetIndicesToMotifPosition(k, AliMpIntPair(ix, iy));
316 rowSegment->SetGlobalIndices();
319 SetLowIndicesLimit(GetRowSegment(0)->GetLowIndicesLimit());
320 SetHighIndicesLimit(GetRowSegment(GetNofRowSegments()-1)->GetHighIndicesLimit());
325 //_____________________________________________________________________________
326 TVector2 AliMpRow::Position() const
328 // Returns the position of the row centre.
331 Double_t x = (GetRowSegment(0)->LeftBorderX() +
332 GetRowSegment(GetNofRowSegments()-1)->RightBorderX())/2.;
334 Double_t y = fOffsetY;
336 return TVector2(x, y);
339 //_____________________________________________________________________________
340 TVector2 AliMpRow::Dimensions() const
342 // Returns the maximum halflengths of the row in x, y.
345 Double_t x = (GetRowSegment(GetNofRowSegments()-1)->RightBorderX() -
346 GetRowSegment(0)->LeftBorderX())/2.;
348 Double_t y = GetRowSegment(0)->HalfSizeY();
350 return TVector2(x, y);
353 //_____________________________________________________________________________
354 void AliMpRow::SetRowSegmentOffsets(const TVector2& offset)
356 // Sets the row segments offsets in X .
361 AliMpVRowSegment* previous = 0;
363 for (Int_t j=0; j<GetNofRowSegments(); j++) {
364 AliMpVRowSegment* rowSegment = GetRowSegment(j);
368 offsetX = previous->RightBorderX();
370 offsetX = offset.X();
372 rowSegment->SetOffset(TVector2(offsetX, 0.));
373 previous = rowSegment;
378 //_____________________________________________________________________________
379 Double_t AliMpRow::SetOffsetY(Double_t offsetY)
381 // Sets the row offset (the Y coordinate of the position of the
382 // center of motif) and returns the offset of the top border.
387 AliMpVRowSegment* first = GetRowSegment(0);
388 Double_t rowSizeY = first->HalfSizeY();
390 // Check if all next row segments have motif of
391 // the same size in y
392 for (Int_t i=1; i<GetNofRowSegments(); i++) {
393 Double_t sizeY = GetRowSegment(i)->HalfSizeY();
395 if (TMath::Abs(sizeY - rowSizeY) >= AliMpConstants::LengthTolerance()) {
396 //cout << GetID() << "th row " << i << "th segment "
397 // << sizeY << " " << rowSizeY << endl;
398 Fatal("SetOffsetY", "Motif with different Y size in one row");
403 offsetY += rowSizeY ;
407 return offsetY += rowSizeY;
410 //_____________________________________________________________________________
411 Int_t AliMpRow::GetNofRowSegments() const
413 // Returns number of row segments.
416 return fSegments.size();
420 return fSegments.GetSize();
424 //_____________________________________________________________________________
425 AliMpVRowSegment* AliMpRow::GetRowSegment(Int_t i) const
427 if (i<0 || i>=GetNofRowSegments()) {
428 Warning("GetRowSegment", "Index outside range");
437 return (AliMpVRowSegment*)fSegments.At(i);