]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSlat.cxx
2b82d57ae86c60b24149e2ecb8781bc50106d8aa
[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 const char*
352 AliMpSlat::GetName() const
353 {
354   TString name(GetID());
355   if ( fPlaneType == kBendingPlane )
356   {
357     name += ".Bending";
358   }
359   else if ( fPlaneType == kNonBendingPlane )
360   {
361     name += ".NonBending";
362   }
363   else
364   {
365     name += ".Invalid";
366   }
367   return name.Data();  
368 }
369
370 //_____________________________________________________________________________
371 Int_t
372 AliMpSlat::GetNofElectronicCards() const
373 {
374   return fManuMap.GetSize();
375 }
376
377 //_____________________________________________________________________________
378 Int_t
379 AliMpSlat::GetNofPadsX() const
380 {
381   //
382   // Returns the number of pad in x-direction.
383   //
384   return fNofPadsX;
385 }
386
387 //_____________________________________________________________________________
388 AliMpPCB*
389 AliMpSlat::GetPCB(AliMpSlat::Size_t i) const
390 {
391   //
392   // Returns the i-th PCB of this slat.
393   //
394 #ifdef WITH_ROOT
395   if ( i >= fPCBs.GetEntriesFast() ) return 0;
396   return (AliMpPCB*)fPCBs[i];
397 #else
398   if ( i >= fPCBs.size() ) return 0;
399   return fPCBs[i];
400 #endif  
401 }
402
403 //_____________________________________________________________________________
404 AliMpSlat::Size_t
405 AliMpSlat::GetSize() const
406 {
407   //
408   // Returns the number of PCB in this slat.
409   //
410 #ifdef WITH_ROOT
411   return fPCBs.GetEntriesFast();
412 #else
413   return fPCBs.size();
414 #endif  
415 }
416
417 //_____________________________________________________________________________
418 TVector2
419 AliMpSlat::Position() const
420 {
421   return fPosition;
422 }
423
424 //_____________________________________________________________________________
425 void
426 AliMpSlat::Print(Option_t* option) const
427 {
428   //
429   // Prints the slat characteristics.
430   //
431   cout << "SLAT " << GetID() <<  " 1/2 DIM = (" << DX() << "," << DY() << ")"
432   << " POS = " << Position().X() << "," << Position().Y()
433         << " NPADSX = " << GetNofPadsX() 
434   << " MAXNPADSY = " << GetMaxNofPadsY()
435   << " NPCBs=" << GetSize() << endl;
436   
437   TString soption(option);
438   
439   if ( soption.Contains("P") )
440         {
441     for ( Size_t i = 0; i < GetSize() ; ++i )
442                 {
443       cout << "    ";
444                         if ( option )
445             {
446                                 fPCBs[i]->Print(option+1);
447             }
448                         else
449             {
450               fPCBs[i]->Print();
451             }
452                 }
453         }
454   
455   if ( soption.Contains("M") || soption.Contains("L") )
456   {
457     cout << fManuMap.GetSize() << " ";
458     cout << "Electronic card (manu or local board) Ids : ";
459     
460     TExMapIter iter(fManuMap.GetIterator());
461     Long_t key, value;
462     while ( iter.Next(key,value) )
463     {
464       cout << key << " ";
465     }
466     cout << endl;
467   }
468 }