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