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(const AliMpRow& right)
50 : AliMpVIndexed(right) {
52 Fatal("AliMpRow", "Copy constructor not provided.");
55 //_____________________________________________________________________________
56 AliMpRow::~AliMpRow() {
60 for (Int_t i=0; i<GetNofRowSegments(); i++)
73 //_____________________________________________________________________________
74 AliMpRow& AliMpRow::operator=(const AliMpRow& right)
76 // check assignement to self
77 if (this == &right) return *this;
79 Fatal("operator =", "Assignement operator not provided.");
88 //_____________________________________________________________________________
89 AliMpVRowSegment* AliMpRow::FindRowSegment(Int_t ix) const
91 // Finds first normal row segment with low indices limit >= ix.
94 for (Int_t i=0; i<GetNofRowSegments(); i++) {
95 AliMpVRowSegment* segment = GetRowSegment(i);
97 if (!dynamic_cast<AliMpVRowSegmentSpecial*>(segment) &&
98 segment->GetHighIndicesLimit().GetFirst() >= ix)
106 //_____________________________________________________________________________
108 AliMpRow::FindMotifPosition(AliMpVRowSegment* segment, Int_t ix) const
110 // Finds first motif position in the specified row segment
111 // with high indices limit >= ix.
114 if (!segment) return 0;
116 for (Int_t i=0; i<segment->GetNofMotifs(); i++){
117 AliMpMotifPosition* motifPosition
118 = GetMotifMap()->FindMotifPosition(segment->GetMotifPositionId(i));
121 Fatal("FindMotifPosition", "Not found.");
125 if (motifPosition->GetHighIndicesLimit().GetFirst()>=ix)
126 return motifPosition;
133 //_____________________________________________________________________________
134 void AliMpRow::SetHighIndicesLimits(Int_t iy)
136 // Sets the global indices high limit to its row segments,
137 // motif positions with a given value.
138 // Keeps ix unmodified.
141 for (Int_t j=0; j<GetNofRowSegments(); j++) {
142 AliMpVRowSegment* rowSegment = GetRowSegment(j);
144 ->SetHighIndicesLimit(
145 AliMpIntPair(rowSegment->GetHighIndicesLimit().GetFirst(),iy));
147 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
149 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
150 AliMpMotifPosition* motifPosition
151 = GetMotifMap()->FindMotifPosition(motifPositionId);
154 ->SetHighIndicesLimit(
155 AliMpIntPair(motifPosition->GetHighIndicesLimit().GetFirst(), iy));
161 //_____________________________________________________________________________
162 void AliMpRow::CheckEmpty() const
164 // Give a fatal if row is empty.
167 if (GetNofRowSegments() == 0)
168 Fatal("CheckEmpty", "Empty row");
175 //_____________________________________________________________________________
176 void AliMpRow::AddRowSegment(AliMpVRowSegment* rowSegment)
178 // Adds row segment at the end.
182 fSegments.push_back(rowSegment);
186 fSegments.Add(rowSegment);
190 //_____________________________________________________________________________
191 void AliMpRow::AddRowSegmentInFront(AliMpVRowSegment* rowSegment)
193 // Inserts row segment in the first vector position.
197 fSegments.insert(fSegments.begin(), rowSegment);
201 fSegments.AddFirst(rowSegment);
205 //_____________________________________________________________________________
206 AliMpVRowSegment* AliMpRow::FindRowSegment(Double_t x) const
208 // Finds the row segment for the specified x position;
209 // returns 0 if no row segment is found.
212 for (Int_t i=0; i<GetNofRowSegments(); i++) {
215 AliMpVRowSegment* rs = fSegments[i];
218 AliMpVRowSegment* rs = (AliMpVRowSegment*)fSegments.At(i);
221 if (x >= rs->LeftBorderX() && x <= rs->RightBorderX())
228 //_____________________________________________________________________________
229 Double_t AliMpRow::LowBorderY() const
231 // Returns the lowest row offset (the Y coordinate of the position of the
232 // low border of motif).
237 return fOffsetY - GetRowSegment(0)->HalfSizeY();
240 //_____________________________________________________________________________
241 Double_t AliMpRow::UpperBorderY() const
243 // Returns the uppermost row offset (the Y coordinate of the position of the
244 // upper border of motif).
249 return fOffsetY + GetRowSegment(0)->HalfSizeY();
252 //_____________________________________________________________________________
253 AliMpVPadIterator* AliMpRow::CreateIterator() const
255 // Iterator is not yet implemented.
258 Fatal("CreateIterator", "Iterator is not yet implemented.");
263 //_____________________________________________________________________________
264 void AliMpRow::SetMotifPositions()
266 // Creates motif positions objects and fills them in the motif map.
271 for (Int_t j=0; j<GetNofRowSegments(); j++) {
272 AliMpVRowSegment* rowSegment = GetRowSegment(j);
274 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
276 Int_t motifPositionId = rowSegment->GetMotifPositionId(k);
277 AliMpVMotif* motif = rowSegment->GetMotif(k);
278 TVector2 position = rowSegment->MotifCenter(motifPositionId);
280 AliMpMotifPosition* motifPosition
281 = new AliMpMotifPosition(motifPositionId, motif, position);
282 // set the initial value to of HighIndicesLimit() Invalid()
283 // (this is used for calculation of indices in case of
284 // special row segments)
285 motifPosition->SetHighIndicesLimit(AliMpIntPair::Invalid());
287 //Bool_t warn = (rowSegment->GetNofMotifs()==1);
289 if (dynamic_cast<AliMpVRowSegmentSpecial*>(rowSegment)) warn = false;
290 // supress warnings for special row segments
291 // which motifs can overlap the row borders
293 Bool_t added = GetMotifMap()->AddMotifPosition(motifPosition, warn);
295 if (!added) delete motifPosition;
300 //_____________________________________________________________________________
301 void AliMpRow::SetGlobalIndices(AliMpDirection constPadSizeDirection,
304 // Sets the global indices limits to its row segments,
308 Int_t ix = AliMpConstants::StartPadIndex();
309 Int_t iy = AliMpConstants::StartPadIndex();
311 for (Int_t j=0; j<GetNofRowSegments(); j++) {
312 AliMpVRowSegment* rowSegment = GetRowSegment(j);
314 ix += rowSegment->GetLowIndicesLimit().GetFirst();
316 for (Int_t k=0; k<rowSegment->GetNofMotifs(); k++) {
318 // Find the y index value of the low edge
320 if (constPadSizeDirection == kY) {
321 iy = rowBefore->GetHighIndicesLimit().GetSecond()+1;
324 AliMpVRowSegment* seg = rowBefore->FindRowSegment(ix);
325 AliMpMotifPosition* motPos = FindMotifPosition(seg, ix);
326 if (!dynamic_cast<AliMpRowSegmentRSpecial*>(rowSegment)) {
328 Fatal("SetGlobalIndices", "Motif position in rowBefore not found.");
330 iy = motPos->GetHighIndicesLimit().GetSecond()+1;
335 // Set (ix, iy) to k-th motif position and update ix
336 ix = rowSegment->SetIndicesToMotifPosition(k, AliMpIntPair(ix, iy));
338 rowSegment->SetGlobalIndices();
341 SetLowIndicesLimit(GetRowSegment(0)->GetLowIndicesLimit());
342 SetHighIndicesLimit(GetRowSegment(GetNofRowSegments()-1)->GetHighIndicesLimit());
347 //_____________________________________________________________________________
348 TVector2 AliMpRow::Position() const
350 // Returns the position of the row centre.
353 Double_t x = (GetRowSegment(0)->LeftBorderX() +
354 GetRowSegment(GetNofRowSegments()-1)->RightBorderX())/2.;
356 Double_t y = fOffsetY;
358 return TVector2(x, y);
361 //_____________________________________________________________________________
362 TVector2 AliMpRow::Dimensions() const
364 // Returns the maximum halflengths of the row in x, y.
367 Double_t x = (GetRowSegment(GetNofRowSegments()-1)->RightBorderX() -
368 GetRowSegment(0)->LeftBorderX())/2.;
370 Double_t y = GetRowSegment(0)->HalfSizeY();
372 return TVector2(x, y);
375 //_____________________________________________________________________________
376 void AliMpRow::SetRowSegmentOffsets(const TVector2& offset)
378 // Sets the row segments offsets in X .
383 AliMpVRowSegment* previous = 0;
385 for (Int_t j=0; j<GetNofRowSegments(); j++) {
386 AliMpVRowSegment* rowSegment = GetRowSegment(j);
390 offsetX = previous->RightBorderX();
392 offsetX = offset.X();
394 rowSegment->SetOffset(TVector2(offsetX, 0.));
395 previous = rowSegment;
400 //_____________________________________________________________________________
401 Double_t AliMpRow::SetOffsetY(Double_t offsetY)
403 // Sets the row offset (the Y coordinate of the position of the
404 // center of motif) and returns the offset of the top border.
409 AliMpVRowSegment* first = GetRowSegment(0);
410 Double_t rowSizeY = first->HalfSizeY();
412 // Check if all next row segments have motif of
413 // the same size in y
414 for (Int_t i=1; i<GetNofRowSegments(); i++) {
415 Double_t sizeY = GetRowSegment(i)->HalfSizeY();
417 if (TMath::Abs(sizeY - rowSizeY) >= AliMpConstants::LengthTolerance()) {
418 //cout << GetID() << "th row " << i << "th segment "
419 // << sizeY << " " << rowSizeY << endl;
420 Fatal("SetOffsetY", "Motif with different Y size in one row");
425 offsetY += rowSizeY ;
429 return offsetY += rowSizeY;
432 //_____________________________________________________________________________
433 Int_t AliMpRow::GetNofRowSegments() const
435 // Returns number of row segments.
439 return fSegments.size();
443 return fSegments.GetSize();
447 //_____________________________________________________________________________
448 AliMpVRowSegment* AliMpRow::GetRowSegment(Int_t i) const
450 // Returns i-th row segment.
453 if (i<0 || i>=GetNofRowSegments()) {
454 Warning("GetRowSegment", "Index outside range");
463 return (AliMpVRowSegment*)fSegments.At(i);