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;
43 //_____________________________________________________________________________
44 AliMpPad::AliMpPad(Int_t manuId, Int_t channel,
46 Double_t x, Double_t y,
47 Double_t dx, Double_t dy,
52 fLLocation(AliMp::Pair(manuId, channel)),
53 fLIndices(AliMp::Pair(ix, iy)),
60 /// Standard constructor \n
61 /// Be carefull : this constructor doesn't check the validity of
62 /// the correspondance between location and indices.
63 /// By default, validity is set true.
64 /// It is aimed to be used by MSegmentation methods, and never from outside....
67 //_____________________________________________________________________________
68 AliMpPad::AliMpPad(Int_t manuId, Int_t channel,
70 Double_t x, Double_t y,
71 Double_t dx, Double_t dy,
76 fLLocation(AliMp::Pair(manuId, channel)),
84 /// Standard constructor \n
85 /// Be carefull : this constructor doesn't check the validity of
86 /// the correspondance between location and indices.
87 /// By default, validity is set true.
88 /// It is aimed to be used by MSegmentation methods, and never from outside....
91 //_____________________________________________________________________________
104 /// Default constructor - creates pad in invalid state
107 //_____________________________________________________________________________
108 AliMpPad::AliMpPad(const AliMpPad& rhs)
125 //_____________________________________________________________________________
126 AliMpPad::~AliMpPad()
130 delete [] fLLocations;
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 fLLocation = rhs.fLLocation;
146 fLIndices = rhs.fLIndices;
147 fPositionX = rhs.fPositionX;
148 fPositionY = rhs.fPositionY;
149 fDimensionX = rhs.fDimensionX;
150 fDimensionY = rhs.fDimensionY;
151 fValidity = rhs.fValidity;
154 fNofLocations = rhs.fNofLocations;
155 if ( rhs.GetNofLocations() ) {
156 fLLocations = new MpPair_t[fgkMaxNofLocations];
157 for ( UInt_t i=0; i<rhs.fNofLocations; i++ )
158 fLLocations[i] = rhs.fLLocations[i];
164 //_____________________________________________________________________________
165 Bool_t AliMpPad::operator == (const AliMpPad& rhs) const
167 /// Equality operator
169 // are this and rhs equals?
171 // one valid, one invalid
172 if (fValidity != rhs.fValidity) return false;
175 if (!fValidity) return true;
178 Bool_t sameLocations = true;
180 if (rhs.GetNofLocations()) {
181 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
182 if ( GetLocation(i) != rhs.GetLocation(i) )
183 sameLocations = false;
186 return ( fLLocation == rhs.fLLocation )
187 && ( fLIndices == rhs.fLIndices )
188 && ( fPositionX == rhs.fPositionX )
189 && ( fPositionY == rhs.fPositionY )
190 && ( fDimensionX == rhs.fDimensionX )
193 //_____________________________________________________________________________
194 Bool_t AliMpPad::operator != (const AliMpPad& rhs) const
196 /// Non-equality operator
198 // are this and rhs equals?
199 return !(*this==rhs);
202 //_____________________________________________________________________________
203 Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
207 if ( left.GetIx() < right.GetIx() ) return kTRUE;
208 if ( left.GetIx() > right.GetIx() ) return kFALSE;
209 if ( left.GetIy() < right.GetIy() ) return kTRUE;
213 //_____________________________________________________________________________
214 Bool_t AliMpPad::AddLocation(Int_t localBoardId, Int_t localBoardChannel,
217 /// Add location to the collection if not yet present and
218 /// if collection is not yet full \n
219 /// Return false and optionally give a warning if location is not
222 // Check maximum number limit
223 if ( GetNofLocations() == fgkMaxNofLocations ) {
225 AliWarningStream() << "Cannot add location: ("
226 << localBoardId << "," << localBoardChannel << ")."
227 << " Maximum number has been reached." << endl;
232 // Check if location is present
233 if ( HasLocation(localBoardId, localBoardChannel) ) {
235 AliWarningStream() << "Cannot add location: "
236 << localBoardId << "," << localBoardChannel << ")."
237 << " Location is already present." << endl;
244 fLLocations = new MpPair_t[fgkMaxNofLocations];
246 fLLocations[fNofLocations++]
247 = AliMp::Pair(localBoardId, localBoardChannel);
252 //_____________________________________________________________________________
253 Int_t AliMpPad::GetManuId() const
255 /// Return pad manu Id
257 return AliMp::PairFirst(fLLocation);
260 //_____________________________________________________________________________
261 Int_t AliMpPad::GetManuChannel() const
263 /// Return pad manu channel
265 return AliMp::PairSecond(fLLocation);
268 //_____________________________________________________________________________
269 Int_t AliMpPad::GetIx() const
271 /// Return pad index ix
273 return AliMp::PairFirst(fLIndices);
276 //_____________________________________________________________________________
277 Int_t AliMpPad::GetIy() const
279 /// Return pad index iy
281 return AliMp::PairSecond(fLIndices);
284 //_____________________________________________________________________________
285 void AliMpPad::PrintOn(ostream& out) const
287 /// Prints all pad data.
290 out << "Pad::Invalid";
294 out << "Pad: Location ";
295 AliMp::PairPut(out, fLLocation)
297 AliMp::PairPut(out,fLIndices)
299 << "(" << fPositionX << "," << fPositionY << ")"
301 << "(" << fDimensionX << "," << fDimensionY << ")";
303 if ( GetNofLocations() ) {
305 out << " Other locations: ";
307 for (Int_t i=0; i<GetNofLocations(); i++)
308 AliMp::PairPut(out,GetLocation(i)) << " ";
312 //_____________________________________________________________________________
313 void AliMpPad::Print(const char* /*option*/) const
315 /// Prints all pad data.
321 //_____________________________________________________________________________
322 Int_t AliMpPad::GetNofLocations() const
324 /// Return number of other locations associated with this pad
326 if (!fLLocations) return 0;
328 return fNofLocations;
332 //_____________________________________________________________________________
333 MpPair_t AliMpPad::GetLocation(Int_t i) const
335 /// Return i-th other location associated with this pad
337 if ( !fLLocations || i<0 || i>=GetNofLocations() )
340 return fLLocations[i];
343 //_____________________________________________________________________________
344 Int_t AliMpPad::GetLocalBoardId(Int_t i) const
346 /// Return i-th other local board Id associated with this pad
348 if ( !fLLocations || i<0 || i>=GetNofLocations() )
351 return AliMp::PairFirst(fLLocations[i]);
354 //_____________________________________________________________________________
355 Int_t AliMpPad::GetLocalBoardChannel(Int_t i) const
357 /// Return i-th other local board channel associated with this pad
359 if ( !fLLocations || i<0 || i>=GetNofLocations() )
362 return AliMp::PairSecond(fLLocations[i]);
365 //_____________________________________________________________________________
366 Bool_t AliMpPad::HasLocation(Int_t localBoardId, Int_t localBoardChannel) const
368 /// Return true if given location is present either as fLLocation
369 /// or in the collectio
371 MpPair_t location = AliMp::Pair(localBoardId, localBoardChannel);
373 if (fLLocation == location) return true;
375 for ( Int_t i=0; i<GetNofLocations(); i++ ) {
376 if ( GetLocation(i) == location ) return true;
382 //_____________________________________________________________________________
383 ostream& operator<< (ostream &out, const AliMpPad& pad)