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