AliRoot Core  v5-06-15 (45dab64)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMpPad.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
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  **************************************************************************/
15 
16 // $Id$
17 // $MpId: AliMpPad.cxx,v 1.9 2006/05/24 13:58:29 ivana Exp $
18 // Category: basic
19 
20 //-----------------------------------------------------------------------------
21 // Class AliMpPad
22 // ---------------
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 //-----------------------------------------------------------------------------
29 
30 #include "AliMpPad.h"
31 #include "AliMpEncodePair.h"
32 #include "AliLog.h"
33 
34 #include <TClonesArray.h>
35 #include <Riostream.h>
36 
37 using std::cout;
38 using std::endl;
42 
43 const Int_t AliMpPad::fgkMaxNofLocations = 6;
44 
45 //_____________________________________________________________________________
46 AliMpPad::AliMpPad(Int_t manuId, Int_t channel,
47  Int_t ix, Int_t iy,
48  Double_t x, Double_t y,
49  Double_t dx, Double_t dy,
50  Bool_t validity)
51  : TObject(),
52  fNofLocations(0),
53  fLLocations(0),
54  fLLocation(AliMp::Pair(manuId, channel)),
55  fLIndices(AliMp::Pair(ix, iy)),
56  fPositionX(x),
57  fPositionY(y),
58  fDimensionX(dx),
59  fDimensionY(dy),
60  fValidity(validity)
61 {
67 }
68 
69 //_____________________________________________________________________________
70 AliMpPad::AliMpPad(Int_t manuId, Int_t channel,
71  MpPair_t indices,
72  Double_t x, Double_t y,
73  Double_t dx, Double_t dy,
74  Bool_t validity)
75  : TObject(),
76  fNofLocations(0),
77  fLLocations(0),
78  fLLocation(AliMp::Pair(manuId, channel)),
79  fLIndices(indices),
80  fPositionX(x),
81  fPositionY(y),
82  fDimensionX(dx),
83  fDimensionY(dy),
84  fValidity(validity)
85 {
91 }
92 
93 //_____________________________________________________________________________
95  : TObject(),
96  fNofLocations(0),
97  fLLocations(0),
98  fLLocation(0),
99  fLIndices(0),
100  fPositionX(-1.),
101  fPositionY(-1.),
102  fDimensionX(-1.),
103  fDimensionY(-1.),
104  fValidity(false)
105 {
107 }
108 
109 //_____________________________________________________________________________
111  : TObject(),
112  fNofLocations(0),
113  fLLocations(0),
114  fLLocation(0),
115  fLIndices(0),
116  fPositionX(-1.),
117  fPositionY(-1.),
118  fDimensionX(-1.),
119  fDimensionY(-1.),
120  fValidity(false)
121 {
123 
124  *this = rhs;
125 }
126 
127 //_____________________________________________________________________________
129 {
131 
132  delete [] fLLocations;
133 }
134 
135 //_____________________________________________________________________________
137 {
139 
140  // check assignment to self
141  if (this == &rhs) return *this;
142 
143  // base class assignment
144  TObject::operator=(rhs);
145 
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;
154 
155  delete [] fLLocations;
156  fLLocations = 0;
158  if ( rhs.GetNofLocations() ) {
160  for ( UInt_t i=0; i<rhs.fNofLocations; i++ )
161  fLLocations[i] = rhs.fLLocations[i];
162  }
163 
164  return *this;
165 }
166 
167 //_____________________________________________________________________________
168 Bool_t AliMpPad::operator == (const AliMpPad& rhs) const
169 {
171 
172  // are this and rhs equals?
173 
174  // one valid, one invalid
175  if (fValidity != rhs.fValidity) return false;
176 
177  // both invalid
178  if (!fValidity) return true;
179 
180  // both valid
181  Bool_t sameLocations = true;
182 
183  if (rhs.GetNofLocations()) {
184  for (Int_t i=0; i<rhs.GetNofLocations(); i++)
185  if ( GetLocation(i) != rhs.GetLocation(i) )
186  sameLocations = false;
187  }
188 
189  return ( fLLocation == rhs.fLLocation )
190  && ( fLIndices == rhs.fLIndices )
191  && ( fPositionX == rhs.fPositionX )
192  && ( fPositionY == rhs.fPositionY )
193  && ( fDimensionX == rhs.fDimensionX )
194  && sameLocations;
195 }
196 //_____________________________________________________________________________
197 Bool_t AliMpPad::operator != (const AliMpPad& rhs) const
198 {
200 
201  // are this and rhs equals?
202  return !(*this==rhs);
203 }
204 
205 //_____________________________________________________________________________
206 Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
207 {
209 
210  if ( left.GetIx() < right.GetIx() ) return kTRUE;
211  if ( left.GetIx() > right.GetIx() ) return kFALSE;
212  if ( left.GetIy() < right.GetIy() ) return kTRUE;
213  return kFALSE;
214 }
215 
216 //_____________________________________________________________________________
217 Bool_t AliMpPad::AddLocation(Int_t localBoardId, Int_t localBoardChannel,
218  Bool_t warn)
219 {
224 
225  // Check maximum number limit
226  if ( GetNofLocations() == fgkMaxNofLocations ) {
227  if (warn) {
228  AliWarningStream() << "Cannot add location: ("
229  << localBoardId << "," << localBoardChannel << ")."
230  << " Maximum number has been reached." << endl;
231  }
232  return false;
233  }
234 
235  // Check if location is present
236  if ( HasLocation(localBoardId, localBoardChannel) ) {
237  if (warn) {
238  AliWarningStream() << "Cannot add location: "
239  << localBoardId << "," << localBoardChannel << ")."
240  << " Location is already present." << endl;
241  }
242  return false;
243  }
244 
245  // Add location
246  if ( ! fLLocations)
248 
250  = AliMp::Pair(localBoardId, localBoardChannel);
251 
252  return true;
253 }
254 
255 //_____________________________________________________________________________
256 Int_t AliMpPad::GetManuId() const
257 {
259 
261 }
262 
263 //_____________________________________________________________________________
265 {
267 
269 }
270 
271 //_____________________________________________________________________________
272 Int_t AliMpPad::GetIx() const
273 {
275 
276  return AliMp::PairFirst(fLIndices);
277 }
278 
279 //_____________________________________________________________________________
280 Int_t AliMpPad::GetIy() const
281 {
283 
285 }
286 
287 //_____________________________________________________________________________
288 void AliMpPad::PrintOn(ostream& out) const
289 {
291 
292  if ( !fValidity ) {
293  out << "Pad::Invalid";
294  return;
295  }
296 
297  out << "Pad: Location ";
299  << " Indices ";
301  << " Position "
302  << "(" << fPositionX << "," << fPositionY << ")"
303  << " Dimensions "
304  << "(" << fDimensionX << "," << fDimensionY << ")";
305 
306  if ( GetNofLocations() ) {
307  out << endl;
308  out << " Other locations: ";
309 
310  for (Int_t i=0; i<GetNofLocations(); i++)
311  AliMp::PairPut(out,GetLocation(i)) << " ";
312  }
313 }
314 
315 //_____________________________________________________________________________
316 void AliMpPad::Print(const char* /*option*/) const
317 {
319 
320  PrintOn(cout);
321  cout << endl;
322 }
323 
324 //_____________________________________________________________________________
326 {
328 
329  if (!fLLocations) return 0;
330 
331  return fNofLocations;
332 }
333 
334 
335 //_____________________________________________________________________________
337 {
339 
340  if ( !fLLocations || i<0 || i>=GetNofLocations() )
341  return 0;
342 
343  return fLLocations[i];
344 }
345 
346 //_____________________________________________________________________________
347 Int_t AliMpPad::GetLocalBoardId(Int_t i) const
348 {
350 
351  if ( !fLLocations || i<0 || i>=GetNofLocations() )
352  return 0;
353 
354  return AliMp::PairFirst(fLLocations[i]);
355 }
356 
357 //_____________________________________________________________________________
358 Int_t AliMpPad::GetLocalBoardChannel(Int_t i) const
359 {
361 
362  if ( !fLLocations || i<0 || i>=GetNofLocations() )
363  return 0;
364 
365  return AliMp::PairSecond(fLLocations[i]);
366 }
367 
368 //_____________________________________________________________________________
369 Bool_t AliMpPad::HasLocation(Int_t localBoardId, Int_t localBoardChannel) const
370 {
373 
374  MpPair_t location = AliMp::Pair(localBoardId, localBoardChannel);
375 
376  if (fLLocation == location) return true;
377 
378  for ( Int_t i=0; i<GetNofLocations(); i++ ) {
379  if ( GetLocation(i) == location ) return true;
380  }
381 
382  return false;
383 }
384 
385 //_____________________________________________________________________________
386 ostream& operator<< (ostream &out, const AliMpPad& pad)
387 {
389 
390  pad.PrintOn(out);
391 
392  return out;
393 }
394 
MpPair_t fLIndices
pad indices as encoded pair (ix, iy)
Definition: AliMpPad.h:108
Int_t GetNofLocations() const
Definition: AliMpPad.cxx:325
Bool_t operator<(const AliMpPad &left, const AliMpPad &right)
Definition: AliMpPad.cxx:206
Double_t fDimensionX
the pad x dimension - half length (in cm)
Definition: AliMpPad.h:111
UInt_t fNofLocations
Definition: AliMpPad.h:104
Int_t GetIy() const
Definition: AliMpPad.cxx:280
Int_t GetManuId() const
Definition: AliMpPad.cxx:256
void PrintOn(ostream &out) const
Definition: AliMpPad.cxx:288
MpPair_t * fLLocations
Collection of pad locations - encoded pair (localBoardId, localBoardChannel)
Definition: AliMpPad.h:106
ostream & operator<<(ostream &out, const AliMpPad &pad)
Definition: AliMpPad.cxx:386
MpPair_t Pair(Int_t first, Int_t second)
Encode the pair of integers to another integer.
Bool_t fValidity
validity
Definition: AliMpPad.h:113
MpPair_t fLLocation
pad location as encoded pair (manuId, manuChannel)
Definition: AliMpPad.h:107
Bool_t HasLocation(Int_t localBoardId, Int_t localBoardChannel) const
Definition: AliMpPad.cxx:369
Bool_t operator==(const AliMpPad &pos2) const
Definition: AliMpPad.cxx:168
Double_t fPositionY
the pad y position (in cm)
Definition: AliMpPad.h:110
MpPair_t GetLocation() const
Return pad location as encoded pair (manuId, manuChannel)
Definition: AliMpPad.h:69
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
Int_t GetManuChannel() const
Definition: AliMpPad.cxx:264
static const Int_t fgkMaxNofLocations
maximum number of pad locations in the collection
Definition: AliMpPad.h:101
void Print(const char *="") const
Definition: AliMpPad.cxx:316
Int_t GetLocalBoardId(Int_t i) const
Definition: AliMpPad.cxx:347
Double_t fPositionX
the pad x position (in cm)
Definition: AliMpPad.h:109
Bool_t operator!=(const AliMpPad &pos2) const
Definition: AliMpPad.cxx:197
AliMpPad & operator=(const AliMpPad &src)
Definition: AliMpPad.cxx:136
Int_t GetIx() const
Definition: AliMpPad.cxx:272
Int_t MpPair_t
Int_t PairFirst(MpPair_t pair)
Decode the first integer from encoded pair.
Class which encapsuate all information about a pad.
Definition: AliMpPad.h:22
Int_t PairSecond(MpPair_t pair)
Decode the second integer from encoded pair.
Double_t fDimensionY
the pad y dimension - half length(in cm)
Definition: AliMpPad.h:112
Bool_t AddLocation(Int_t localBoardId, Int_t localBoardChannel, Bool_t warn=true)
Definition: AliMpPad.cxx:217
ostream & PairPut(ostream &s, MpPair_t pair)
A special printing for encoded pair.
AliMpPad()
Definition: AliMpPad.cxx:94
Int_t GetLocalBoardChannel(Int_t i) const
Definition: AliMpPad.cxx:358