]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSlat.cxx
Fixing a problem due the fact that MaxPadIndexX might be different
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSlat.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: AliMpSlat.cxx,v 1.2 2005/09/19 19:01:31 ivana Exp $
18
19 #include "AliMpSlat.h"
20
21 #include "AliLog.h"
22 #include "AliMpConnection.h"
23 #include "AliMpMotif.h"
24 #include "AliMpMotifPosition.h"
25 #include "AliMpMotifType.h"
26 #include "AliMpPCB.h"
27 #include "AliMpSlatPadIterator.h"
28
29 #include "Riostream.h"
30
31 #include "TArrayI.h"
32
33 ClassImp(AliMpSlat)
34
35 //_____________________________________________________________________________
36 AliMpSlat::AliMpSlat() 
37 : TObject(), 
38   fId(""), 
39   fPlaneType(kNonBendingPlane),
40   fDX(0), 
41   fDY(0),
42   fNofPadsX(0), 
43   fMaxNofPadsY(0),
44   fManuMap()
45 {
46     //
47     // Empty ctor.
48     //
49   AliDebug(1,Form("this=%p Empty ctor",this));
50 }
51
52 //_____________________________________________________________________________
53 AliMpSlat::AliMpSlat(const char* id, AliMpPlaneType bendingOrNonBending)
54 : TObject(), 
55   fId(id), 
56   fPlaneType(bendingOrNonBending),
57   fDX(0), 
58   fDY(0),
59   fNofPadsX(0), 
60   fMaxNofPadsY(0),
61   fManuMap(kTRUE)
62 {
63     //
64     // Normal ctor
65     //
66         AliDebug(1,Form("this=%p id=%s",this,id));                      
67 }
68
69 //_____________________________________________________________________________
70 AliMpSlat::~AliMpSlat()
71 {
72   //
73   // Dtor.
74   //
75                 AliDebug(1,Form("this=%p fId=%s",this,fId.Data()));                     
76 }
77
78 //_____________________________________________________________________________
79 void
80 AliMpSlat::Add(AliMpPCB* pcbType, const TArrayI& manuList) 
81 {
82   //
83   // Adds a PCB to this slat. The manuList speficy the ids of the manu
84   // that compose the PCB. The manuList ordering is important, as the 
85   // assumption is that it's ordered counter-clockwise, starting from
86   // the lower-left of the PCB.
87   //
88   Int_t ixOffset = 0;
89   if ( GetSize() )
90         {
91                 ixOffset = GetPCB(GetSize()-1)->Ixmax()+1;
92         }
93   else
94   {
95     ixOffset = pcbType->Ixmin();
96   }
97   Double_t xOffset = DX()*2;
98   AliMpPCB* pcb = pcbType->Clone(manuList,ixOffset,xOffset);
99 #ifdef WITH_ROOT
100   fPCBs.AddLast(pcb);
101 #else
102   fPCBs.push_back(pcb);
103 #endif  
104   fDY = TMath::Max(pcb->DY(),fDY);
105   fDX += pcb->DX();
106   fNofPadsX += pcb->GetNofPadsX();
107   fMaxNofPadsY = std::max(fMaxNofPadsY,pcb->GetNofPadsY());
108   for ( AliMpPCB::Size_t i = 0; i < pcb->GetSize(); ++i )
109         {
110                 AliMpMotifPosition* mp = pcb->GetMotifPosition(i);
111                 Int_t manuID = mp->GetID();
112     // Before inserting a new key, check if it's already there
113 #ifdef WITH_ROOT
114     TObject* there = fManuMap.GetValue(manuID);
115     if ( there == 0 )
116     {
117       fManuMap.Add(manuID,(TObject*)mp);
118     }
119     else
120     {
121       AliError(Form("ManuID %d is duplicated for PCB %s",manuID,pcbType->GetID()));      
122     }
123 #else
124   fManuMap[manuID] = mp;
125 #endif  
126         }
127   fPosition.Set(DX(),DY());
128 }
129
130 //_____________________________________________________________________________
131 TVector2
132 AliMpSlat::Dimensions() const
133 {
134   //
135   // Returns the half-sizes of the slat.
136   //
137   return TVector2(DX(),DY());
138 }
139
140 //_____________________________________________________________________________
141 Double_t
142 AliMpSlat::DX() const
143 {
144   //
145   // Returns the x-half-size of the slat.
146   //
147   return fDX;
148 }
149
150 //_____________________________________________________________________________
151 Double_t
152 AliMpSlat::DY() const
153 {
154   //
155   // Returns the y-half-size of the slat.
156   //
157   return fDY;
158 }
159
160 //_____________________________________________________________________________
161 AliMpMotifPosition*
162 AliMpSlat::FindMotifPosition(Int_t manuID) const
163 {
164   //
165   // Returns the motifPosition referenced by it manuID
166   //
167 #ifdef WITH_ROOT
168   TObject* rv = fManuMap.GetValue(manuID);
169   if ( rv )
170   {
171     return (AliMpMotifPosition*)(rv);
172   }
173   else
174   {
175     return 0;
176   }
177 #else
178   std::map<int,AliMpMotifPosition*>::const_iterator it = fManuMap.find(manuID);
179   if ( it != fManuMap.end() )
180       {
181               return it->second;
182       }
183   else
184   {
185     return 0;
186   }
187 #endif      
188 }
189
190 //_____________________________________________________________________________
191 AliMpMotifPosition*
192 AliMpSlat::FindMotifPosition(Int_t ix, Int_t iy) const
193 {
194   //
195   // 1. Find the PCB containing ix (iy not needed for this)
196   // 2. Forward the request to the PCB, using pcb local indices.
197         //
198   const AliMpPCB* pcb = FindPCB(ix);
199   if ( pcb )
200         {
201                 return pcb->FindMotifPosition(ix,iy);
202         }
203   else
204         {
205                 return 0;
206         }
207 }
208
209 //_____________________________________________________________________________
210 AliMpMotifPosition*
211 AliMpSlat::FindMotifPosition(Double_t x, Double_t y) const
212 {
213   //
214   // Returns the motifPosition containing position (x,y)
215   //
216   const AliMpPCB* pcb = FindPCB(x,y);
217   if (pcb)
218         {
219                 return pcb->FindMotifPosition(x,y);
220         }
221   else
222         {
223                 return 0;
224         }
225 }
226
227 //_____________________________________________________________________________
228 AliMpPCB*
229 AliMpSlat::FindPCB(Int_t ix) const
230 {
231   //
232   // Returns the PCB containing x-integer-position ix
233   //
234   for ( Size_t i = 0; i < GetSize(); ++i ) 
235         {
236                 AliMpPCB* pcb = GetPCB(i);
237                 if ( ix >= pcb->Ixmin() && ix <= pcb->Ixmax() )
238                 {
239                         return pcb;
240                 }
241         }
242   return 0;
243 }
244
245 //_____________________________________________________________________________
246 Int_t
247 AliMpSlat::FindPCBIndex(Int_t ix) const
248 {
249   //
250   // Returns the index of the PCB containing x-integer-position ix.
251   //
252   for ( Size_t i = 0; i < GetSize(); ++i ) 
253         {
254                 AliMpPCB* pcb = GetPCB(i);
255                 if ( ix >= pcb->Ixmin() && ix <= pcb->Ixmax() )
256                 {
257                         return i;
258                 }
259         }
260   return -1;
261 }
262
263 //_____________________________________________________________________________
264 AliMpPCB*
265 AliMpSlat::FindPCB(Double_t x, Double_t y) const
266 {
267   //
268   // Returns the PCB containing position (x,y)
269   //
270   for ( Size_t i = 0; i < GetSize(); ++i ) 
271         {
272                 AliMpPCB* pcb = GetPCB(i);
273                 if ( x >= pcb->Xmin() && x < pcb->Xmax() &&
274                                  y >= pcb->Ymin() && y < pcb->Ymax() )
275                 {
276                         return pcb;
277                 }
278         }
279   return 0;
280 }
281
282 //_____________________________________________________________________________
283 Int_t
284 AliMpSlat::FindPCBIndex(Double_t x, Double_t y) const
285 {
286   //
287   // Returns the index of the PCB containing position (x,y)
288   //
289   for ( Size_t i = 0; i < GetSize(); ++i ) 
290         {
291                 AliMpPCB* pcb = GetPCB(i);
292                 if ( x >= pcb->Xmin() && x < pcb->Xmax() &&
293                                  y >= pcb->Ymin() && y < pcb->Ymax() )
294                 {
295                         return i;
296                 }
297         }
298   return -1;
299 }
300
301 //_____________________________________________________________________________
302 void
303 AliMpSlat::ForcePosition(const TVector2& pos)
304 {
305   //
306   // Force the position to be different from (DX(),DY()).
307   // Normally only used by triggerSlats (for layers).
308   // Beware that this method must be called once all PCB have been added,
309   // as the Add() method resets the position.
310   //
311   fPosition = pos;
312 }
313
314 //_____________________________________________________________________________
315 void
316 AliMpSlat::GetAllElectronicCardNumbers(TArrayI& ecn) const
317 {
318   ecn.Set(GetNofElectronicCards());
319   TExMapIter it(fManuMap.GetIterator());
320   Long_t key;
321   Long_t value;
322   Int_t n(0);
323   while ( it.Next(key,value) == kTRUE )
324   {
325     ecn.AddAt((Int_t)(key),n);
326     ++n;
327   }
328 }
329
330 //_____________________________________________________________________________
331 const char*
332 AliMpSlat::GetID() const
333 {
334   //
335   // Returns the name of this slat.
336   //
337   return fId.Data();
338 }
339
340 //_____________________________________________________________________________
341 Int_t 
342 AliMpSlat::GetMaxNofPadsY() const
343 {
344   //
345   // Returns the maximum number of pads to be found in this slat y-direction.
346   // 
347   return fMaxNofPadsY;
348 }
349
350 //_____________________________________________________________________________
351 Int_t 
352 AliMpSlat::GetMaxPadIndexX() const
353 {
354   AliMpPCB* last = GetPCB(GetSize()-1);
355   if (last)
356   {
357     return last->Ixmax();
358   }
359   return 0;
360 }
361
362 //_____________________________________________________________________________
363 const char*
364 AliMpSlat::GetName() const
365 {
366   TString name(GetID());
367   if ( fPlaneType == kBendingPlane )
368   {
369     name += ".Bending";
370   }
371   else if ( fPlaneType == kNonBendingPlane )
372   {
373     name += ".NonBending";
374   }
375   else
376   {
377     name += ".Invalid";
378   }
379   return name.Data();  
380 }
381
382 //_____________________________________________________________________________
383 Int_t
384 AliMpSlat::GetNofElectronicCards() const
385 {
386   return fManuMap.GetSize();
387 }
388
389 //_____________________________________________________________________________
390 Int_t
391 AliMpSlat::GetNofPadsX() const
392 {
393   //
394   // Returns the number of pad in x-direction.
395   //
396   return fNofPadsX;
397 }
398
399 //_____________________________________________________________________________
400 AliMpPCB*
401 AliMpSlat::GetPCB(AliMpSlat::Size_t i) const
402 {
403   //
404   // Returns the i-th PCB of this slat.
405   //
406 #ifdef WITH_ROOT
407   if ( i >= fPCBs.GetEntriesFast() ) return 0;
408   return (AliMpPCB*)fPCBs[i];
409 #else
410   if ( i >= fPCBs.size() ) return 0;
411   return fPCBs[i];
412 #endif  
413 }
414
415 //_____________________________________________________________________________
416 AliMpSlat::Size_t
417 AliMpSlat::GetSize() const
418 {
419   //
420   // Returns the number of PCB in this slat.
421   //
422 #ifdef WITH_ROOT
423   return fPCBs.GetEntriesFast();
424 #else
425   return fPCBs.size();
426 #endif  
427 }
428
429 //_____________________________________________________________________________
430 TVector2
431 AliMpSlat::Position() const
432 {
433   return fPosition;
434 }
435
436 //_____________________________________________________________________________
437 void
438 AliMpSlat::Print(Option_t* option) const
439 {
440   //
441   // Prints the slat characteristics.
442   //
443   cout << "SLAT " << GetID() <<  " 1/2 DIM = (" << DX() << "," << DY() << ")"
444   << " POS = " << Position().X() << "," << Position().Y()
445         << " NPADSX = " << GetNofPadsX() 
446   << " MAXNPADSY = " << GetMaxNofPadsY()
447   << " NPCBs=" << GetSize() << endl;
448   
449   TString soption(option);
450   
451   if ( soption.Contains("P") )
452         {
453     for ( Size_t i = 0; i < GetSize() ; ++i )
454                 {
455       cout << "    ";
456                         if ( option )
457             {
458                                 fPCBs[i]->Print(option+1);
459             }
460                         else
461             {
462               fPCBs[i]->Print();
463             }
464                 }
465         }
466   
467   if ( soption.Contains("M") || soption.Contains("L") )
468   {
469     cout << fManuMap.GetSize() << " ";
470     cout << "Electronic card (manu or local board) Ids : ";
471     
472     TExMapIter iter(fManuMap.GetIterator());
473     Long_t key, value;
474     while ( iter.Next(key,value) )
475     {
476       cout << key << " ";
477     }
478     cout << endl;
479   }
480 }