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