]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - MUON/MUONmapping/AliMpRow.cxx
MUON + CheckCompiler
[u/mrichter/AliRoot.git] / MUON / MUONmapping / AliMpRow.cxx
... / ...
CommitLineData
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"
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"
37
38#include "AliLog.h"
39
40#include <TMath.h>
41#include <Riostream.h>
42
43using std::endl;
44/// \cond CLASSIMP
45ClassImp(AliMpRow)
46/// \endcond
47
48//_____________________________________________________________________________
49AliMpRow::AliMpRow(Int_t id, AliMpMotifMap* motifMap)
50 : AliMpVIndexed(),
51 fID(id),
52 fOffsetY(0.),
53 fSegments(),
54 fMotifMap(motifMap)
55{
56/// Standard constructor
57}
58
59//_____________________________________________________________________________
60AliMpRow::AliMpRow()
61 : AliMpVIndexed(),
62 fID(0),
63 fOffsetY(0.),
64 fSegments(),
65 fMotifMap(0)
66{
67/// Default constructor
68}
69
70//_____________________________________________________________________________
71AliMpRow::~AliMpRow()
72{
73/// Destructor
74
75 fSegments.Delete();
76}
77
78//
79// private methods
80//
81
82//_____________________________________________________________________________
83AliMpVRowSegment* AliMpRow::FindRowSegment(Int_t ix) const
84{
85/// Find first normal row segment with low indices limit >= ix.
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//_____________________________________________________________________________
100AliMpMotifPosition*
101AliMpRow::FindMotifPosition(AliMpVRowSegment* segment, Int_t ix) const
102{
103/// Find first motif position in the specified row segment
104/// with high indices limit >= ix.
105
106 if (!segment) return 0;
107
108 for (Int_t i=0; i<segment->GetNofMotifs(); i++){
109 AliMpMotifPosition* motifPosition
110 = GetMotifMap()->FindMotifPosition(segment->GetMotifPositionId(i));
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//_____________________________________________________________________________
126void AliMpRow::SetHighIndicesLimits(Int_t iy)
127{
128/// Set the global indices high limit to its row segments,
129/// motif positions with a given value.
130/// Keep ix unmodified.
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//_____________________________________________________________________________
151void AliMpRow::CheckEmpty() const
152{
153/// Give a fatal if the row is empty.
154
155 if (GetNofRowSegments() == 0)
156 Fatal("CheckEmpty", "Empty row");
157}
158
159//
160// public methods
161//
162
163//_____________________________________________________________________________
164void AliMpRow::AddRowSegment(AliMpVRowSegment* rowSegment)
165{
166/// Add row segment at the end.
167
168 fSegments.Add(rowSegment);
169}
170
171//_____________________________________________________________________________
172void AliMpRow::AddRowSegmentInFront(AliMpVRowSegment* rowSegment)
173{
174/// Insert row segment in the first vector position.
175
176 fSegments.AddFirst(rowSegment);
177}
178
179//_____________________________________________________________________________
180AliMpVRowSegment* AliMpRow::FindRowSegment(Double_t x) const
181{
182/// Find the row segment for the specified x position;
183/// return 0 if no row segment is found.
184
185 for (Int_t i=0; i<GetNofRowSegments(); i++) {
186
187 AliMpVRowSegment* rs = (AliMpVRowSegment*)fSegments.At(i);
188
189 if (x >= rs->LeftBorderX() && x <= rs->RightBorderX())
190 return rs;
191 }
192
193 return 0;
194}
195
196//_____________________________________________________________________________
197Double_t AliMpRow::LowBorderY() const
198{
199/// Return the lowest row offset (the Y coordinate of the position of the
200/// low border of motif).
201
202 CheckEmpty();
203
204 return fOffsetY - GetRowSegment(0)->HalfSizeY();
205}
206
207//_____________________________________________________________________________
208Double_t AliMpRow::UpperBorderY() const
209{
210/// Return the uppermost row offset (the Y coordinate of the position of the
211/// upper border of motif).
212\
213 CheckEmpty();
214
215 return fOffsetY + GetRowSegment(0)->HalfSizeY();
216}
217
218//_____________________________________________________________________________
219AliMpVPadIterator* AliMpRow::CreateIterator() const
220{
221/// Iterator is not implemented.
222
223 Fatal("CreateIterator", "Iterator is not implemented.");
224
225 return 0;
226}
227
228//_____________________________________________________________________________
229void AliMpRow::SetMotifPositions()
230{
231/// Create motif positions objects and fills them in the motif map.
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//_____________________________________________________________________________
268void AliMpRow::SetGlobalIndices(AliMp::Direction constPadSizeDirection,
269 AliMpRow* rowBefore)
270{
271/// Set the global indices limits to its row segments, motif positions
272/// and itself.
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//_____________________________________________________________________________
338Double_t AliMpRow::GetPositionX() const
339{
340/// Return the position of the row centre.
341
342 return ( GetRowSegment(0)->LeftBorderX() +
343 GetRowSegment(GetNofRowSegments()-1)->RightBorderX() )/2.;
344}
345
346//_____________________________________________________________________________
347Double_t AliMpRow::GetPositionY() const
348{
349/// Return the position of the row centre.
350
351 return fOffsetY;
352}
353
354//_____________________________________________________________________________
355Double_t AliMpRow::GetDimensionX() const
356{
357/// Return the maximum halflengths of the row in x, y.
358
359 return ( GetRowSegment(GetNofRowSegments()-1)->RightBorderX() -
360 GetRowSegment(0)->LeftBorderX() )/2.;
361}
362
363//_____________________________________________________________________________
364Double_t AliMpRow::GetDimensionY() const
365{
366/// Return the maximum halflengths of the row in x, y.
367
368 return GetRowSegment(0)->HalfSizeY();
369}
370
371//_____________________________________________________________________________
372void AliMpRow::SetRowSegmentOffsets(Double_t offsetx)
373{
374/// Set the row segments offsets in X .
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//_____________________________________________________________________________
396Double_t AliMpRow::SetOffsetY(Double_t offsetY)
397{
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.
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//_____________________________________________________________________________
425Int_t AliMpRow::GetNofRowSegments() const
426{
427/// Return number of row segments.
428
429 return fSegments.GetSize();
430}
431
432//_____________________________________________________________________________
433AliMpVRowSegment* AliMpRow::GetRowSegment(Int_t i) const
434{
435/// Return i-th row segment.
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