Fixing a backward compatibility issue
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpPad.cxx
CommitLineData
dee1d5f1 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
5f91c9e8 16// $Id$
13985652 17// $MpId: AliMpPad.cxx,v 1.9 2006/05/24 13:58:29 ivana Exp $
5f91c9e8 18// Category: basic
3d1463c8 19
20//-----------------------------------------------------------------------------
5f91c9e8 21// Class AliMpPad
22// ---------------
23// Class which encapsuate all informations about a pad
dbe945cc 24// Included in AliRoot: 2003/05/02
5f91c9e8 25// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
2100f1c2 26// root [0] .x testSectorAreaIterator.C
27// Real time 0:00:56, CP time 36.270
3d1463c8 28//-----------------------------------------------------------------------------
5f91c9e8 29
5f91c9e8 30#include "AliMpPad.h"
168e9c4d 31#include "AliMpEncodePair.h"
2100f1c2 32#include "AliLog.h"
5f91c9e8 33
2c605e66 34#include <TClonesArray.h>
35#include <Riostream.h>
36
13985652 37/// \cond CLASSIMP
5f91c9e8 38ClassImp(AliMpPad)
13985652 39/// \endcond
5f91c9e8 40
2100f1c2 41const Int_t AliMpPad::fgkMaxNofLocations = 6;
42
5f91c9e8 43//_____________________________________________________________________________
168e9c4d 44AliMpPad::AliMpPad(Int_t manuId, Int_t channel,
45 Int_t ix, Int_t iy,
6e97fbb8 46 Double_t x, Double_t y,
47 Double_t dx, Double_t dy,
5f91c9e8 48 Bool_t validity)
49 : TObject(),
c9d734d4 50 fNofLocations(0),
1c37d914 51 fLLocations(0),
168e9c4d 52 fLLocation(AliMp::Pair(manuId, channel)),
53 fLIndices(AliMp::Pair(ix, iy)),
6e97fbb8 54 fPositionX(x),
55 fPositionY(y),
56 fDimensionX(dx),
57 fDimensionY(dy),
5f91c9e8 58 fValidity(validity)
59{
dee1d5f1 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....
5f91c9e8 65}
66
168e9c4d 67//_____________________________________________________________________________
68AliMpPad::AliMpPad(Int_t manuId, Int_t channel,
69 MpPair_t indices,
6e97fbb8 70 Double_t x, Double_t y,
71 Double_t dx, Double_t dy,
168e9c4d 72 Bool_t validity)
73 : TObject(),
168e9c4d 74 fNofLocations(0),
1c37d914 75 fLLocations(0),
168e9c4d 76 fLLocation(AliMp::Pair(manuId, channel)),
77 fLIndices(indices),
6e97fbb8 78 fPositionX(x),
79 fPositionY(y),
80 fDimensionX(dx),
81 fDimensionY(dy),
168e9c4d 82 fValidity(validity)
83{
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....
89}
5f91c9e8 90
91//_____________________________________________________________________________
92AliMpPad::AliMpPad()
93 : TObject(),
c9d734d4 94 fNofLocations(0),
1c37d914 95 fLLocations(0),
168e9c4d 96 fLLocation(0),
97 fLIndices(0),
6e97fbb8 98 fPositionX(-1.),
99 fPositionY(-1.),
100 fDimensionX(-1.),
101 fDimensionY(-1.),
5f91c9e8 102 fValidity(false)
103{
dee1d5f1 104/// Default constructor - creates pad in invalid state
5f91c9e8 105}
106
5f91c9e8 107//_____________________________________________________________________________
2100f1c2 108AliMpPad::AliMpPad(const AliMpPad& rhs)
6e97fbb8 109 : TObject(),
c9d734d4 110 fNofLocations(0),
1c37d914 111 fLLocations(0),
168e9c4d 112 fLLocation(0),
113 fLIndices(0),
6e97fbb8 114 fPositionX(-1.),
115 fPositionY(-1.),
116 fDimensionX(-1.),
117 fDimensionY(-1.),
0471c97b 118 fValidity(false)
5f91c9e8 119{
dee1d5f1 120/// Copy constructor
121
2100f1c2 122 *this = rhs;
5f91c9e8 123}
124
125//_____________________________________________________________________________
dee1d5f1 126AliMpPad::~AliMpPad()
127{
128/// Destructor
2100f1c2 129
168e9c4d 130 delete [] fLLocations;
5f91c9e8 131}
132
133//_____________________________________________________________________________
2100f1c2 134AliMpPad& AliMpPad::operator = (const AliMpPad& rhs)
5f91c9e8 135{
dee1d5f1 136/// Assignment operator
137
138 // check assignment to self
2100f1c2 139 if (this == &rhs) return *this;
5f91c9e8 140
dee1d5f1 141 // base class assignment
2100f1c2 142 TObject::operator=(rhs);
5f91c9e8 143
dee1d5f1 144 // assignment operator
168e9c4d 145 fLLocation = rhs.fLLocation;
146 fLIndices = rhs.fLIndices;
6e97fbb8 147 fPositionX = rhs.fPositionX;
148 fPositionY = rhs.fPositionY;
149 fDimensionX = rhs.fDimensionX;
150 fDimensionY = rhs.fDimensionY;
2100f1c2 151 fValidity = rhs.fValidity;
152
168e9c4d 153 fLLocations = 0;
c9d734d4 154 fNofLocations = rhs.fNofLocations;
2100f1c2 155 if ( rhs.GetNofLocations() ) {
168e9c4d 156 fLLocations = new MpPair_t[fgkMaxNofLocations];
c9d734d4 157 for ( UInt_t i=0; i<rhs.fNofLocations; i++ )
168e9c4d 158 fLLocations[i] = rhs.fLLocations[i];
2100f1c2 159 }
5f91c9e8 160
161 return *this;
162}
163
164//_____________________________________________________________________________
2100f1c2 165Bool_t AliMpPad::operator == (const AliMpPad& rhs) const
5f91c9e8 166{
dee1d5f1 167/// Equality operator
168
2100f1c2 169 // are this and rhs equals?
5f91c9e8 170
171 // one valid, one invalid
2100f1c2 172 if (fValidity != rhs.fValidity) return false;
5f91c9e8 173
174 // both invalid
175 if (!fValidity) return true;
176
177 // both valid
2100f1c2 178 Bool_t sameLocations = true;
179
180 if (rhs.GetNofLocations()) {
181 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
182 if ( GetLocation(i) != rhs.GetLocation(i) )
183 sameLocations = false;
184 }
185
6e97fbb8 186 return ( fLLocation == rhs.fLLocation )
187 && ( fLIndices == rhs.fLIndices )
188 && ( fPositionX == rhs.fPositionX )
189 && ( fPositionY == rhs.fPositionY )
190 && ( fDimensionX == rhs.fDimensionX )
2100f1c2 191 && sameLocations;
5f91c9e8 192}
193//_____________________________________________________________________________
2100f1c2 194Bool_t AliMpPad::operator != (const AliMpPad& rhs) const
5f91c9e8 195{
dee1d5f1 196/// Non-equality operator
197
2100f1c2 198 // are this and rhs equals?
199 return !(*this==rhs);
5f91c9e8 200}
201
202//_____________________________________________________________________________
2100f1c2 203Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
5f91c9e8 204{
2100f1c2 205/// Less operator
dee1d5f1 206
168e9c4d 207 if ( left.GetIx() < right.GetIx() ) return kTRUE;
208 if ( left.GetIx() > right.GetIx() ) return kFALSE;
209 if ( left.GetIy() < right.GetIy() ) return kTRUE;
210 return kFALSE;
5f91c9e8 211}
212
213//_____________________________________________________________________________
168e9c4d 214Bool_t AliMpPad::AddLocation(Int_t localBoardId, Int_t localBoardChannel,
215 Bool_t warn)
5f91c9e8 216{
2100f1c2 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
220/// added.
dee1d5f1 221
2100f1c2 222 // Check maximum number limit
223 if ( GetNofLocations() == fgkMaxNofLocations ) {
224 if (warn) {
168e9c4d 225 AliWarningStream() << "Cannot add location: ("
226 << localBoardId << "," << localBoardChannel << ")."
6e97fbb8 227 << " Maximum number has been reached." << endl;
2100f1c2 228 }
229 return false;
230 }
231
232 // Check if location is present
168e9c4d 233 if ( HasLocation(localBoardId, localBoardChannel) ) {
2100f1c2 234 if (warn) {
235 AliWarningStream() << "Cannot add location: "
168e9c4d 236 << localBoardId << "," << localBoardChannel << ")."
6e97fbb8 237 << " Location is already present." << endl;
2100f1c2 238 }
239 return false;
240 }
241
242 // Add location
168e9c4d 243 if ( ! fLLocations)
244 fLLocations = new MpPair_t[fgkMaxNofLocations];
c9d734d4 245
168e9c4d 246 fLLocations[fNofLocations++]
247 = AliMp::Pair(localBoardId, localBoardChannel);
248
2100f1c2 249 return true;
2100f1c2 250}
251
252//_____________________________________________________________________________
168e9c4d 253Int_t AliMpPad::GetManuId() const
254{
255/// Return pad manu Id
256
257 return AliMp::PairFirst(fLLocation);
258}
259
260//_____________________________________________________________________________
261Int_t AliMpPad::GetManuChannel() const
262{
263/// Return pad manu channel
264
265 return AliMp::PairSecond(fLLocation);
266}
267
268//_____________________________________________________________________________
269Int_t AliMpPad::GetIx() const
270{
271/// Return pad index ix
272
273 return AliMp::PairFirst(fLIndices);
274}
275
276//_____________________________________________________________________________
277Int_t AliMpPad::GetIy() const
278{
279/// Return pad index iy
280
281 return AliMp::PairSecond(fLIndices);
282}
283
284//_____________________________________________________________________________
2100f1c2 285void AliMpPad::PrintOn(ostream& out) const
286{
287/// Prints all pad data.
288
289 if ( !fValidity ) {
290 out << "Pad::Invalid";
291 return;
292 }
293
168e9c4d 294 out << "Pad: Location ";
295 AliMp::PairPut(out, fLLocation)
296 << " Indices ";
297 AliMp::PairPut(out,fLIndices)
6e97fbb8 298 << " Position "
299 << "(" << fPositionX << "," << fPositionY << ")"
300 << " Dimensions "
301 << "(" << fDimensionX << "," << fDimensionY << ")";
2100f1c2 302
303 if ( GetNofLocations() ) {
304 out << endl;
305 out << " Other locations: ";
306
307 for (Int_t i=0; i<GetNofLocations(); i++)
168e9c4d 308 AliMp::PairPut(out,GetLocation(i)) << " ";
2100f1c2 309 }
5f91c9e8 310}
311
312//_____________________________________________________________________________
2998a151 313void AliMpPad::Print(const char* /*option*/) const
5f91c9e8 314{
dee1d5f1 315/// Prints all pad data.
5f91c9e8 316
2100f1c2 317 PrintOn(cout);
318 cout << endl;
319}
320
321//_____________________________________________________________________________
322Int_t AliMpPad::GetNofLocations() const
323{
324/// Return number of other locations associated with this pad
325
168e9c4d 326 if (!fLLocations) return 0;
2100f1c2 327
c9d734d4 328 return fNofLocations;
2100f1c2 329}
330
331
332//_____________________________________________________________________________
168e9c4d 333MpPair_t AliMpPad::GetLocation(Int_t i) const
2100f1c2 334{
335/// Return i-th other location associated with this pad
336
168e9c4d 337 if ( !fLLocations || i<0 || i>=GetNofLocations() )
338 return 0;
2100f1c2 339
168e9c4d 340 return fLLocations[i];
2100f1c2 341}
342
343//_____________________________________________________________________________
168e9c4d 344Int_t AliMpPad::GetLocalBoardId(Int_t i) const
2100f1c2 345{
168e9c4d 346/// Return i-th other local board Id associated with this pad
347
348 if ( !fLLocations || i<0 || i>=GetNofLocations() )
349 return 0;
350
351 return AliMp::PairFirst(fLLocations[i]);
352}
353
354//_____________________________________________________________________________
355Int_t AliMpPad::GetLocalBoardChannel(Int_t i) const
356{
357/// Return i-th other local board channel associated with this pad
358
359 if ( !fLLocations || i<0 || i>=GetNofLocations() )
360 return 0;
361
362 return AliMp::PairSecond(fLLocations[i]);
363}
364
365//_____________________________________________________________________________
366Bool_t AliMpPad::HasLocation(Int_t localBoardId, Int_t localBoardChannel) const
367{
368/// Return true if given location is present either as fLLocation
2100f1c2 369/// or in the collectio
370
168e9c4d 371 MpPair_t location = AliMp::Pair(localBoardId, localBoardChannel);
372
373 if (fLLocation == location) return true;
2100f1c2 374
c9d734d4 375 for ( Int_t i=0; i<GetNofLocations(); i++ ) {
2100f1c2 376 if ( GetLocation(i) == location ) return true;
5f91c9e8 377 }
2100f1c2 378
379 return false;
380}
381
382//_____________________________________________________________________________
383ostream& operator<< (ostream &out, const AliMpPad& pad)
384{
385/// Output streaming
386
387 pad.PrintOn(out);
388
389 return out;
5f91c9e8 390}
391