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