]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpPadRow.cxx
Corrected delete
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpPadRow.cxx
1 // $Id$
2 // --------------------------------------------------------
3 // Category: sector
4 //
5 // Class AliMpPadRow
6 // ------------------
7 // Class describing a pad row composed of the pad row segments.
8 // Included in AliRoot: 2003/05/02
9 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
10
11 #include <TError.h>
12
13 #include "AliMpPadRow.h"
14 #include "AliMpPadRowLSegment.h"
15 #include "AliMpPadRowRSegment.h"
16
17 ClassImp(AliMpPadRow)
18
19 //_____________________________________________________________________________
20 AliMpPadRow::AliMpPadRow(AliMpXDirection direction) 
21   : TObject(),
22     fDirection(direction), 
23     fID(0)
24 {
25 //
26 }
27
28 //_____________________________________________________________________________
29 AliMpPadRow::AliMpPadRow() 
30   : TObject(),
31     fDirection(kLeft), 
32     fID(0)
33 {
34 //
35 }
36
37 //_____________________________________________________________________________
38 AliMpPadRow::~AliMpPadRow() {
39 //  
40
41   for (Int_t i=0; i<GetNofPadRowSegments() ; i++)
42     delete fSegments[i];
43 }
44
45 //
46 // private methods
47 //
48
49 //_____________________________________________________________________________
50 Double_t AliMpPadRow::CurrentBorderX() const
51 {
52 // Returns the left/right x border 
53 // (depending on the direction which the row segments are filled in).
54 // ---
55
56   if (GetNofPadRowSegments() == 0)
57       return fOffsetX;
58   else 
59     if (fDirection == kLeft)
60       return GetPadRowSegment(GetNofPadRowSegments()-1)->LeftBorderX();
61     else  
62       return GetPadRowSegment(GetNofPadRowSegments()-1)->RightBorderX();
63 }
64
65 //
66 // public methods
67 //
68
69 //_____________________________________________________________________________
70 AliMpVPadRowSegment* 
71 AliMpPadRow::AddPadRowSegment(AliMpMotif* motif, Int_t motifPositionId,
72                               Int_t nofPads)
73 {
74 // Adds pad row segment.
75 // ---
76
77   AliMpVPadRowSegment* padRowSegment = 0;
78
79   if (fDirection == kLeft) {
80     padRowSegment 
81       = new AliMpPadRowLSegment(this, motif, motifPositionId, nofPads);
82   }    
83   else  {
84     padRowSegment 
85       = new AliMpPadRowRSegment(this, motif, motifPositionId, nofPads);
86   }     
87
88   // Set pad row segment offset
89   padRowSegment->SetOffsetX(CurrentBorderX());
90
91   // Adds the pad row segment
92 #ifdef WITH_STL
93   fSegments.push_back(padRowSegment);
94 #endif
95
96 #ifdef WITH_ROOT
97   fSegments.Add(padRowSegment);
98 #endif
99   
100   return padRowSegment;
101 }  
102   
103 //_____________________________________________________________________________
104 AliMpVPadRowSegment* AliMpPadRow::FindPadRowSegment(Double_t x) const
105 {
106 // Finds the row segment for the specified x position;
107 // returns 0 if no row segment is found.
108 // ---
109
110   for (Int_t i=0; i<GetNofPadRowSegments(); i++) {
111     AliMpVPadRowSegment* rs = GetPadRowSegment(i);
112     if (x >= rs->LeftBorderX() && x <= rs->RightBorderX())
113       return rs;
114   }
115   
116   return 0;    
117 }    
118
119 //_____________________________________________________________________________
120 Double_t  AliMpPadRow::HalfSizeY() const
121 {
122   return GetPadRowSegment(0)->HalfSizeY();
123 }
124
125 //_____________________________________________________________________________
126 void  AliMpPadRow::SetID(Int_t id)
127 {
128 // Sets the ID.
129 // ---
130
131   fID = id;
132 }    
133
134 //_____________________________________________________________________________
135 void  AliMpPadRow::SetOffsetX(Double_t offsetX)
136 {
137 // Sets the x offset.
138 // ---
139
140   fOffsetX = offsetX;
141 }    
142
143 //_____________________________________________________________________________
144 Int_t AliMpPadRow::GetID() const 
145 {
146 // Returns the row ID.
147 // ---
148
149   return fID;
150 }  
151
152 //_____________________________________________________________________________
153 Int_t AliMpPadRow::GetNofPadRowSegments() const 
154 {
155 // Returns number of row segments.
156 // ---
157
158 #ifdef WITH_STL
159   return fSegments.size();
160 #endif
161
162 #ifdef WITH_ROOT
163   return fSegments.GetEntriesFast();
164 #endif
165 }  
166
167 //_____________________________________________________________________________
168 AliMpVPadRowSegment* AliMpPadRow::GetPadRowSegment(Int_t i) const 
169 {
170 // Returns pad row segment with specified number.
171 // ---
172
173   if (i<0 || i>=GetNofPadRowSegments()) {
174     Warning("GetRowSegment", "Index outside range");
175     return 0;
176   }
177   
178 #ifdef WITH_STL
179   return fSegments[i];  
180 #endif
181
182 #ifdef WITH_ROOT
183   return (AliMpVPadRowSegment*)fSegments[i];  
184 #endif
185 }
186
187 //_____________________________________________________________________________
188 Int_t AliMpPadRow::GetNofPads() const 
189 {
190 // Returns number of pads in this pad row.
191 // ---
192
193   Int_t nofPads=0;
194   for (Int_t i=0; i<GetNofPadRowSegments(); i++)
195     nofPads += GetPadRowSegment(i)->GetNofPads();
196
197   return nofPads;
198 }  
199