]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpPad.cxx
Replacement of AliMpIntPair object with algoritmic
[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//
44// foreign operators
45//
46
47//_____________________________________________________________________________
48Bool_t operator==(const TVector2& v1,const TVector2& v2)
49{
c9d734d4 50 return v1.X()==v2.X() && v1.Y()==v2.Y();
5f91c9e8 51}
52
53
54//_____________________________________________________________________________
55ostream& operator<<(ostream& out,const TVector2& v)
56{
57 out << '(' << v.X() << ',' << v.Y() << ')';
58 return out;
59}
60
2100f1c2 61
5f91c9e8 62//_____________________________________________________________________________
168e9c4d 63AliMpPad::AliMpPad(Int_t manuId, Int_t channel,
64 Int_t ix, Int_t iy,
5f91c9e8 65 const TVector2& position,const TVector2& dimensions,
66 Bool_t validity)
67 : TObject(),
168e9c4d 68 fLLocations(0),
c9d734d4 69 fNofLocations(0),
168e9c4d 70 fLLocation(AliMp::Pair(manuId, channel)),
71 fLIndices(AliMp::Pair(ix, iy)),
5f91c9e8 72 fPosition(position),
73 fDimensions(dimensions),
74 fValidity(validity)
75{
dee1d5f1 76/// Standard constructor \n
77/// Be carefull : this constructor doesn't check the validity of
78/// the correspondance between location and indices.
79/// By default, validity is set true.
80/// It is aimed to be used by MSegmentation methods, and never from outside....
5f91c9e8 81}
82
168e9c4d 83//_____________________________________________________________________________
84AliMpPad::AliMpPad(Int_t manuId, Int_t channel,
85 MpPair_t indices,
86 const TVector2& position,const TVector2& dimensions,
87 Bool_t validity)
88 : TObject(),
89 fLLocations(0),
90 fNofLocations(0),
91 fLLocation(AliMp::Pair(manuId, channel)),
92 fLIndices(indices),
93 fPosition(position),
94 fDimensions(dimensions),
95 fValidity(validity)
96{
97/// Standard constructor \n
98/// Be carefull : this constructor doesn't check the validity of
99/// the correspondance between location and indices.
100/// By default, validity is set true.
101/// It is aimed to be used by MSegmentation methods, and never from outside....
102}
5f91c9e8 103
104//_____________________________________________________________________________
105AliMpPad::AliMpPad()
106 : TObject(),
168e9c4d 107 fLLocations(0),
c9d734d4 108 fNofLocations(0),
168e9c4d 109 fLLocation(0),
110 fLIndices(0),
5f91c9e8 111 fPosition(-1.,-1.),
112 fDimensions(0.,0.),
113 fValidity(false)
114{
dee1d5f1 115/// Default constructor - creates pad in invalid state
5f91c9e8 116}
117
5f91c9e8 118//_____________________________________________________________________________
2100f1c2 119AliMpPad::AliMpPad(const AliMpPad& rhs)
0471c97b 120 : TObject(rhs),
168e9c4d 121 fLLocations(0),
c9d734d4 122 fNofLocations(0),
168e9c4d 123 fLLocation(0),
124 fLIndices(0),
0471c97b 125 fPosition(-1.,-1.),
126 fDimensions(0.,0.),
127 fValidity(false)
5f91c9e8 128{
dee1d5f1 129/// Copy constructor
130
2100f1c2 131 *this = rhs;
5f91c9e8 132}
133
134//_____________________________________________________________________________
dee1d5f1 135AliMpPad::~AliMpPad()
136{
137/// Destructor
2100f1c2 138
168e9c4d 139 delete [] fLLocations;
5f91c9e8 140}
141
142//_____________________________________________________________________________
2100f1c2 143AliMpPad& AliMpPad::operator = (const AliMpPad& rhs)
5f91c9e8 144{
dee1d5f1 145/// Assignment operator
146
147 // check assignment to self
2100f1c2 148 if (this == &rhs) return *this;
5f91c9e8 149
dee1d5f1 150 // base class assignment
2100f1c2 151 TObject::operator=(rhs);
5f91c9e8 152
dee1d5f1 153 // assignment operator
168e9c4d 154 fLLocation = rhs.fLLocation;
155 fLIndices = rhs.fLIndices;
2100f1c2 156 fPosition.Set(rhs.fPosition);
157 fDimensions.Set(rhs.fDimensions);
158 fValidity = rhs.fValidity;
159
168e9c4d 160 fLLocations = 0;
c9d734d4 161 fNofLocations = rhs.fNofLocations;
2100f1c2 162 if ( rhs.GetNofLocations() ) {
168e9c4d 163 fLLocations = new MpPair_t[fgkMaxNofLocations];
c9d734d4 164 for ( UInt_t i=0; i<rhs.fNofLocations; i++ )
168e9c4d 165 fLLocations[i] = rhs.fLLocations[i];
2100f1c2 166 }
5f91c9e8 167
168 return *this;
169}
170
171//_____________________________________________________________________________
2100f1c2 172Bool_t AliMpPad::operator == (const AliMpPad& rhs) const
5f91c9e8 173{
dee1d5f1 174/// Equality operator
175
2100f1c2 176 // are this and rhs equals?
5f91c9e8 177
178 // one valid, one invalid
2100f1c2 179 if (fValidity != rhs.fValidity) return false;
5f91c9e8 180
181 // both invalid
182 if (!fValidity) return true;
183
184 // both valid
2100f1c2 185 Bool_t sameLocations = true;
186
187 if (rhs.GetNofLocations()) {
188 for (Int_t i=0; i<rhs.GetNofLocations(); i++)
189 if ( GetLocation(i) != rhs.GetLocation(i) )
190 sameLocations = false;
191 }
192
168e9c4d 193 return (fLLocation == rhs.fLLocation)
194 && (fLIndices == rhs.fLIndices)
2100f1c2 195 && (fPosition == rhs.fPosition)
196 && (fDimensions == rhs.fDimensions)
197 && sameLocations;
5f91c9e8 198}
199//_____________________________________________________________________________
2100f1c2 200Bool_t AliMpPad::operator != (const AliMpPad& rhs) const
5f91c9e8 201{
dee1d5f1 202/// Non-equality operator
203
2100f1c2 204 // are this and rhs equals?
205 return !(*this==rhs);
5f91c9e8 206}
207
208//_____________________________________________________________________________
2100f1c2 209Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
5f91c9e8 210{
2100f1c2 211/// Less operator
dee1d5f1 212
168e9c4d 213 if ( left.GetIx() < right.GetIx() ) return kTRUE;
214 if ( left.GetIx() > right.GetIx() ) return kFALSE;
215 if ( left.GetIy() < right.GetIy() ) return kTRUE;
216 return kFALSE;
5f91c9e8 217}
218
219//_____________________________________________________________________________
168e9c4d 220Bool_t AliMpPad::AddLocation(Int_t localBoardId, Int_t localBoardChannel,
221 Bool_t warn)
5f91c9e8 222{
2100f1c2 223/// Add location to the collection if not yet present and
224/// if collection is not yet full \n
225/// Return false and optionally give a warning if location is not
226/// added.
dee1d5f1 227
2100f1c2 228 // Check maximum number limit
229 if ( GetNofLocations() == fgkMaxNofLocations ) {
230 if (warn) {
168e9c4d 231 AliWarningStream() << "Cannot add location: ("
232 << localBoardId << "," << localBoardChannel << ")."
2100f1c2 233 << " Maximum number has been reached." << endl;
234 }
235 return false;
236 }
237
238 // Check if location is present
168e9c4d 239 if ( HasLocation(localBoardId, localBoardChannel) ) {
2100f1c2 240 if (warn) {
241 AliWarningStream() << "Cannot add location: "
168e9c4d 242 << localBoardId << "," << localBoardChannel << ")."
2100f1c2 243 << " Location is already present." << endl;
244 }
245 return false;
246 }
247
248 // Add location
168e9c4d 249 if ( ! fLLocations)
250 fLLocations = new MpPair_t[fgkMaxNofLocations];
c9d734d4 251
168e9c4d 252 fLLocations[fNofLocations++]
253 = AliMp::Pair(localBoardId, localBoardChannel);
254
2100f1c2 255 return true;
2100f1c2 256}
257
168e9c4d 258//_____________________________________________________________________________
259Int_t AliMpPad::GetManuId() const
260{
261/// Return pad manu Id
262
263 return AliMp::PairFirst(fLLocation);
264}
265
266//_____________________________________________________________________________
267Int_t AliMpPad::GetManuChannel() const
268{
269/// Return pad manu channel
270
271 return AliMp::PairSecond(fLLocation);
272}
273
274//_____________________________________________________________________________
275Int_t AliMpPad::GetIx() const
276{
277/// Return pad index ix
278
279 return AliMp::PairFirst(fLIndices);
280}
281
282//_____________________________________________________________________________
283Int_t AliMpPad::GetIy() const
284{
285/// Return pad index iy
286
287 return AliMp::PairSecond(fLIndices);
288}
289
2100f1c2 290//_____________________________________________________________________________
291void AliMpPad::PrintOn(ostream& out) const
292{
293/// Prints all pad data.
294
295 if ( !fValidity ) {
296 out << "Pad::Invalid";
297 return;
298 }
299
168e9c4d 300 out << "Pad: Location ";
301 AliMp::PairPut(out, fLLocation)
302 << " Indices ";
303 AliMp::PairPut(out,fLIndices)
2100f1c2 304 << " Position " << fPosition
305 << " Dimensions " << fDimensions;
306
307 if ( GetNofLocations() ) {
308 out << endl;
309 out << " Other locations: ";
310
311 for (Int_t i=0; i<GetNofLocations(); i++)
168e9c4d 312 AliMp::PairPut(out,GetLocation(i)) << " ";
2100f1c2 313 }
5f91c9e8 314}
315
316//_____________________________________________________________________________
2998a151 317void AliMpPad::Print(const char* /*option*/) const
5f91c9e8 318{
dee1d5f1 319/// Prints all pad data.
5f91c9e8 320
2100f1c2 321 PrintOn(cout);
322 cout << endl;
323}
324
325//_____________________________________________________________________________
326Int_t AliMpPad::GetNofLocations() const
327{
328/// Return number of other locations associated with this pad
329
168e9c4d 330 if (!fLLocations) return 0;
2100f1c2 331
c9d734d4 332 return fNofLocations;
2100f1c2 333}
334
335
336//_____________________________________________________________________________
168e9c4d 337MpPair_t AliMpPad::GetLocation(Int_t i) const
2100f1c2 338{
339/// Return i-th other location associated with this pad
340
168e9c4d 341 if ( !fLLocations || i<0 || i>=GetNofLocations() )
342 return 0;
2100f1c2 343
168e9c4d 344 return fLLocations[i];
2100f1c2 345}
346
347//_____________________________________________________________________________
168e9c4d 348Int_t AliMpPad::GetLocalBoardId(Int_t i) const
2100f1c2 349{
168e9c4d 350/// Return i-th other local board Id associated with this pad
351
352 if ( !fLLocations || i<0 || i>=GetNofLocations() )
353 return 0;
354
355 return AliMp::PairFirst(fLLocations[i]);
356}
357
358//_____________________________________________________________________________
359Int_t AliMpPad::GetLocalBoardChannel(Int_t i) const
360{
361/// Return i-th other local board channel associated with this pad
362
363 if ( !fLLocations || i<0 || i>=GetNofLocations() )
364 return 0;
365
366 return AliMp::PairSecond(fLLocations[i]);
367}
368
369//_____________________________________________________________________________
370Bool_t AliMpPad::HasLocation(Int_t localBoardId, Int_t localBoardChannel) const
371{
372/// Return true if given location is present either as fLLocation
2100f1c2 373/// or in the collectio
374
168e9c4d 375 MpPair_t location = AliMp::Pair(localBoardId, localBoardChannel);
376
377 if (fLLocation == location) return true;
2100f1c2 378
c9d734d4 379 for ( Int_t i=0; i<GetNofLocations(); i++ ) {
2100f1c2 380 if ( GetLocation(i) == location ) return true;
5f91c9e8 381 }
2100f1c2 382
383 return false;
384}
385
386//_____________________________________________________________________________
387ostream& operator<< (ostream &out, const AliMpPad& pad)
388{
389/// Output streaming
390
391 pad.PrintOn(out);
392
393 return out;
5f91c9e8 394}
395