Updated comments for Doxygen - corrected warnings
[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)
95 : TObject(rhs)
5f91c9e8 96{
dee1d5f1 97/// Copy constructor
98
2100f1c2 99 *this = rhs;
5f91c9e8 100}
101
102//_____________________________________________________________________________
dee1d5f1 103AliMpPad::~AliMpPad()
104{
105/// Destructor
2100f1c2 106
107#ifdef WITH_ROOT
108 if (fLocations) fLocations->Delete();
109#endif
110
111 delete fLocations;
5f91c9e8 112}
113
114//_____________________________________________________________________________
2100f1c2 115AliMpPad& AliMpPad::operator = (const AliMpPad& rhs)
5f91c9e8 116{
dee1d5f1 117/// Assignment operator
118
119 // check assignment to self
2100f1c2 120 if (this == &rhs) return *this;
5f91c9e8 121
dee1d5f1 122 // base class assignment
2100f1c2 123 TObject::operator=(rhs);
5f91c9e8 124
dee1d5f1 125 // assignment operator
2100f1c2 126 fLocation = rhs.fLocation;
127 fIndices = rhs.fIndices;
128 fPosition.Set(rhs.fPosition);
129 fDimensions.Set(rhs.fDimensions);
130 fValidity = rhs.fValidity;
131
132 fLocations = 0;
133
134#ifdef WITH_STL
135 if ( rhs.GetNofLocations() ) {
136 fLocations = new IntPairVector(rhs.GetNofLocations());
137
138 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
139 (*fLocations)[i] = rhs.GetLocation(i);
140 }
141#endif
142
143#ifdef WITH_ROOT
144 if ( rhs.GetNofLocations() ) {
145 fLocations = new TClonesArray("AliMpIntPair", rhs.GetNofLocations());
146
147 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
148 new((*fLocations)[i]) AliMpIntPair(rhs.GetLocation(i));
149 }
150#endif
5f91c9e8 151
152 return *this;
153}
154
155//_____________________________________________________________________________
2100f1c2 156Bool_t AliMpPad::operator == (const AliMpPad& rhs) const
5f91c9e8 157{
dee1d5f1 158/// Equality operator
159
2100f1c2 160 // are this and rhs equals?
5f91c9e8 161
162 // one valid, one invalid
2100f1c2 163 if (fValidity != rhs.fValidity) return false;
5f91c9e8 164
165 // both invalid
166 if (!fValidity) return true;
167
168 // both valid
2100f1c2 169 Bool_t sameLocations = true;
170
171 if (rhs.GetNofLocations()) {
172 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
173 if ( GetLocation(i) != rhs.GetLocation(i) )
174 sameLocations = false;
175 }
176
177 return (fLocation == rhs.fLocation)
178 && (fIndices == rhs.fIndices)
179 && (fPosition == rhs.fPosition)
180 && (fDimensions == rhs.fDimensions)
181 && sameLocations;
5f91c9e8 182}
183//_____________________________________________________________________________
2100f1c2 184Bool_t AliMpPad::operator != (const AliMpPad& rhs) const
5f91c9e8 185{
dee1d5f1 186/// Non-equality operator
187
2100f1c2 188 // are this and rhs equals?
189 return !(*this==rhs);
5f91c9e8 190}
191
192//_____________________________________________________________________________
2100f1c2 193Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
5f91c9e8 194{
2100f1c2 195/// Less operator
dee1d5f1 196
2100f1c2 197 return left.GetIndices()<right.GetIndices();
5f91c9e8 198}
199
200//_____________________________________________________________________________
2100f1c2 201Bool_t AliMpPad::AddLocation(const AliMpIntPair& location, Bool_t warn)
5f91c9e8 202{
2100f1c2 203/// Add location to the collection if not yet present and
204/// if collection is not yet full \n
205/// Return false and optionally give a warning if location is not
206/// added.
dee1d5f1 207
2100f1c2 208 // Check maximum number limit
209 if ( GetNofLocations() == fgkMaxNofLocations ) {
210 if (warn) {
211 AliWarningStream() << "Cannot add location: "
212 << location
213 << " Maximum number has been reached." << endl;
214 }
215 return false;
216 }
217
218 // Check if location is present
219 if ( HasLocation(location) ) {
220 if (warn) {
221 AliWarningStream() << "Cannot add location: "
222 << location
223 << " Location is already present." << endl;
224 }
225 return false;
226 }
227
228 // Add location
229#ifdef WITH_STL
230 if (! fLocations )
231 fLocations = new IntPairVector();
232
233 fLocations->push_back(location);
234 return true;
235#endif
236
237#ifdef WITH_ROOT
238 if (! fLocations)
239 fLocations = new TClonesArray("AliMpIntPair", fgkMaxNofLocations);
240
241 new ((*fLocations)[GetNofLocations()]) AliMpIntPair(location);
242 return true;
243#endif
244}
245
246//_____________________________________________________________________________
247void AliMpPad::PrintOn(ostream& out) const
248{
249/// Prints all pad data.
250
251 if ( !fValidity ) {
252 out << "Pad::Invalid";
253 return;
254 }
255
256 out << "Pad: Location " << fLocation
257 << " Indices " << fIndices
258 << " Position " << fPosition
259 << " Dimensions " << fDimensions;
260
261 if ( GetNofLocations() ) {
262 out << endl;
263 out << " Other locations: ";
264
265 for (Int_t i=0; i<GetNofLocations(); i++)
266 out << GetLocation(i) << " ";
267 }
5f91c9e8 268}
269
270//_____________________________________________________________________________
2998a151 271void AliMpPad::Print(const char* /*option*/) const
5f91c9e8 272{
dee1d5f1 273/// Prints all pad data.
5f91c9e8 274
2100f1c2 275 PrintOn(cout);
276 cout << endl;
277}
278
279//_____________________________________________________________________________
280Int_t AliMpPad::GetNofLocations() const
281{
282/// Return number of other locations associated with this pad
283
284 if (!fLocations) return 0;
285
286#ifdef WITH_STL
287 return fLocations->size();
288#endif
289
290#ifdef WITH_ROOT
291 return fLocations->GetEntriesFast();
292#endif
293}
294
295
296//_____________________________________________________________________________
297AliMpIntPair AliMpPad::GetLocation(Int_t i) const
298{
299/// Return i-th other location associated with this pad
300
301 if ( !fLocations || i<0 || i>=GetNofLocations() )
302 return AliMpIntPair::Invalid();
303
304#ifdef WITH_STL
305 return (*fLocations)[i];
306#endif
307
308#ifdef WITH_ROOT
309 return *(AliMpIntPair*)fLocations->At(i);
310#endif
311}
312
313//_____________________________________________________________________________
314Bool_t AliMpPad::HasLocation(const AliMpIntPair& location) const
315{
316/// Return true if given location is present either as fLocation
317/// or in the collectio
318
319 if (fLocation == location) return true;
320
321 for (Int_t i=0; i<GetNofLocations(); i++) {
322 if ( GetLocation(i) == location ) return true;
5f91c9e8 323 }
2100f1c2 324
325 return false;
326}
327
328//_____________________________________________________________________________
329ostream& operator<< (ostream &out, const AliMpPad& pad)
330{
331/// Output streaming
332
333 pad.PrintOn(out);
334
335 return out;
5f91c9e8 336}
337