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.8 2006/03/17 11:34:46 ivana Exp $
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
31 #include <TClonesArray.h>
32 #include <Riostream.h>
36 //////////////////////////////////////////////////////////
38 // This class encapsulate all the information about a pad
40 //////////////////////////////////////////////////////////
42 const Int_t AliMpPad::fgkMaxNofLocations = 6;
48 //_____________________________________________________________________________
49 Bool_t operator==(const TVector2& v1,const TVector2& v2)
51 return v1.X()==v2.X() && v1.Y()==v2.Y();
55 //_____________________________________________________________________________
56 ostream& operator<<(ostream& out,const TVector2& v)
58 out << '(' << v.X() << ',' << v.Y() << ')';
63 //_____________________________________________________________________________
64 AliMpPad::AliMpPad(const AliMpIntPair& location,const AliMpIntPair& indices,
65 const TVector2& position,const TVector2& dimensions,
72 fDimensions(dimensions),
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....
83 //_____________________________________________________________________________
87 fLocation(AliMpIntPair::Invalid()),
88 fIndices(AliMpIntPair::Invalid()),
93 /// Default constructor - creates pad in invalid state
97 //_____________________________________________________________________________
98 AliMpPad::AliMpPad(const AliMpPad& rhs)
106 //_____________________________________________________________________________
107 AliMpPad::~AliMpPad()
112 if (fLocations) fLocations->Delete();
118 //_____________________________________________________________________________
119 AliMpPad& AliMpPad::operator = (const AliMpPad& rhs)
121 /// Assignment operator
123 // check assignment to self
124 if (this == &rhs) return *this;
126 // base class assignment
127 TObject::operator=(rhs);
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;
139 if ( rhs.GetNofLocations() ) {
140 fLocations = new IntPairVector(rhs.GetNofLocations());
142 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
143 (*fLocations)[i] = rhs.GetLocation(i);
148 if ( rhs.GetNofLocations() ) {
149 fLocations = new TClonesArray("AliMpIntPair", rhs.GetNofLocations());
151 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
152 new((*fLocations)[i]) AliMpIntPair(rhs.GetLocation(i));
159 //_____________________________________________________________________________
160 Bool_t AliMpPad::operator == (const AliMpPad& rhs) const
162 /// Equality operator
164 // are this and rhs equals?
166 // one valid, one invalid
167 if (fValidity != rhs.fValidity) return false;
170 if (!fValidity) return true;
173 Bool_t sameLocations = true;
175 if (rhs.GetNofLocations()) {
176 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
177 if ( GetLocation(i) != rhs.GetLocation(i) )
178 sameLocations = false;
181 return (fLocation == rhs.fLocation)
182 && (fIndices == rhs.fIndices)
183 && (fPosition == rhs.fPosition)
184 && (fDimensions == rhs.fDimensions)
187 //_____________________________________________________________________________
188 Bool_t AliMpPad::operator != (const AliMpPad& rhs) const
190 /// Non-equality operator
192 // are this and rhs equals?
193 return !(*this==rhs);
196 //_____________________________________________________________________________
197 Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
201 return left.GetIndices()<right.GetIndices();
204 //_____________________________________________________________________________
205 Bool_t AliMpPad::AddLocation(const AliMpIntPair& location, Bool_t warn)
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
212 // Check maximum number limit
213 if ( GetNofLocations() == fgkMaxNofLocations ) {
215 AliWarningStream() << "Cannot add location: "
217 << " Maximum number has been reached." << endl;
222 // Check if location is present
223 if ( HasLocation(location) ) {
225 AliWarningStream() << "Cannot add location: "
227 << " Location is already present." << endl;
235 fLocations = new IntPairVector();
237 fLocations->push_back(location);
243 fLocations = new TClonesArray("AliMpIntPair", fgkMaxNofLocations);
245 new ((*fLocations)[GetNofLocations()]) AliMpIntPair(location);
250 //_____________________________________________________________________________
251 void AliMpPad::PrintOn(ostream& out) const
253 /// Prints all pad data.
256 out << "Pad::Invalid";
260 out << "Pad: Location " << fLocation
261 << " Indices " << fIndices
262 << " Position " << fPosition
263 << " Dimensions " << fDimensions;
265 if ( GetNofLocations() ) {
267 out << " Other locations: ";
269 for (Int_t i=0; i<GetNofLocations(); i++)
270 out << GetLocation(i) << " ";
274 //_____________________________________________________________________________
275 void AliMpPad::Print(const char* /*option*/) const
277 /// Prints all pad data.
283 //_____________________________________________________________________________
284 Int_t AliMpPad::GetNofLocations() const
286 /// Return number of other locations associated with this pad
288 if (!fLocations) return 0;
291 return fLocations->size();
295 return fLocations->GetEntriesFast();
300 //_____________________________________________________________________________
301 AliMpIntPair AliMpPad::GetLocation(Int_t i) const
303 /// Return i-th other location associated with this pad
305 if ( !fLocations || i<0 || i>=GetNofLocations() )
306 return AliMpIntPair::Invalid();
309 return (*fLocations)[i];
313 return *(AliMpIntPair*)fLocations->At(i);
317 //_____________________________________________________________________________
318 Bool_t AliMpPad::HasLocation(const AliMpIntPair& location) const
320 /// Return true if given location is present either as fLocation
321 /// or in the collectio
323 if (fLocation == location) return true;
325 for (Int_t i=0; i<GetNofLocations(); i++) {
326 if ( GetLocation(i) == location ) return true;
332 //_____________________________________________________________________________
333 ostream& operator<< (ostream &out, const AliMpPad& pad)