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