]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - MUON/mapping/AliMpPad.cxx
Compatibility with ROOT trunk
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpPad.cxx
... / ...
CommitLineData
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
37using std::cout;
38using std::endl;
39/// \cond CLASSIMP
40ClassImp(AliMpPad)
41/// \endcond
42
43const Int_t AliMpPad::fgkMaxNofLocations = 6;
44
45//_____________________________________________________________________________
46AliMpPad::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{
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....
67}
68
69//_____________________________________________________________________________
70AliMpPad::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{
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}
92
93//_____________________________________________________________________________
94AliMpPad::AliMpPad()
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{
106/// Default constructor - creates pad in invalid state
107}
108
109//_____________________________________________________________________________
110AliMpPad::AliMpPad(const AliMpPad& rhs)
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{
122/// Copy constructor
123
124 *this = rhs;
125}
126
127//_____________________________________________________________________________
128AliMpPad::~AliMpPad()
129{
130/// Destructor
131
132 delete [] fLLocations;
133}
134
135//_____________________________________________________________________________
136AliMpPad& AliMpPad::operator = (const AliMpPad& rhs)
137{
138/// Assignment operator
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;
157 fNofLocations = rhs.fNofLocations;
158 if ( rhs.GetNofLocations() ) {
159 fLLocations = new MpPair_t[fgkMaxNofLocations];
160 for ( UInt_t i=0; i<rhs.fNofLocations; i++ )
161 fLLocations[i] = rhs.fLLocations[i];
162 }
163
164 return *this;
165}
166
167//_____________________________________________________________________________
168Bool_t AliMpPad::operator == (const AliMpPad& rhs) const
169{
170/// Equality operator
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//_____________________________________________________________________________
197Bool_t AliMpPad::operator != (const AliMpPad& rhs) const
198{
199/// Non-equality operator
200
201 // are this and rhs equals?
202 return !(*this==rhs);
203}
204
205//_____________________________________________________________________________
206Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
207{
208/// Less operator
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//_____________________________________________________________________________
217Bool_t AliMpPad::AddLocation(Int_t localBoardId, Int_t localBoardChannel,
218 Bool_t warn)
219{
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.
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)
247 fLLocations = new MpPair_t[fgkMaxNofLocations];
248
249 fLLocations[fNofLocations++]
250 = AliMp::Pair(localBoardId, localBoardChannel);
251
252 return true;
253}
254
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
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
297 out << "Pad: Location ";
298 AliMp::PairPut(out, fLLocation)
299 << " Indices ";
300 AliMp::PairPut(out,fLIndices)
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//_____________________________________________________________________________
316void AliMpPad::Print(const char* /*option*/) const
317{
318/// Prints all pad data.
319
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
329 if (!fLLocations) return 0;
330
331 return fNofLocations;
332}
333
334
335//_____________________________________________________________________________
336MpPair_t AliMpPad::GetLocation(Int_t i) const
337{
338/// Return i-th other location associated with this pad
339
340 if ( !fLLocations || i<0 || i>=GetNofLocations() )
341 return 0;
342
343 return fLLocations[i];
344}
345
346//_____________________________________________________________________________
347Int_t AliMpPad::GetLocalBoardId(Int_t i) const
348{
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
372/// or in the collectio
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//_____________________________________________________________________________
386ostream& operator<< (ostream &out, const AliMpPad& pad)
387{
388/// Output streaming
389
390 pad.PrintOn(out);
391
392 return out;
393}
394