]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpPad.cxx
Replacement of AliMpIntPair object with algoritmic
[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 // foreign operators
45 //
46
47 //_____________________________________________________________________________
48 Bool_t operator==(const TVector2& v1,const TVector2& v2)
49 {
50   return v1.X()==v2.X() && v1.Y()==v2.Y();
51 }
52
53
54 //_____________________________________________________________________________
55 ostream& operator<<(ostream& out,const TVector2& v)
56 {
57   out << '(' << v.X() << ',' << v.Y() << ')';
58   return out; 
59 }
60
61
62 //_____________________________________________________________________________
63 AliMpPad::AliMpPad(Int_t manuId, Int_t channel,
64                    Int_t ix, Int_t iy,
65                    const TVector2& position,const TVector2& dimensions,
66                    Bool_t validity)
67  : TObject(),
68    fLLocations(0),
69    fNofLocations(0),
70    fLLocation(AliMp::Pair(manuId, channel)),
71    fLIndices(AliMp::Pair(ix, iy)),
72    fPosition(position),
73    fDimensions(dimensions),
74    fValidity(validity)
75 {
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....
81 }
82
83 //_____________________________________________________________________________
84 AliMpPad::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 }
103
104 //_____________________________________________________________________________
105 AliMpPad::AliMpPad()
106   : TObject(),
107     fLLocations(0),
108     fNofLocations(0),
109     fLLocation(0),
110     fLIndices(0),
111     fPosition(-1.,-1.),
112     fDimensions(0.,0.),
113     fValidity(false) 
114 {
115 /// Default constructor - creates pad in invalid state
116 }
117
118 //_____________________________________________________________________________
119 AliMpPad::AliMpPad(const AliMpPad& rhs)
120   : TObject(rhs),
121     fLLocations(0),
122     fNofLocations(0),
123     fLLocation(0),
124     fLIndices(0),
125     fPosition(-1.,-1.),
126     fDimensions(0.,0.),
127     fValidity(false) 
128 {
129 /// Copy constructor
130
131  *this = rhs;
132 }
133
134 //_____________________________________________________________________________
135 AliMpPad::~AliMpPad() 
136 {
137 /// Destructor
138
139   delete [] fLLocations;
140 }
141
142 //_____________________________________________________________________________
143 AliMpPad& AliMpPad::operator = (const AliMpPad& rhs) 
144 {
145 /// Assignment operator
146  
147   // check assignment to self
148   if (this == &rhs) return *this;
149
150   // base class assignment
151   TObject::operator=(rhs);
152
153   // assignment operator
154   fLLocation   = rhs.fLLocation;
155   fLIndices    = rhs.fLIndices;
156   fPosition.Set(rhs.fPosition);
157   fDimensions.Set(rhs.fDimensions);
158   fValidity = rhs.fValidity;
159   
160   fLLocations = 0;
161   fNofLocations = rhs.fNofLocations;
162   if ( rhs.GetNofLocations() ) {
163     fLLocations = new MpPair_t[fgkMaxNofLocations];
164     for ( UInt_t i=0; i<rhs.fNofLocations; i++ )
165       fLLocations[i] = rhs.fLLocations[i];
166   }                     
167
168   return *this;
169 }
170
171 //_____________________________________________________________________________
172 Bool_t AliMpPad::operator == (const AliMpPad& rhs) const
173 {
174 /// Equality operator
175
176   // are this and rhs equals?
177
178   // one valid, one invalid
179   if (fValidity != rhs.fValidity) return false;
180   
181   // both invalid
182   if (!fValidity) return true;
183   
184   // both valid
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   
193   return    (fLLocation  == rhs.fLLocation) 
194          && (fLIndices   == rhs.fLIndices)
195          && (fPosition   == rhs.fPosition) 
196          && (fDimensions == rhs.fDimensions)
197          && sameLocations;
198 }
199 //_____________________________________________________________________________
200 Bool_t AliMpPad::operator != (const AliMpPad& rhs) const
201 {
202 /// Non-equality operator
203
204   // are this and rhs equals?
205   return !(*this==rhs);
206 }
207
208 //_____________________________________________________________________________
209 Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
210 {
211 /// Less operator
212
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;
217 }
218
219 //_____________________________________________________________________________
220 Bool_t AliMpPad::AddLocation(Int_t localBoardId, Int_t localBoardChannel, 
221                              Bool_t warn)
222 {
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. 
227
228   // Check maximum number limit
229   if ( GetNofLocations() == fgkMaxNofLocations ) {
230     if (warn) {
231       AliWarningStream() << "Cannot add location: ("
232                          << localBoardId << "," << localBoardChannel << ")."
233                          << "  Maximum number has been reached." << endl;
234     }
235     return false;
236   }                      
237
238   // Check if location is present
239   if ( HasLocation(localBoardId, localBoardChannel) ) {
240     if (warn) {
241       AliWarningStream() << "Cannot add location: "
242                          << localBoardId << "," << localBoardChannel << ")."
243                          << "  Location is already present." << endl;
244     }
245     return false;
246   } 
247   
248   // Add location
249   if ( ! fLLocations)
250     fLLocations = new MpPair_t[fgkMaxNofLocations];
251   
252   fLLocations[fNofLocations++] 
253     = AliMp::Pair(localBoardId, localBoardChannel);
254
255   return true;
256 }
257
258 //_____________________________________________________________________________
259 Int_t  AliMpPad::GetManuId() const
260 {
261 /// Return pad manu Id 
262
263   return AliMp::PairFirst(fLLocation);
264 }  
265
266 //_____________________________________________________________________________
267 Int_t  AliMpPad::GetManuChannel() const
268 {
269 /// Return pad manu channel
270
271   return AliMp::PairSecond(fLLocation);
272 }  
273
274 //_____________________________________________________________________________
275 Int_t  AliMpPad::GetIx() const
276 {
277 /// Return pad index ix
278
279   return AliMp::PairFirst(fLIndices);
280 }  
281
282 //_____________________________________________________________________________
283 Int_t  AliMpPad::GetIy() const
284 {
285 /// Return pad index iy
286
287   return AliMp::PairSecond(fLIndices);
288 }  
289
290 //_____________________________________________________________________________
291 void AliMpPad::PrintOn(ostream& out) const
292 {
293 /// Prints all pad data.
294
295   if ( !fValidity ) {
296     out << "Pad::Invalid";
297     return;
298   }  
299
300   out << "Pad: Location ";
301   AliMp::PairPut(out, fLLocation)
302       << "  Indices ";     
303   AliMp::PairPut(out,fLIndices)
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++) 
312         AliMp::PairPut(out,GetLocation(i)) << "  ";
313   }
314 }
315
316 //_____________________________________________________________________________
317 void AliMpPad::Print(const char* /*option*/) const
318 {
319 /// Prints all pad data.
320
321   PrintOn(cout);
322   cout << endl;
323 }
324
325 //_____________________________________________________________________________
326 Int_t  AliMpPad::GetNofLocations() const
327 {
328 /// Return number of other locations associated with this pad
329
330   if (!fLLocations) return 0;
331   
332   return fNofLocations;
333 }  
334   
335
336 //_____________________________________________________________________________
337 MpPair_t AliMpPad::GetLocation(Int_t i) const
338 {
339 /// Return i-th other location associated with this pad
340
341   if ( !fLLocations || i<0 || i>=GetNofLocations() ) 
342     return 0;
343
344   return fLLocations[i];
345 }  
346
347 //_____________________________________________________________________________
348 Int_t AliMpPad::GetLocalBoardId(Int_t i) const
349 {
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 //_____________________________________________________________________________
359 Int_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 //_____________________________________________________________________________
370 Bool_t AliMpPad::HasLocation(Int_t localBoardId, Int_t localBoardChannel) const
371 {
372 /// Return true if given location is present either as fLLocation
373 /// or in the collectio
374
375   MpPair_t location = AliMp::Pair(localBoardId, localBoardChannel);
376
377   if (fLLocation == location) return true;
378
379   for ( Int_t i=0; i<GetNofLocations(); i++ ) {
380     if ( GetLocation(i) == location ) return true;
381   }
382     
383   return false;
384 }      
385
386 //_____________________________________________________________________________
387 ostream& operator<< (ostream &out, const AliMpPad& pad)
388 {
389 /// Output streaming
390
391   pad.PrintOn(out);
392
393   return out;
394 }
395