]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpPad.cxx
In AliMpPad:
[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   delete [] fLLocations;
154   fLLocations = 0;
155   fNofLocations = rhs.fNofLocations;
156   if ( rhs.GetNofLocations() ) {
157     fLLocations = new MpPair_t[fgkMaxNofLocations];
158     for ( UInt_t i=0; i<rhs.fNofLocations; i++ )
159       fLLocations[i] = rhs.fLLocations[i];
160   }                     
161
162   return *this;
163 }
164
165 //_____________________________________________________________________________
166 Bool_t AliMpPad::operator == (const AliMpPad& rhs) const
167 {
168 /// Equality operator
169
170   // are this and rhs equals?
171
172   // one valid, one invalid
173   if (fValidity != rhs.fValidity) return false;
174   
175   // both invalid
176   if (!fValidity) return true;
177   
178   // both valid
179   Bool_t sameLocations = true;
180   
181   if (rhs.GetNofLocations()) {
182     for (Int_t i=0; i<rhs.GetNofLocations(); i++) 
183       if ( GetLocation(i) != rhs.GetLocation(i) )
184         sameLocations = false;
185   }
186   
187   return    ( fLLocation  == rhs.fLLocation ) 
188          && ( fLIndices   == rhs.fLIndices )
189          && ( fPositionX  == rhs.fPositionX ) 
190          && ( fPositionY  == rhs.fPositionY ) 
191          && ( fDimensionX == rhs.fDimensionX )
192          && sameLocations;
193 }
194 //_____________________________________________________________________________
195 Bool_t AliMpPad::operator != (const AliMpPad& rhs) const
196 {
197 /// Non-equality operator
198
199   // are this and rhs equals?
200   return !(*this==rhs);
201 }
202
203 //_____________________________________________________________________________
204 Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
205 {
206 /// Less operator
207
208   if ( left.GetIx() < right.GetIx() ) return kTRUE;
209   if ( left.GetIx() > right.GetIx() ) return kFALSE;
210   if ( left.GetIy() < right.GetIy() ) return kTRUE;
211   return kFALSE;
212 }
213
214 //_____________________________________________________________________________
215 Bool_t AliMpPad::AddLocation(Int_t localBoardId, Int_t localBoardChannel, 
216                              Bool_t warn)
217 {
218 /// Add location to the collection if not yet present and
219 /// if collection is not yet full                                           \n
220 /// Return false and optionally give a warning if location is not 
221 /// added. 
222
223   // Check maximum number limit
224   if ( GetNofLocations() == fgkMaxNofLocations ) {
225     if (warn) {
226       AliWarningStream() << "Cannot add location: ("
227                          << localBoardId << "," << localBoardChannel << ")."
228                          << "  Maximum number has been reached." << endl;
229     }
230     return false;
231   }                      
232
233   // Check if location is present
234   if ( HasLocation(localBoardId, localBoardChannel) ) {
235     if (warn) {
236       AliWarningStream() << "Cannot add location: "
237                          << localBoardId << "," << localBoardChannel << ")."
238                          << "  Location is already present." << endl;
239     }
240     return false;
241   } 
242   
243   // Add location
244   if ( ! fLLocations)
245     fLLocations = new MpPair_t[fgkMaxNofLocations];
246   
247   fLLocations[fNofLocations++] 
248     = AliMp::Pair(localBoardId, localBoardChannel);
249
250   return true;
251 }
252
253 //_____________________________________________________________________________
254 Int_t  AliMpPad::GetManuId() const
255 {
256 /// Return pad manu Id 
257
258   return AliMp::PairFirst(fLLocation);
259 }  
260
261 //_____________________________________________________________________________
262 Int_t  AliMpPad::GetManuChannel() const
263 {
264 /// Return pad manu channel
265
266   return AliMp::PairSecond(fLLocation);
267 }  
268
269 //_____________________________________________________________________________
270 Int_t  AliMpPad::GetIx() const
271 {
272 /// Return pad index ix
273
274   return AliMp::PairFirst(fLIndices);
275 }  
276
277 //_____________________________________________________________________________
278 Int_t  AliMpPad::GetIy() const
279 {
280 /// Return pad index iy
281
282   return AliMp::PairSecond(fLIndices);
283 }  
284
285 //_____________________________________________________________________________
286 void AliMpPad::PrintOn(ostream& out) const
287 {
288 /// Prints all pad data.
289
290   if ( !fValidity ) {
291     out << "Pad::Invalid";
292     return;
293   }  
294
295   out << "Pad: Location ";
296   AliMp::PairPut(out, fLLocation)
297       << "  Indices ";     
298   AliMp::PairPut(out,fLIndices)
299       << "  Position "
300       << "(" << fPositionX << "," << fPositionY << ")"
301       << "  Dimensions "
302       << "(" << fDimensionX << "," << fDimensionY << ")";
303
304   if ( GetNofLocations() ) {
305     out << endl;
306     out << "     Other locations: ";
307
308     for (Int_t i=0; i<GetNofLocations(); i++) 
309         AliMp::PairPut(out,GetLocation(i)) << "  ";
310   }
311 }
312
313 //_____________________________________________________________________________
314 void AliMpPad::Print(const char* /*option*/) const
315 {
316 /// Prints all pad data.
317
318   PrintOn(cout);
319   cout << endl;
320 }
321
322 //_____________________________________________________________________________
323 Int_t  AliMpPad::GetNofLocations() const
324 {
325 /// Return number of other locations associated with this pad
326
327   if (!fLLocations) return 0;
328   
329   return fNofLocations;
330 }  
331   
332
333 //_____________________________________________________________________________
334 MpPair_t AliMpPad::GetLocation(Int_t i) const
335 {
336 /// Return i-th other location associated with this pad
337
338   if ( !fLLocations || i<0 || i>=GetNofLocations() ) 
339     return 0;
340
341   return fLLocations[i];
342 }  
343
344 //_____________________________________________________________________________
345 Int_t AliMpPad::GetLocalBoardId(Int_t i) const
346 {
347 /// Return i-th other local board Id associated with this pad
348
349   if ( !fLLocations || i<0 || i>=GetNofLocations() ) 
350     return 0;
351
352   return AliMp::PairFirst(fLLocations[i]);
353 }  
354
355 //_____________________________________________________________________________
356 Int_t AliMpPad::GetLocalBoardChannel(Int_t i) const
357 {
358 /// Return i-th other local board channel associated with this pad
359
360   if ( !fLLocations || i<0 || i>=GetNofLocations() ) 
361     return 0;
362
363   return AliMp::PairSecond(fLLocations[i]);
364 }  
365
366 //_____________________________________________________________________________
367 Bool_t AliMpPad::HasLocation(Int_t localBoardId, Int_t localBoardChannel) const
368 {
369 /// Return true if given location is present either as fLLocation
370 /// or in the collectio
371
372   MpPair_t location = AliMp::Pair(localBoardId, localBoardChannel);
373
374   if (fLLocation == location) return true;
375
376   for ( Int_t i=0; i<GetNofLocations(); i++ ) {
377     if ( GetLocation(i) == location ) return true;
378   }
379     
380   return false;
381 }      
382
383 //_____________________________________________________________________________
384 ostream& operator<< (ostream &out, const AliMpPad& pad)
385 {
386 /// Output streaming
387
388   pad.PrintOn(out);
389
390   return out;
391 }
392