1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpPad.cxx,v 1.9 2006/05/24 13:58:29 ivana Exp $
20 //-----------------------------------------------------------------------------
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 //-----------------------------------------------------------------------------
33 #include <TClonesArray.h>
34 #include <Riostream.h>
40 const Int_t AliMpPad::fgkMaxNofLocations = 6;
46 //_____________________________________________________________________________
47 Bool_t operator==(const TVector2& v1,const TVector2& v2)
49 return v1.X()==v2.X() && v1.Y()==v2.Y();
53 //_____________________________________________________________________________
54 ostream& operator<<(ostream& out,const TVector2& v)
56 out << '(' << v.X() << ',' << v.Y() << ')';
61 //_____________________________________________________________________________
62 AliMpPad::AliMpPad(const AliMpIntPair& location,const AliMpIntPair& indices,
63 const TVector2& position,const TVector2& dimensions,
73 fDimensions(dimensions),
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....
84 //_____________________________________________________________________________
91 fLocation(AliMpIntPair::Invalid()),
92 fIndices(AliMpIntPair::Invalid()),
97 /// Default constructor - creates pad in invalid state
101 //_____________________________________________________________________________
102 AliMpPad::AliMpPad(const AliMpPad& rhs)
108 fLocation(AliMpIntPair::Invalid()),
109 fIndices(AliMpIntPair::Invalid()),
119 //_____________________________________________________________________________
120 AliMpPad::~AliMpPad()
129 delete [] fLocations;
133 //_____________________________________________________________________________
134 AliMpPad& AliMpPad::operator = (const AliMpPad& rhs)
136 /// Assignment operator
138 // check assignment to self
139 if (this == &rhs) return *this;
141 // base class assignment
142 TObject::operator=(rhs);
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;
154 if ( rhs.GetNofLocations() ) {
155 fLocations = new IntPairVector(rhs.GetNofLocations());
157 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
158 (*fLocations)[i] = rhs.GetLocation(i);
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];
174 //_____________________________________________________________________________
175 Bool_t AliMpPad::operator == (const AliMpPad& rhs) const
177 /// Equality operator
179 // are this and rhs equals?
181 // one valid, one invalid
182 if (fValidity != rhs.fValidity) return false;
185 if (!fValidity) return true;
188 Bool_t sameLocations = true;
190 if (rhs.GetNofLocations()) {
191 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
192 if ( GetLocation(i) != rhs.GetLocation(i) )
193 sameLocations = false;
196 return (fLocation == rhs.fLocation)
197 && (fIndices == rhs.fIndices)
198 && (fPosition == rhs.fPosition)
199 && (fDimensions == rhs.fDimensions)
202 //_____________________________________________________________________________
203 Bool_t AliMpPad::operator != (const AliMpPad& rhs) const
205 /// Non-equality operator
207 // are this and rhs equals?
208 return !(*this==rhs);
211 //_____________________________________________________________________________
212 Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
216 return left.GetIndices()<right.GetIndices();
219 //_____________________________________________________________________________
220 Bool_t AliMpPad::AddLocation(const AliMpIntPair& location, Bool_t warn)
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
227 // Check maximum number limit
228 if ( GetNofLocations() == fgkMaxNofLocations ) {
230 AliWarningStream() << "Cannot add location: "
232 << " Maximum number has been reached." << endl;
237 // Check if location is present
238 if ( HasLocation(location) ) {
240 AliWarningStream() << "Cannot add location: "
242 << " Location is already present." << endl;
250 fLocations = new IntPairVector();
252 fLocations->push_back(location);
258 fLocations = new AliMpIntPair[fgkMaxNofLocations];
260 fLocations[fNofLocations++] = location;
265 //_____________________________________________________________________________
266 void AliMpPad::PrintOn(ostream& out) const
268 /// Prints all pad data.
271 out << "Pad::Invalid";
275 out << "Pad: Location " << fLocation
276 << " Indices " << fIndices
277 << " Position " << fPosition
278 << " Dimensions " << fDimensions;
280 if ( GetNofLocations() ) {
282 out << " Other locations: ";
284 for (Int_t i=0; i<GetNofLocations(); i++)
285 out << GetLocation(i) << " ";
289 //_____________________________________________________________________________
290 void AliMpPad::Print(const char* /*option*/) const
292 /// Prints all pad data.
298 //_____________________________________________________________________________
299 Int_t AliMpPad::GetNofLocations() const
301 /// Return number of other locations associated with this pad
303 if (!fLocations) return 0;
306 return fLocations->size();
310 return fNofLocations;
315 //_____________________________________________________________________________
316 AliMpIntPair AliMpPad::GetLocation(Int_t i) const
318 /// Return i-th other location associated with this pad
320 if ( !fLocations || i<0 || i>=GetNofLocations() )
321 return AliMpIntPair::Invalid();
324 return (*fLocations)[i];
328 return fLocations[i];
332 //_____________________________________________________________________________
333 Bool_t AliMpPad::HasLocation(const AliMpIntPair& location) const
335 /// Return true if given location is present either as fLocation
336 /// or in the collectio
338 if (fLocation == location) return true;
340 for ( Int_t i=0; i<GetNofLocations(); i++ ) {
341 if ( GetLocation(i) == location ) return true;
347 //_____________________________________________________________________________
348 ostream& operator<< (ostream &out, const AliMpPad& pad)