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>
43 const Int_t AliMpPad::fgkMaxNofLocations = 6;
45 //_____________________________________________________________________________
46 AliMpPad::AliMpPad(Int_t manuId, Int_t channel,
48 Double_t x, Double_t y,
49 Double_t dx, Double_t dy,
54 fLLocation(AliMp::Pair(manuId, channel)),
55 fLIndices(AliMp::Pair(ix, iy)),
62 /// Standard constructor \n
63 /// Be carefull : this constructor doesn't check the validity of
64 /// the correspondance between location and indices.
65 /// By default, validity is set true.
66 /// It is aimed to be used by MSegmentation methods, and never from outside....
69 //_____________________________________________________________________________
70 AliMpPad::AliMpPad(Int_t manuId, Int_t channel,
72 Double_t x, Double_t y,
73 Double_t dx, Double_t dy,
78 fLLocation(AliMp::Pair(manuId, channel)),
86 /// Standard constructor \n
87 /// Be carefull : this constructor doesn't check the validity of
88 /// the correspondance between location and indices.
89 /// By default, validity is set true.
90 /// It is aimed to be used by MSegmentation methods, and never from outside....
93 //_____________________________________________________________________________
106 /// Default constructor - creates pad in invalid state
109 //_____________________________________________________________________________
110 AliMpPad::AliMpPad(const AliMpPad& rhs)
127 //_____________________________________________________________________________
128 AliMpPad::~AliMpPad()
132 delete [] fLLocations;
135 //_____________________________________________________________________________
136 AliMpPad& AliMpPad::operator = (const AliMpPad& rhs)
138 /// Assignment operator
140 // check assignment to self
141 if (this == &rhs) return *this;
143 // base class assignment
144 TObject::operator=(rhs);
146 // assignment operator
147 fLLocation = rhs.fLLocation;
148 fLIndices = rhs.fLIndices;
149 fPositionX = rhs.fPositionX;
150 fPositionY = rhs.fPositionY;
151 fDimensionX = rhs.fDimensionX;
152 fDimensionY = rhs.fDimensionY;
153 fValidity = rhs.fValidity;
155 delete [] fLLocations;
157 fNofLocations = rhs.fNofLocations;
158 if ( rhs.GetNofLocations() ) {
159 fLLocations = new MpPair_t[fgkMaxNofLocations];
160 for ( UInt_t i=0; i<rhs.fNofLocations; i++ )
161 fLLocations[i] = rhs.fLLocations[i];
167 //_____________________________________________________________________________
168 Bool_t AliMpPad::operator == (const AliMpPad& rhs) const
170 /// Equality operator
172 // are this and rhs equals?
174 // one valid, one invalid
175 if (fValidity != rhs.fValidity) return false;
178 if (!fValidity) return true;
181 Bool_t sameLocations = true;
183 if (rhs.GetNofLocations()) {
184 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
185 if ( GetLocation(i) != rhs.GetLocation(i) )
186 sameLocations = false;
189 return ( fLLocation == rhs.fLLocation )
190 && ( fLIndices == rhs.fLIndices )
191 && ( fPositionX == rhs.fPositionX )
192 && ( fPositionY == rhs.fPositionY )
193 && ( fDimensionX == rhs.fDimensionX )
196 //_____________________________________________________________________________
197 Bool_t AliMpPad::operator != (const AliMpPad& rhs) const
199 /// Non-equality operator
201 // are this and rhs equals?
202 return !(*this==rhs);
205 //_____________________________________________________________________________
206 Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
210 if ( left.GetIx() < right.GetIx() ) return kTRUE;
211 if ( left.GetIx() > right.GetIx() ) return kFALSE;
212 if ( left.GetIy() < right.GetIy() ) return kTRUE;
216 //_____________________________________________________________________________
217 Bool_t AliMpPad::AddLocation(Int_t localBoardId, Int_t localBoardChannel,
220 /// Add location to the collection if not yet present and
221 /// if collection is not yet full \n
222 /// Return false and optionally give a warning if location is not
225 // Check maximum number limit
226 if ( GetNofLocations() == fgkMaxNofLocations ) {
228 AliWarningStream() << "Cannot add location: ("
229 << localBoardId << "," << localBoardChannel << ")."
230 << " Maximum number has been reached." << endl;
235 // Check if location is present
236 if ( HasLocation(localBoardId, localBoardChannel) ) {
238 AliWarningStream() << "Cannot add location: "
239 << localBoardId << "," << localBoardChannel << ")."
240 << " Location is already present." << endl;
247 fLLocations = new MpPair_t[fgkMaxNofLocations];
249 fLLocations[fNofLocations++]
250 = AliMp::Pair(localBoardId, localBoardChannel);
255 //_____________________________________________________________________________
256 Int_t AliMpPad::GetManuId() const
258 /// Return pad manu Id
260 return AliMp::PairFirst(fLLocation);
263 //_____________________________________________________________________________
264 Int_t AliMpPad::GetManuChannel() const
266 /// Return pad manu channel
268 return AliMp::PairSecond(fLLocation);
271 //_____________________________________________________________________________
272 Int_t AliMpPad::GetIx() const
274 /// Return pad index ix
276 return AliMp::PairFirst(fLIndices);
279 //_____________________________________________________________________________
280 Int_t AliMpPad::GetIy() const
282 /// Return pad index iy
284 return AliMp::PairSecond(fLIndices);
287 //_____________________________________________________________________________
288 void AliMpPad::PrintOn(ostream& out) const
290 /// Prints all pad data.
293 out << "Pad::Invalid";
297 out << "Pad: Location ";
298 AliMp::PairPut(out, fLLocation)
300 AliMp::PairPut(out,fLIndices)
302 << "(" << fPositionX << "," << fPositionY << ")"
304 << "(" << fDimensionX << "," << fDimensionY << ")";
306 if ( GetNofLocations() ) {
308 out << " Other locations: ";
310 for (Int_t i=0; i<GetNofLocations(); i++)
311 AliMp::PairPut(out,GetLocation(i)) << " ";
315 //_____________________________________________________________________________
316 void AliMpPad::Print(const char* /*option*/) const
318 /// Prints all pad data.
324 //_____________________________________________________________________________
325 Int_t AliMpPad::GetNofLocations() const
327 /// Return number of other locations associated with this pad
329 if (!fLLocations) return 0;
331 return fNofLocations;
335 //_____________________________________________________________________________
336 MpPair_t AliMpPad::GetLocation(Int_t i) const
338 /// Return i-th other location associated with this pad
340 if ( !fLLocations || i<0 || i>=GetNofLocations() )
343 return fLLocations[i];
346 //_____________________________________________________________________________
347 Int_t AliMpPad::GetLocalBoardId(Int_t i) const
349 /// Return i-th other local board Id associated with this pad
351 if ( !fLLocations || i<0 || i>=GetNofLocations() )
354 return AliMp::PairFirst(fLLocations[i]);
357 //_____________________________________________________________________________
358 Int_t AliMpPad::GetLocalBoardChannel(Int_t i) const
360 /// Return i-th other local board channel associated with this pad
362 if ( !fLLocations || i<0 || i>=GetNofLocations() )
365 return AliMp::PairSecond(fLLocations[i]);
368 //_____________________________________________________________________________
369 Bool_t AliMpPad::HasLocation(Int_t localBoardId, Int_t localBoardChannel) const
371 /// Return true if given location is present either as fLLocation
372 /// or in the collectio
374 MpPair_t location = AliMp::Pair(localBoardId, localBoardChannel);
376 if (fLLocation == location) return true;
378 for ( Int_t i=0; i<GetNofLocations(); i++ ) {
379 if ( GetLocation(i) == location ) return true;
385 //_____________________________________________________________________________
386 ostream& operator<< (ostream &out, const AliMpPad& pad)