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