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,
70 fDimensions(dimensions),
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....
81 //_____________________________________________________________________________
85 fLocation(AliMpIntPair::Invalid()),
86 fIndices(AliMpIntPair::Invalid()),
91 /// Default constructor - creates pad in invalid state
95 //_____________________________________________________________________________
96 AliMpPad::AliMpPad(const AliMpPad& rhs)
99 fLocation(AliMpIntPair::Invalid()),
100 fIndices(AliMpIntPair::Invalid()),
110 //_____________________________________________________________________________
111 AliMpPad::~AliMpPad()
116 if (fLocations) fLocations->Delete();
122 //_____________________________________________________________________________
123 AliMpPad& AliMpPad::operator = (const AliMpPad& rhs)
125 /// Assignment operator
127 // check assignment to self
128 if (this == &rhs) return *this;
130 // base class assignment
131 TObject::operator=(rhs);
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;
143 if ( rhs.GetNofLocations() ) {
144 fLocations = new IntPairVector(rhs.GetNofLocations());
146 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
147 (*fLocations)[i] = rhs.GetLocation(i);
152 if ( rhs.GetNofLocations() ) {
153 fLocations = new TClonesArray("AliMpIntPair", rhs.GetNofLocations());
155 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
156 new((*fLocations)[i]) AliMpIntPair(rhs.GetLocation(i));
163 //_____________________________________________________________________________
164 Bool_t AliMpPad::operator == (const AliMpPad& rhs) const
166 /// Equality operator
168 // are this and rhs equals?
170 // one valid, one invalid
171 if (fValidity != rhs.fValidity) return false;
174 if (!fValidity) return true;
177 Bool_t sameLocations = true;
179 if (rhs.GetNofLocations()) {
180 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
181 if ( GetLocation(i) != rhs.GetLocation(i) )
182 sameLocations = false;
185 return (fLocation == rhs.fLocation)
186 && (fIndices == rhs.fIndices)
187 && (fPosition == rhs.fPosition)
188 && (fDimensions == rhs.fDimensions)
191 //_____________________________________________________________________________
192 Bool_t AliMpPad::operator != (const AliMpPad& rhs) const
194 /// Non-equality operator
196 // are this and rhs equals?
197 return !(*this==rhs);
200 //_____________________________________________________________________________
201 Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
205 return left.GetIndices()<right.GetIndices();
208 //_____________________________________________________________________________
209 Bool_t AliMpPad::AddLocation(const AliMpIntPair& location, Bool_t warn)
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
216 // Check maximum number limit
217 if ( GetNofLocations() == fgkMaxNofLocations ) {
219 AliWarningStream() << "Cannot add location: "
221 << " Maximum number has been reached." << endl;
226 // Check if location is present
227 if ( HasLocation(location) ) {
229 AliWarningStream() << "Cannot add location: "
231 << " Location is already present." << endl;
239 fLocations = new IntPairVector();
241 fLocations->push_back(location);
247 fLocations = new TClonesArray("AliMpIntPair", fgkMaxNofLocations);
249 new ((*fLocations)[GetNofLocations()]) AliMpIntPair(location);
254 //_____________________________________________________________________________
255 void AliMpPad::PrintOn(ostream& out) const
257 /// Prints all pad data.
260 out << "Pad::Invalid";
264 out << "Pad: Location " << fLocation
265 << " Indices " << fIndices
266 << " Position " << fPosition
267 << " Dimensions " << fDimensions;
269 if ( GetNofLocations() ) {
271 out << " Other locations: ";
273 for (Int_t i=0; i<GetNofLocations(); i++)
274 out << GetLocation(i) << " ";
278 //_____________________________________________________________________________
279 void AliMpPad::Print(const char* /*option*/) const
281 /// Prints all pad data.
287 //_____________________________________________________________________________
288 Int_t AliMpPad::GetNofLocations() const
290 /// Return number of other locations associated with this pad
292 if (!fLocations) return 0;
295 return fLocations->size();
299 return fLocations->GetEntriesFast();
304 //_____________________________________________________________________________
305 AliMpIntPair AliMpPad::GetLocation(Int_t i) const
307 /// Return i-th other location associated with this pad
309 if ( !fLocations || i<0 || i>=GetNofLocations() )
310 return AliMpIntPair::Invalid();
313 return (*fLocations)[i];
317 return *(AliMpIntPair*)fLocations->At(i);
321 //_____________________________________________________________________________
322 Bool_t AliMpPad::HasLocation(const AliMpIntPair& location) const
324 /// Return true if given location is present either as fLocation
325 /// or in the collectio
327 if (fLocation == location) return true;
329 for (Int_t i=0; i<GetNofLocations(); i++) {
330 if ( GetLocation(i) == location ) return true;
336 //_____________________________________________________________________________
337 ostream& operator<< (ostream &out, const AliMpPad& pad)