]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpPad.cxx
Work around for CINT bug in root 5.10/00, with gcc4.0.2
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpPad.cxx
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
16 // $Id$
17 // $MpId: AliMpPad.cxx,v 1.6 2005/08/26 15:43:36 ivana Exp $
18 // Category: basic
19 //
20 // Class AliMpPad
21 // ---------------
22 // Class which encapsuate all informations about a pad
23 // Included in AliRoot: 2003/05/02
24 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
25 // root [0] .x testSectorAreaIterator.C
26 // Real time 0:00:56, CP time 36.270
27
28 #include <Riostream.h>
29 #include <TClonesArray.h>
30
31 #include "AliMpPad.h"
32 #include "AliLog.h"
33
34 ClassImp(AliMpPad)
35
36 //////////////////////////////////////////////////////////
37 //
38 // This class encapsulate all the information about a pad
39 //
40 //////////////////////////////////////////////////////////
41
42 const Int_t  AliMpPad::fgkMaxNofLocations = 6;
43
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
62
63 //_____________________________________________________________________________
64 AliMpPad::AliMpPad(const AliMpIntPair& location,const AliMpIntPair& indices,
65                    const TVector2& position,const TVector2& dimensions,
66                    Bool_t validity)
67  : TObject(),
68    fLocations(0),
69    fLocation(location),
70    fIndices(indices),
71    fPosition(position),
72    fDimensions(dimensions),
73    fValidity(validity)
74 {
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....
80 }
81
82
83 //_____________________________________________________________________________
84 AliMpPad::AliMpPad()
85   : TObject(),
86     fLocations(0),
87     fLocation(AliMpIntPair::Invalid()),
88     fIndices(AliMpIntPair::Invalid()),
89     fPosition(-1.,-1.),
90     fDimensions(0.,0.),
91     fValidity(false) 
92 {
93 /// Default constructor - creates pad in invalid state
94 }
95
96
97 //_____________________________________________________________________________
98 AliMpPad::AliMpPad(const AliMpPad& rhs)
99   : TObject(rhs)
100 {
101 /// Copy constructor
102
103  *this = rhs;
104 }
105
106 //_____________________________________________________________________________
107 AliMpPad::~AliMpPad() 
108 {
109 /// Destructor
110
111 #ifdef WITH_ROOT
112   if (fLocations) fLocations->Delete();
113 #endif
114
115   delete fLocations;
116 }
117
118 //_____________________________________________________________________________
119 AliMpPad& AliMpPad::operator = (const AliMpPad& rhs) 
120 {
121 /// Assignment operator
122  
123   // check assignment to self
124   if (this == &rhs) return *this;
125
126   // base class assignment
127   TObject::operator=(rhs);
128
129   // assignment operator
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
155
156   return *this;
157 }
158
159 //_____________________________________________________________________________
160 Bool_t AliMpPad::operator == (const AliMpPad& rhs) const
161 {
162 /// Equality operator
163
164   // are this and rhs equals?
165
166   // one valid, one invalid
167   if (fValidity != rhs.fValidity) return false;
168   
169   // both invalid
170   if (!fValidity) return true;
171   
172   // both valid
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;
186 }
187 //_____________________________________________________________________________
188 Bool_t AliMpPad::operator != (const AliMpPad& rhs) const
189 {
190 /// Non-equality operator
191
192   // are this and rhs equals?
193   return !(*this==rhs);
194 }
195
196 //_____________________________________________________________________________
197 Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
198 {
199 /// Less operator
200
201   return left.GetIndices()<right.GetIndices();
202 }
203
204 //_____________________________________________________________________________
205 Bool_t AliMpPad::AddLocation(const AliMpIntPair& location, Bool_t warn)
206 {
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. 
211
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   }
272 }
273
274 //_____________________________________________________________________________
275 void AliMpPad::Print(const char* /*option*/) const
276 {
277 /// Prints all pad data.
278
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;
327   }
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;
340 }
341