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