]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSlatSegmentation.cxx
Work around for CINT bug in root 5.10/00, with gcc4.0.2
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSlatSegmentation.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: AliMpSlatSegmentation.cxx,v 1.9 2006/03/14 09:04:28 ivana Exp $
18
19 // Caution !!
20 // Implementation note.
21 // The position(s) used in the interface are supposed to be relative
22 // to the slat center (AliMpSlat::Position()), whereas internally
23 // the x,y are relative to bottom-left corner.
24
25 #include "AliMpSlatSegmentation.h"
26
27 #include "AliLog.h"
28 #include "AliMpArea.h"
29 #include "AliMpConnection.h"
30 #include "AliMpMotif.h"
31 #include "AliMpMotifPosition.h"
32 #include "AliMpMotifType.h"
33 #include "AliMpPCB.h"
34 #include "AliMpSlat.h"
35 #include "AliMpSlatPadIterator.h"
36
37 ClassImp(AliMpSlatSegmentation)
38
39 //_____________________________________________________________________________
40 AliMpSlatSegmentation::AliMpSlatSegmentation() 
41 : AliMpVSegmentation(),
42 fkSlat(0)
43 {
44   //
45   // Default ctor. Not to be used really.
46   //
47   AliDebug(1,Form("this=%p Empty ctor",this));
48 }
49
50 //_____________________________________________________________________________
51 AliMpSlatSegmentation::AliMpSlatSegmentation(const AliMpSlat* slat) 
52 : AliMpVSegmentation(), 
53 fkSlat(slat)
54 {
55   //
56   // Normal ctor.
57   //
58   AliDebug(1,Form("this=%p Normal ctor slat=%p",this,slat));
59 }
60
61 //______________________________________________________________________________
62 AliMpSlatSegmentation::AliMpSlatSegmentation(const AliMpSlatSegmentation& right) 
63   : AliMpVSegmentation(right) 
64 {  
65 /// Protected copy constructor (not implemented)
66
67   AliFatal("Copy constructor not provided.");
68 }
69
70 //_____________________________________________________________________________
71 AliMpSlatSegmentation::~AliMpSlatSegmentation()
72 {
73   //
74   // Dtor (empty).
75   //
76   // Int_t i(0);//just to be able to put a breakpoint in gdb
77   AliDebug(1,Form("this=%p",this));                     
78 }
79
80 //______________________________________________________________________________
81 AliMpSlatSegmentation& 
82 AliMpSlatSegmentation::operator=(const AliMpSlatSegmentation& right)
83 {
84 /// Protected assignement operator (not implemented)
85
86   // check assignement to self
87   if (this == &right) return *this;
88
89   AliFatal("Assignement operator not provided.");
90     
91   return *this;  
92 }    
93
94 //_____________________________________________________________________________
95 AliMpVPadIterator*
96 AliMpSlatSegmentation::CreateIterator(const AliMpArea& area) const
97 {
98   //
99   // Returns an iterator to loop over the pad contained within given area.
100   //
101   AliMpArea a(area.Position()+fkSlat->Position(),area.Dimensions());
102   AliDebug(3,Form("Converted input area wrt to slat center : "
103                   "%7.2f,%7.2f->%7.2f,%7.2f to wrt slat lower-left : "
104                   "%7.2f,%7.2f->%7.2f,%7.2f ",
105                   area.LeftBorder(),area.DownBorder(),
106                   area.RightBorder(),area.UpBorder(),
107                   a.LeftBorder(),a.DownBorder(),
108                   a.RightBorder(),a.UpBorder()));
109                   
110   return new AliMpSlatPadIterator(fkSlat,a);
111 }
112
113 //_____________________________________________________________________________
114 TVector2
115 AliMpSlatSegmentation::Dimensions() const
116 {
117   return Slat()->Dimensions();
118 }
119
120 //_____________________________________________________________________________
121 void 
122 AliMpSlatSegmentation::GetAllElectronicCardIDs(TArrayI& ecn) const
123 {
124   Slat()->GetAllMotifPositionsIDs(ecn);
125 }
126
127 //_____________________________________________________________________________
128 const char*
129 AliMpSlatSegmentation::GetName() const
130 {
131   TString name("SlatSegmentation");
132   if ( fkSlat) 
133   {
134     name += ".";
135     name += fkSlat->GetName();
136   }
137   return name.Data();
138 }
139
140 //_____________________________________________________________________________
141 Bool_t
142 AliMpSlatSegmentation::HasPad(const AliMpIntPair& indices) const
143 {
144   //
145   // Test if this slat has a pad located at the position referenced
146   // by the integer indices.
147   //
148   
149   return PadByIndices(indices,kFALSE) != AliMpPad::Invalid();
150 }
151
152 //_____________________________________________________________________________
153 Int_t 
154 AliMpSlatSegmentation::MaxPadIndexX() const
155 {
156   //
157   // Returns the value of the largest pad index in x-direction.
158   //
159   
160   return fkSlat->GetMaxPadIndexX();
161 }
162
163 //_____________________________________________________________________________
164 Int_t 
165 AliMpSlatSegmentation::MaxPadIndexY() const
166 {
167   //
168   // Returns the value of the largest pad index in y-direction.
169   //
170   
171   return fkSlat->GetMaxNofPadsY()-1;
172 }
173
174 //_____________________________________________________________________________
175 Int_t 
176 AliMpSlatSegmentation::NofPads() const
177 {
178 /// Return number of pads defined in the slat
179   
180   AliError("Not yet implemented");
181
182   return 0;
183 }
184
185 //_____________________________________________________________________________
186 AliMpPad
187 AliMpSlatSegmentation::PadByLocation(const AliMpIntPair& location, 
188                                      Bool_t warning) const
189 {
190   //
191   // Returns the pad specified by its location, where location is the 
192   // pair (ManuID,ManuChannel).
193   // If warning=kTRUE and the pad does not exist, a warning message is 
194   // printed.
195   //
196   // AliMpPad::Invalid() is returned if there's no pad at the given location.
197   //
198   Int_t manuID = location.GetFirst();
199         
200   AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(manuID);
201         
202   if (!motifPos)
203         {
204                 if (warning)
205                 {
206                         AliWarning(Form("Manu ID %d not found in slat %s",
207                                          manuID, fkSlat->GetID()));
208     }
209     return AliMpPad::Invalid();
210         }
211   AliMpVMotif* motif = motifPos->GetMotif();
212   AliMpIntPair localIndices = 
213     motif->GetMotifType()->FindLocalIndicesByGassiNum(location.GetSecond());
214         
215   if (!localIndices.IsValid()) 
216         {
217                 if (warning) 
218                 {
219                         AliWarning(Form("The pad number %d doesn't exists",
220                                         location.GetSecond()));
221                 }
222                 return AliMpPad::Invalid();
223         }
224         
225   return AliMpPad(location,
226                   motifPos->GlobalIndices(localIndices),
227                   motifPos->Position() 
228                   + motif->PadPositionLocal(localIndices) 
229                   - fkSlat->Position(),
230                   motif->GetPadDimensions(localIndices));  
231 }
232
233 //_____________________________________________________________________________
234 AliMpPad
235 AliMpSlatSegmentation::PadByIndices(const AliMpIntPair& indices, 
236                                     Bool_t warning) const
237 {
238   //
239   // Returns the pad specified by its integer indices.
240   // If warning=kTRUE and the pad does not exist, a warning message is 
241   // printed.
242   //
243   // AliMpPad::Invalid() is returned if there's no pad at the given location.
244   //
245   //  
246   // FIXME: except for the FindMotifPosition below, this method
247   // is exactly as the one in AliMpSectorSegmentation.
248   // See if we can merge them somehow.
249         
250   AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(indices.GetFirst(),
251                                                                                                                                                                                                          indices.GetSecond());
252   if (!motifPos)
253         {
254                 if ( warning ) 
255                 {
256                         AliWarning(Form("No motif found containing pad location (%d,%d)",
257                                          indices.GetFirst(),indices.GetSecond()));        
258                 }
259                 return AliMpPad::Invalid();
260         }
261         
262   AliMpVMotif* motif = motifPos->GetMotif();
263   AliMpMotifType* motifType = motif->GetMotifType();
264   AliMpIntPair localIndices(indices-motifPos->GetLowIndicesLimit());
265   AliMpConnection* connection = motifType->FindConnectionByLocalIndices(localIndices);
266   
267   if (!connection)
268         {
269                 if ( warning )
270                 {
271                         AliWarning(Form("No connection for pad location (%d,%d)",
272                                         indices.GetFirst(),indices.GetSecond()));
273     }
274     return AliMpPad::Invalid();
275         }
276         
277   return AliMpPad(AliMpIntPair(motifPos->GetID(),connection->GetGassiNum()),
278                   indices,
279                   motifPos->Position()
280                   + motif->PadPositionLocal(localIndices)
281                   - fkSlat->Position(),
282                   motif->GetPadDimensions(localIndices));
283 }
284
285 //_____________________________________________________________________________
286 AliMpPad
287 AliMpSlatSegmentation::PadByPosition(const TVector2& position, 
288                                      Bool_t warning) const
289 {
290   //
291   // Returns the pad specified by its (floating point) position.
292   // If warning=kTRUE and the pad does not exist, a warning message is 
293   // printed.
294   //
295   // AliMpPad::Invalid() is returned if there's no pad at the given location.
296   //
297   
298   TVector2 blPos(position+fkSlat->Position()); // position relative to 
299   // bottom-left of the slat.
300   
301   AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(blPos.X(),blPos.Y());
302         
303   if (!motifPos)
304         {
305                 if (warning) 
306                 {
307                         AliWarning(Form("Slat %s Position (%e,%e)/center (%e,%e)/bottom-left cm "
308                       " outside limits",fkSlat->GetID(),
309                       position.X(),position.Y(),
310                       blPos.X(),blPos.Y()));
311                 }
312                 return AliMpPad::Invalid();
313         }
314         
315   AliMpVMotif* motif =  motifPos->GetMotif();  
316   AliMpIntPair localIndices 
317     = motif->PadIndicesLocal(blPos-motifPos->Position());
318         
319   AliMpConnection* connect = 
320     motif->GetMotifType()->FindConnectionByLocalIndices(localIndices);
321         
322   if (!connect)
323         {
324                 if (warning) 
325                 {
326                         AliWarning(Form("Slat %s localIndices (%d,%d) outside motif %s limits",
327                       fkSlat->GetID(),localIndices.GetFirst(),
328                       localIndices.GetSecond(),motif->GetID().Data()));
329                 }
330                 return AliMpPad::Invalid();
331         }
332   
333   return AliMpPad(AliMpIntPair(motifPos->GetID(),connect->GetGassiNum()),
334                   motifPos->GlobalIndices(localIndices),
335                   motifPos->Position()
336                   + motif->PadPositionLocal(localIndices)
337                   - fkSlat->Position(),
338                   motif->GetPadDimensions(localIndices));  
339 }
340
341 //_____________________________________________________________________________
342 AliMpPlaneType
343 AliMpSlatSegmentation::PlaneType() const
344 {
345   return Slat()->PlaneType();
346 }
347
348 //_____________________________________________________________________________
349 void
350 AliMpSlatSegmentation::Print(Option_t* opt) const
351 {
352   fkSlat->Print(opt);
353 }
354
355 //_____________________________________________________________________________
356 const AliMpSlat* 
357 AliMpSlatSegmentation::Slat() const
358 {
359   //
360   // Returns the pointer to the referenced slat.
361   //
362   
363   return fkSlat;
364 }