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