]>
Commit | Line | Data |
---|---|---|
dee1d5f1 | 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 | ||
5f91c9e8 | 16 | // $Id$ |
13985652 | 17 | // $MpId: AliMpPad.cxx,v 1.9 2006/05/24 13:58:29 ivana Exp $ |
5f91c9e8 | 18 | // Category: basic |
3d1463c8 | 19 | |
20 | //----------------------------------------------------------------------------- | |
5f91c9e8 | 21 | // Class AliMpPad |
22 | // --------------- | |
23 | // Class which encapsuate all informations about a pad | |
dbe945cc | 24 | // Included in AliRoot: 2003/05/02 |
5f91c9e8 | 25 | // Authors: David Guez, Ivana Hrivnacova; IPN Orsay |
2100f1c2 | 26 | // root [0] .x testSectorAreaIterator.C |
27 | // Real time 0:00:56, CP time 36.270 | |
3d1463c8 | 28 | //----------------------------------------------------------------------------- |
5f91c9e8 | 29 | |
5f91c9e8 | 30 | #include "AliMpPad.h" |
2100f1c2 | 31 | #include "AliLog.h" |
5f91c9e8 | 32 | |
2c605e66 | 33 | #include <TClonesArray.h> |
34 | #include <Riostream.h> | |
35 | ||
13985652 | 36 | /// \cond CLASSIMP |
5f91c9e8 | 37 | ClassImp(AliMpPad) |
13985652 | 38 | /// \endcond |
5f91c9e8 | 39 | |
2100f1c2 | 40 | const Int_t AliMpPad::fgkMaxNofLocations = 6; |
41 | ||
5f91c9e8 | 42 | // |
43 | // foreign operators | |
44 | // | |
45 | ||
46 | //_____________________________________________________________________________ | |
47 | Bool_t operator==(const TVector2& v1,const TVector2& v2) | |
48 | { | |
c9d734d4 | 49 | return v1.X()==v2.X() && v1.Y()==v2.Y(); |
5f91c9e8 | 50 | } |
51 | ||
52 | ||
53 | //_____________________________________________________________________________ | |
54 | ostream& operator<<(ostream& out,const TVector2& v) | |
55 | { | |
56 | out << '(' << v.X() << ',' << v.Y() << ')'; | |
57 | return out; | |
58 | } | |
59 | ||
2100f1c2 | 60 | |
5f91c9e8 | 61 | //_____________________________________________________________________________ |
62 | AliMpPad::AliMpPad(const AliMpIntPair& location,const AliMpIntPair& indices, | |
63 | const TVector2& position,const TVector2& dimensions, | |
64 | Bool_t validity) | |
65 | : TObject(), | |
2100f1c2 | 66 | fLocations(0), |
c9d734d4 | 67 | #ifdef WITH_ROOT |
68 | fNofLocations(0), | |
69 | #endif | |
5f91c9e8 | 70 | fLocation(location), |
71 | fIndices(indices), | |
72 | fPosition(position), | |
73 | fDimensions(dimensions), | |
74 | fValidity(validity) | |
75 | { | |
dee1d5f1 | 76 | /// Standard constructor \n |
77 | /// Be carefull : this constructor doesn't check the validity of | |
78 | /// the correspondance between location and indices. | |
79 | /// By default, validity is set true. | |
80 | /// It is aimed to be used by MSegmentation methods, and never from outside.... | |
5f91c9e8 | 81 | } |
82 | ||
83 | ||
84 | //_____________________________________________________________________________ | |
85 | AliMpPad::AliMpPad() | |
86 | : TObject(), | |
2100f1c2 | 87 | fLocations(0), |
c9d734d4 | 88 | #ifdef WITH_ROOT |
89 | fNofLocations(0), | |
90 | #endif | |
5f91c9e8 | 91 | fLocation(AliMpIntPair::Invalid()), |
92 | fIndices(AliMpIntPair::Invalid()), | |
93 | fPosition(-1.,-1.), | |
94 | fDimensions(0.,0.), | |
95 | fValidity(false) | |
96 | { | |
dee1d5f1 | 97 | /// Default constructor - creates pad in invalid state |
5f91c9e8 | 98 | } |
99 | ||
100 | ||
101 | //_____________________________________________________________________________ | |
2100f1c2 | 102 | AliMpPad::AliMpPad(const AliMpPad& rhs) |
0471c97b | 103 | : TObject(rhs), |
104 | fLocations(0), | |
c9d734d4 | 105 | #ifdef WITH_ROOT |
106 | fNofLocations(0), | |
107 | #endif | |
0471c97b | 108 | fLocation(AliMpIntPair::Invalid()), |
109 | fIndices(AliMpIntPair::Invalid()), | |
110 | fPosition(-1.,-1.), | |
111 | fDimensions(0.,0.), | |
112 | fValidity(false) | |
5f91c9e8 | 113 | { |
dee1d5f1 | 114 | /// Copy constructor |
115 | ||
2100f1c2 | 116 | *this = rhs; |
5f91c9e8 | 117 | } |
118 | ||
119 | //_____________________________________________________________________________ | |
dee1d5f1 | 120 | AliMpPad::~AliMpPad() |
121 | { | |
122 | /// Destructor | |
2100f1c2 | 123 | |
c9d734d4 | 124 | #ifdef WITH_STL |
125 | delete fLocations; | |
2100f1c2 | 126 | #endif |
127 | ||
c9d734d4 | 128 | #ifdef WITH_ROOT |
129 | delete [] fLocations; | |
130 | #endif | |
5f91c9e8 | 131 | } |
132 | ||
133 | //_____________________________________________________________________________ | |
2100f1c2 | 134 | AliMpPad& AliMpPad::operator = (const AliMpPad& rhs) |
5f91c9e8 | 135 | { |
dee1d5f1 | 136 | /// Assignment operator |
137 | ||
138 | // check assignment to self | |
2100f1c2 | 139 | if (this == &rhs) return *this; |
5f91c9e8 | 140 | |
dee1d5f1 | 141 | // base class assignment |
2100f1c2 | 142 | TObject::operator=(rhs); |
5f91c9e8 | 143 | |
dee1d5f1 | 144 | // assignment operator |
2100f1c2 | 145 | fLocation = rhs.fLocation; |
146 | fIndices = rhs.fIndices; | |
147 | fPosition.Set(rhs.fPosition); | |
148 | fDimensions.Set(rhs.fDimensions); | |
149 | fValidity = rhs.fValidity; | |
150 | ||
151 | fLocations = 0; | |
152 | ||
153 | #ifdef WITH_STL | |
154 | if ( rhs.GetNofLocations() ) { | |
155 | fLocations = new IntPairVector(rhs.GetNofLocations()); | |
156 | ||
157 | for (Int_t i=0; i<rhs.GetNofLocations(); i++) | |
158 | (*fLocations)[i] = rhs.GetLocation(i); | |
159 | } | |
160 | #endif | |
161 | ||
162 | #ifdef WITH_ROOT | |
c9d734d4 | 163 | fNofLocations = rhs.fNofLocations; |
2100f1c2 | 164 | if ( rhs.GetNofLocations() ) { |
c9d734d4 | 165 | fLocations = new AliMpIntPair[fgkMaxNofLocations]; |
166 | for ( UInt_t i=0; i<rhs.fNofLocations; i++ ) | |
167 | fLocations[i] = rhs.fLocations[i]; | |
2100f1c2 | 168 | } |
169 | #endif | |
5f91c9e8 | 170 | |
171 | return *this; | |
172 | } | |
173 | ||
174 | //_____________________________________________________________________________ | |
2100f1c2 | 175 | Bool_t AliMpPad::operator == (const AliMpPad& rhs) const |
5f91c9e8 | 176 | { |
dee1d5f1 | 177 | /// Equality operator |
178 | ||
2100f1c2 | 179 | // are this and rhs equals? |
5f91c9e8 | 180 | |
181 | // one valid, one invalid | |
2100f1c2 | 182 | if (fValidity != rhs.fValidity) return false; |
5f91c9e8 | 183 | |
184 | // both invalid | |
185 | if (!fValidity) return true; | |
186 | ||
187 | // both valid | |
2100f1c2 | 188 | Bool_t sameLocations = true; |
189 | ||
190 | if (rhs.GetNofLocations()) { | |
191 | for (Int_t i=0; i<rhs.GetNofLocations(); i++) | |
192 | if ( GetLocation(i) != rhs.GetLocation(i) ) | |
193 | sameLocations = false; | |
194 | } | |
195 | ||
196 | return (fLocation == rhs.fLocation) | |
197 | && (fIndices == rhs.fIndices) | |
198 | && (fPosition == rhs.fPosition) | |
199 | && (fDimensions == rhs.fDimensions) | |
200 | && sameLocations; | |
5f91c9e8 | 201 | } |
202 | //_____________________________________________________________________________ | |
2100f1c2 | 203 | Bool_t AliMpPad::operator != (const AliMpPad& rhs) const |
5f91c9e8 | 204 | { |
dee1d5f1 | 205 | /// Non-equality operator |
206 | ||
2100f1c2 | 207 | // are this and rhs equals? |
208 | return !(*this==rhs); | |
5f91c9e8 | 209 | } |
210 | ||
211 | //_____________________________________________________________________________ | |
2100f1c2 | 212 | Bool_t operator < (const AliMpPad& left, const AliMpPad& right) |
5f91c9e8 | 213 | { |
2100f1c2 | 214 | /// Less operator |
dee1d5f1 | 215 | |
2100f1c2 | 216 | return left.GetIndices()<right.GetIndices(); |
5f91c9e8 | 217 | } |
218 | ||
219 | //_____________________________________________________________________________ | |
2100f1c2 | 220 | Bool_t AliMpPad::AddLocation(const AliMpIntPair& location, Bool_t warn) |
5f91c9e8 | 221 | { |
2100f1c2 | 222 | /// Add location to the collection if not yet present and |
223 | /// if collection is not yet full \n | |
224 | /// Return false and optionally give a warning if location is not | |
225 | /// added. | |
dee1d5f1 | 226 | |
2100f1c2 | 227 | // Check maximum number limit |
228 | if ( GetNofLocations() == fgkMaxNofLocations ) { | |
229 | if (warn) { | |
230 | AliWarningStream() << "Cannot add location: " | |
231 | << location | |
232 | << " Maximum number has been reached." << endl; | |
233 | } | |
234 | return false; | |
235 | } | |
236 | ||
237 | // Check if location is present | |
238 | if ( HasLocation(location) ) { | |
239 | if (warn) { | |
240 | AliWarningStream() << "Cannot add location: " | |
241 | << location | |
242 | << " Location is already present." << endl; | |
243 | } | |
244 | return false; | |
245 | } | |
246 | ||
247 | // Add location | |
248 | #ifdef WITH_STL | |
249 | if (! fLocations ) | |
250 | fLocations = new IntPairVector(); | |
251 | ||
252 | fLocations->push_back(location); | |
253 | return true; | |
254 | #endif | |
255 | ||
256 | #ifdef WITH_ROOT | |
c9d734d4 | 257 | if ( ! fLocations) |
258 | fLocations = new AliMpIntPair[fgkMaxNofLocations]; | |
259 | ||
260 | fLocations[fNofLocations++] = location; | |
2100f1c2 | 261 | return true; |
262 | #endif | |
263 | } | |
264 | ||
265 | //_____________________________________________________________________________ | |
266 | void AliMpPad::PrintOn(ostream& out) const | |
267 | { | |
268 | /// Prints all pad data. | |
269 | ||
270 | if ( !fValidity ) { | |
271 | out << "Pad::Invalid"; | |
272 | return; | |
273 | } | |
274 | ||
275 | out << "Pad: Location " << fLocation | |
276 | << " Indices " << fIndices | |
277 | << " Position " << fPosition | |
278 | << " Dimensions " << fDimensions; | |
279 | ||
280 | if ( GetNofLocations() ) { | |
281 | out << endl; | |
282 | out << " Other locations: "; | |
283 | ||
284 | for (Int_t i=0; i<GetNofLocations(); i++) | |
285 | out << GetLocation(i) << " "; | |
286 | } | |
5f91c9e8 | 287 | } |
288 | ||
289 | //_____________________________________________________________________________ | |
2998a151 | 290 | void AliMpPad::Print(const char* /*option*/) const |
5f91c9e8 | 291 | { |
dee1d5f1 | 292 | /// Prints all pad data. |
5f91c9e8 | 293 | |
2100f1c2 | 294 | PrintOn(cout); |
295 | cout << endl; | |
296 | } | |
297 | ||
298 | //_____________________________________________________________________________ | |
299 | Int_t AliMpPad::GetNofLocations() const | |
300 | { | |
301 | /// Return number of other locations associated with this pad | |
302 | ||
303 | if (!fLocations) return 0; | |
304 | ||
305 | #ifdef WITH_STL | |
306 | return fLocations->size(); | |
307 | #endif | |
308 | ||
309 | #ifdef WITH_ROOT | |
c9d734d4 | 310 | return fNofLocations; |
2100f1c2 | 311 | #endif |
312 | } | |
313 | ||
314 | ||
315 | //_____________________________________________________________________________ | |
316 | AliMpIntPair AliMpPad::GetLocation(Int_t i) const | |
317 | { | |
318 | /// Return i-th other location associated with this pad | |
319 | ||
320 | if ( !fLocations || i<0 || i>=GetNofLocations() ) | |
321 | return AliMpIntPair::Invalid(); | |
322 | ||
323 | #ifdef WITH_STL | |
324 | return (*fLocations)[i]; | |
325 | #endif | |
326 | ||
327 | #ifdef WITH_ROOT | |
c9d734d4 | 328 | return fLocations[i]; |
2100f1c2 | 329 | #endif |
330 | } | |
331 | ||
332 | //_____________________________________________________________________________ | |
333 | Bool_t AliMpPad::HasLocation(const AliMpIntPair& location) const | |
334 | { | |
335 | /// Return true if given location is present either as fLocation | |
336 | /// or in the collectio | |
337 | ||
338 | if (fLocation == location) return true; | |
339 | ||
c9d734d4 | 340 | for ( Int_t i=0; i<GetNofLocations(); i++ ) { |
2100f1c2 | 341 | if ( GetLocation(i) == location ) return true; |
5f91c9e8 | 342 | } |
2100f1c2 | 343 | |
344 | return false; | |
345 | } | |
346 | ||
347 | //_____________________________________________________________________________ | |
348 | ostream& operator<< (ostream &out, const AliMpPad& pad) | |
349 | { | |
350 | /// Output streaming | |
351 | ||
352 | pad.PrintOn(out); | |
353 | ||
354 | return out; | |
5f91c9e8 | 355 | } |
356 |