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