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;
153 delete [] fLLocations;
155 fNofLocations = rhs.fNofLocations;
156 if ( rhs.GetNofLocations() ) {
157 fLLocations = new MpPair_t[fgkMaxNofLocations];
158 for ( UInt_t i=0; i<rhs.fNofLocations; i++ )
159 fLLocations[i] = rhs.fLLocations[i];
165 //_____________________________________________________________________________
166 Bool_t AliMpPad::operator == (const AliMpPad& rhs) const
168 /// Equality operator
170 // are this and rhs equals?
172 // one valid, one invalid
173 if (fValidity != rhs.fValidity) return false;
176 if (!fValidity) return true;
179 Bool_t sameLocations = true;
181 if (rhs.GetNofLocations()) {
182 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
183 if ( GetLocation(i) != rhs.GetLocation(i) )
184 sameLocations = false;
187 return ( fLLocation == rhs.fLLocation )
188 && ( fLIndices == rhs.fLIndices )
189 && ( fPositionX == rhs.fPositionX )
190 && ( fPositionY == rhs.fPositionY )
191 && ( fDimensionX == rhs.fDimensionX )
194 //_____________________________________________________________________________
195 Bool_t AliMpPad::operator != (const AliMpPad& rhs) const
197 /// Non-equality operator
199 // are this and rhs equals?
200 return !(*this==rhs);
203 //_____________________________________________________________________________
204 Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
208 if ( left.GetIx() < right.GetIx() ) return kTRUE;
209 if ( left.GetIx() > right.GetIx() ) return kFALSE;
210 if ( left.GetIy() < right.GetIy() ) return kTRUE;
214 //_____________________________________________________________________________
215 Bool_t AliMpPad::AddLocation(Int_t localBoardId, Int_t localBoardChannel,
218 /// Add location to the collection if not yet present and
219 /// if collection is not yet full \n
220 /// Return false and optionally give a warning if location is not
223 // Check maximum number limit
224 if ( GetNofLocations() == fgkMaxNofLocations ) {
226 AliWarningStream() << "Cannot add location: ("
227 << localBoardId << "," << localBoardChannel << ")."
228 << " Maximum number has been reached." << endl;
233 // Check if location is present
234 if ( HasLocation(localBoardId, localBoardChannel) ) {
236 AliWarningStream() << "Cannot add location: "
237 << localBoardId << "," << localBoardChannel << ")."
238 << " Location is already present." << endl;
245 fLLocations = new MpPair_t[fgkMaxNofLocations];
247 fLLocations[fNofLocations++]
248 = AliMp::Pair(localBoardId, localBoardChannel);
253 //_____________________________________________________________________________
254 Int_t AliMpPad::GetManuId() const
256 /// Return pad manu Id
258 return AliMp::PairFirst(fLLocation);
261 //_____________________________________________________________________________
262 Int_t AliMpPad::GetManuChannel() const
264 /// Return pad manu channel
266 return AliMp::PairSecond(fLLocation);
269 //_____________________________________________________________________________
270 Int_t AliMpPad::GetIx() const
272 /// Return pad index ix
274 return AliMp::PairFirst(fLIndices);
277 //_____________________________________________________________________________
278 Int_t AliMpPad::GetIy() const
280 /// Return pad index iy
282 return AliMp::PairSecond(fLIndices);
285 //_____________________________________________________________________________
286 void AliMpPad::PrintOn(ostream& out) const
288 /// Prints all pad data.
291 out << "Pad::Invalid";
295 out << "Pad: Location ";
296 AliMp::PairPut(out, fLLocation)
298 AliMp::PairPut(out,fLIndices)
300 << "(" << fPositionX << "," << fPositionY << ")"
302 << "(" << fDimensionX << "," << fDimensionY << ")";
304 if ( GetNofLocations() ) {
306 out << " Other locations: ";
308 for (Int_t i=0; i<GetNofLocations(); i++)
309 AliMp::PairPut(out,GetLocation(i)) << " ";
313 //_____________________________________________________________________________
314 void AliMpPad::Print(const char* /*option*/) const
316 /// Prints all pad data.
322 //_____________________________________________________________________________
323 Int_t AliMpPad::GetNofLocations() const
325 /// Return number of other locations associated with this pad
327 if (!fLLocations) return 0;
329 return fNofLocations;
333 //_____________________________________________________________________________
334 MpPair_t AliMpPad::GetLocation(Int_t i) const
336 /// Return i-th other location associated with this pad
338 if ( !fLLocations || i<0 || i>=GetNofLocations() )
341 return fLLocations[i];
344 //_____________________________________________________________________________
345 Int_t AliMpPad::GetLocalBoardId(Int_t i) const
347 /// Return i-th other local board Id associated with this pad
349 if ( !fLLocations || i<0 || i>=GetNofLocations() )
352 return AliMp::PairFirst(fLLocations[i]);
355 //_____________________________________________________________________________
356 Int_t AliMpPad::GetLocalBoardChannel(Int_t i) const
358 /// Return i-th other local board channel associated with this pad
360 if ( !fLLocations || i<0 || i>=GetNofLocations() )
363 return AliMp::PairSecond(fLLocations[i]);
366 //_____________________________________________________________________________
367 Bool_t AliMpPad::HasLocation(Int_t localBoardId, Int_t localBoardChannel) const
369 /// Return true if given location is present either as fLLocation
370 /// or in the collectio
372 MpPair_t location = AliMp::Pair(localBoardId, localBoardChannel);
374 if (fLLocation == location) return true;
376 for ( Int_t i=0; i<GetNofLocations(); i++ ) {
377 if ( GetLocation(i) == location ) return true;
383 //_____________________________________________________________________________
384 ostream& operator<< (ostream &out, const AliMpPad& pad)