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 $
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>
38 const Int_t AliMpPad::fgkMaxNofLocations = 6;
44 //_____________________________________________________________________________
45 Bool_t operator==(const TVector2& v1,const TVector2& v2)
47 return v1.X()==v2.X() && v1.Y()==v2.Y();
51 //_____________________________________________________________________________
52 ostream& operator<<(ostream& out,const TVector2& v)
54 out << '(' << v.X() << ',' << v.Y() << ')';
59 //_____________________________________________________________________________
60 AliMpPad::AliMpPad(const AliMpIntPair& location,const AliMpIntPair& indices,
61 const TVector2& position,const TVector2& dimensions,
68 fDimensions(dimensions),
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....
79 //_____________________________________________________________________________
83 fLocation(AliMpIntPair::Invalid()),
84 fIndices(AliMpIntPair::Invalid()),
89 /// Default constructor - creates pad in invalid state
93 //_____________________________________________________________________________
94 AliMpPad::AliMpPad(const AliMpPad& rhs)
97 fLocation(AliMpIntPair::Invalid()),
98 fIndices(AliMpIntPair::Invalid()),
108 //_____________________________________________________________________________
109 AliMpPad::~AliMpPad()
114 if (fLocations) fLocations->Delete();
120 //_____________________________________________________________________________
121 AliMpPad& AliMpPad::operator = (const AliMpPad& rhs)
123 /// Assignment operator
125 // check assignment to self
126 if (this == &rhs) return *this;
128 // base class assignment
129 TObject::operator=(rhs);
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;
141 if ( rhs.GetNofLocations() ) {
142 fLocations = new IntPairVector(rhs.GetNofLocations());
144 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
145 (*fLocations)[i] = rhs.GetLocation(i);
150 if ( rhs.GetNofLocations() ) {
151 fLocations = new TClonesArray("AliMpIntPair", rhs.GetNofLocations());
153 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
154 new((*fLocations)[i]) AliMpIntPair(rhs.GetLocation(i));
161 //_____________________________________________________________________________
162 Bool_t AliMpPad::operator == (const AliMpPad& rhs) const
164 /// Equality operator
166 // are this and rhs equals?
168 // one valid, one invalid
169 if (fValidity != rhs.fValidity) return false;
172 if (!fValidity) return true;
175 Bool_t sameLocations = true;
177 if (rhs.GetNofLocations()) {
178 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
179 if ( GetLocation(i) != rhs.GetLocation(i) )
180 sameLocations = false;
183 return (fLocation == rhs.fLocation)
184 && (fIndices == rhs.fIndices)
185 && (fPosition == rhs.fPosition)
186 && (fDimensions == rhs.fDimensions)
189 //_____________________________________________________________________________
190 Bool_t AliMpPad::operator != (const AliMpPad& rhs) const
192 /// Non-equality operator
194 // are this and rhs equals?
195 return !(*this==rhs);
198 //_____________________________________________________________________________
199 Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
203 return left.GetIndices()<right.GetIndices();
206 //_____________________________________________________________________________
207 Bool_t AliMpPad::AddLocation(const AliMpIntPair& location, Bool_t warn)
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
214 // Check maximum number limit
215 if ( GetNofLocations() == fgkMaxNofLocations ) {
217 AliWarningStream() << "Cannot add location: "
219 << " Maximum number has been reached." << endl;
224 // Check if location is present
225 if ( HasLocation(location) ) {
227 AliWarningStream() << "Cannot add location: "
229 << " Location is already present." << endl;
237 fLocations = new IntPairVector();
239 fLocations->push_back(location);
245 fLocations = new TClonesArray("AliMpIntPair", fgkMaxNofLocations);
247 new ((*fLocations)[GetNofLocations()]) AliMpIntPair(location);
252 //_____________________________________________________________________________
253 void AliMpPad::PrintOn(ostream& out) const
255 /// Prints all pad data.
258 out << "Pad::Invalid";
262 out << "Pad: Location " << fLocation
263 << " Indices " << fIndices
264 << " Position " << fPosition
265 << " Dimensions " << fDimensions;
267 if ( GetNofLocations() ) {
269 out << " Other locations: ";
271 for (Int_t i=0; i<GetNofLocations(); i++)
272 out << GetLocation(i) << " ";
276 //_____________________________________________________________________________
277 void AliMpPad::Print(const char* /*option*/) const
279 /// Prints all pad data.
285 //_____________________________________________________________________________
286 Int_t AliMpPad::GetNofLocations() const
288 /// Return number of other locations associated with this pad
290 if (!fLocations) return 0;
293 return fLocations->size();
297 return fLocations->GetEntriesFast();
302 //_____________________________________________________________________________
303 AliMpIntPair AliMpPad::GetLocation(Int_t i) const
305 /// Return i-th other location associated with this pad
307 if ( !fLocations || i<0 || i>=GetNofLocations() )
308 return AliMpIntPair::Invalid();
311 return (*fLocations)[i];
315 return *(AliMpIntPair*)fLocations->At(i);
319 //_____________________________________________________________________________
320 Bool_t AliMpPad::HasLocation(const AliMpIntPair& location) const
322 /// Return true if given location is present either as fLocation
323 /// or in the collectio
325 if (fLocation == location) return true;
327 for (Int_t i=0; i<GetNofLocations(); i++) {
328 if ( GetLocation(i) == location ) return true;
334 //_____________________________________________________________________________
335 ostream& operator<< (ostream &out, const AliMpPad& pad)