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 //-----------------------------------------------------------------------------
31 #include "AliMpEncodePair.h"
34 #include <TClonesArray.h>
35 #include <Riostream.h>
41 const Int_t AliMpPad::fgkMaxNofLocations = 6;
47 //_____________________________________________________________________________
48 Bool_t operator==(const TVector2& v1,const TVector2& v2)
50 return v1.X()==v2.X() && v1.Y()==v2.Y();
54 //_____________________________________________________________________________
55 ostream& operator<<(ostream& out,const TVector2& v)
57 out << '(' << v.X() << ',' << v.Y() << ')';
62 //_____________________________________________________________________________
63 AliMpPad::AliMpPad(Int_t manuId, Int_t channel,
65 const TVector2& position,const TVector2& dimensions,
70 fLLocation(AliMp::Pair(manuId, channel)),
71 fLIndices(AliMp::Pair(ix, iy)),
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....
83 //_____________________________________________________________________________
84 AliMpPad::AliMpPad(Int_t manuId, Int_t channel,
86 const TVector2& position,const TVector2& dimensions,
91 fLLocation(AliMp::Pair(manuId, channel)),
94 fDimensions(dimensions),
97 /// Standard constructor \n
98 /// Be carefull : this constructor doesn't check the validity of
99 /// the correspondance between location and indices.
100 /// By default, validity is set true.
101 /// It is aimed to be used by MSegmentation methods, and never from outside....
104 //_____________________________________________________________________________
115 /// Default constructor - creates pad in invalid state
118 //_____________________________________________________________________________
119 AliMpPad::AliMpPad(const AliMpPad& rhs)
134 //_____________________________________________________________________________
135 AliMpPad::~AliMpPad()
139 delete [] fLLocations;
142 //_____________________________________________________________________________
143 AliMpPad& AliMpPad::operator = (const AliMpPad& rhs)
145 /// Assignment operator
147 // check assignment to self
148 if (this == &rhs) return *this;
150 // base class assignment
151 TObject::operator=(rhs);
153 // assignment operator
154 fLLocation = rhs.fLLocation;
155 fLIndices = rhs.fLIndices;
156 fPosition.Set(rhs.fPosition);
157 fDimensions.Set(rhs.fDimensions);
158 fValidity = rhs.fValidity;
161 fNofLocations = rhs.fNofLocations;
162 if ( rhs.GetNofLocations() ) {
163 fLLocations = new MpPair_t[fgkMaxNofLocations];
164 for ( UInt_t i=0; i<rhs.fNofLocations; i++ )
165 fLLocations[i] = rhs.fLLocations[i];
171 //_____________________________________________________________________________
172 Bool_t AliMpPad::operator == (const AliMpPad& rhs) const
174 /// Equality operator
176 // are this and rhs equals?
178 // one valid, one invalid
179 if (fValidity != rhs.fValidity) return false;
182 if (!fValidity) return true;
185 Bool_t sameLocations = true;
187 if (rhs.GetNofLocations()) {
188 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
189 if ( GetLocation(i) != rhs.GetLocation(i) )
190 sameLocations = false;
193 return (fLLocation == rhs.fLLocation)
194 && (fLIndices == rhs.fLIndices)
195 && (fPosition == rhs.fPosition)
196 && (fDimensions == rhs.fDimensions)
199 //_____________________________________________________________________________
200 Bool_t AliMpPad::operator != (const AliMpPad& rhs) const
202 /// Non-equality operator
204 // are this and rhs equals?
205 return !(*this==rhs);
208 //_____________________________________________________________________________
209 Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
213 if ( left.GetIx() < right.GetIx() ) return kTRUE;
214 if ( left.GetIx() > right.GetIx() ) return kFALSE;
215 if ( left.GetIy() < right.GetIy() ) return kTRUE;
219 //_____________________________________________________________________________
220 Bool_t AliMpPad::AddLocation(Int_t localBoardId, Int_t localBoardChannel,
223 /// Add location to the collection if not yet present and
224 /// if collection is not yet full \n
225 /// Return false and optionally give a warning if location is not
228 // Check maximum number limit
229 if ( GetNofLocations() == fgkMaxNofLocations ) {
231 AliWarningStream() << "Cannot add location: ("
232 << localBoardId << "," << localBoardChannel << ")."
233 << " Maximum number has been reached." << endl;
238 // Check if location is present
239 if ( HasLocation(localBoardId, localBoardChannel) ) {
241 AliWarningStream() << "Cannot add location: "
242 << localBoardId << "," << localBoardChannel << ")."
243 << " Location is already present." << endl;
250 fLLocations = new MpPair_t[fgkMaxNofLocations];
252 fLLocations[fNofLocations++]
253 = AliMp::Pair(localBoardId, localBoardChannel);
258 //_____________________________________________________________________________
259 Int_t AliMpPad::GetManuId() const
261 /// Return pad manu Id
263 return AliMp::PairFirst(fLLocation);
266 //_____________________________________________________________________________
267 Int_t AliMpPad::GetManuChannel() const
269 /// Return pad manu channel
271 return AliMp::PairSecond(fLLocation);
274 //_____________________________________________________________________________
275 Int_t AliMpPad::GetIx() const
277 /// Return pad index ix
279 return AliMp::PairFirst(fLIndices);
282 //_____________________________________________________________________________
283 Int_t AliMpPad::GetIy() const
285 /// Return pad index iy
287 return AliMp::PairSecond(fLIndices);
290 //_____________________________________________________________________________
291 void AliMpPad::PrintOn(ostream& out) const
293 /// Prints all pad data.
296 out << "Pad::Invalid";
300 out << "Pad: Location ";
301 AliMp::PairPut(out, fLLocation)
303 AliMp::PairPut(out,fLIndices)
304 << " Position " << fPosition
305 << " Dimensions " << fDimensions;
307 if ( GetNofLocations() ) {
309 out << " Other locations: ";
311 for (Int_t i=0; i<GetNofLocations(); i++)
312 AliMp::PairPut(out,GetLocation(i)) << " ";
316 //_____________________________________________________________________________
317 void AliMpPad::Print(const char* /*option*/) const
319 /// Prints all pad data.
325 //_____________________________________________________________________________
326 Int_t AliMpPad::GetNofLocations() const
328 /// Return number of other locations associated with this pad
330 if (!fLLocations) return 0;
332 return fNofLocations;
336 //_____________________________________________________________________________
337 MpPair_t AliMpPad::GetLocation(Int_t i) const
339 /// Return i-th other location associated with this pad
341 if ( !fLLocations || i<0 || i>=GetNofLocations() )
344 return fLLocations[i];
347 //_____________________________________________________________________________
348 Int_t AliMpPad::GetLocalBoardId(Int_t i) const
350 /// Return i-th other local board Id associated with this pad
352 if ( !fLLocations || i<0 || i>=GetNofLocations() )
355 return AliMp::PairFirst(fLLocations[i]);
358 //_____________________________________________________________________________
359 Int_t AliMpPad::GetLocalBoardChannel(Int_t i) const
361 /// Return i-th other local board channel associated with this pad
363 if ( !fLLocations || i<0 || i>=GetNofLocations() )
366 return AliMp::PairSecond(fLLocations[i]);
369 //_____________________________________________________________________________
370 Bool_t AliMpPad::HasLocation(Int_t localBoardId, Int_t localBoardChannel) const
372 /// Return true if given location is present either as fLLocation
373 /// or in the collectio
375 MpPair_t location = AliMp::Pair(localBoardId, localBoardChannel);
377 if (fLLocation == location) return true;
379 for ( Int_t i=0; i<GetNofLocations(); i++ ) {
380 if ( GetLocation(i) == location ) return true;
386 //_____________________________________________________________________________
387 ostream& operator<< (ostream &out, const AliMpPad& pad)