]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSlat.cxx
- Reordering includes and/or
[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.4 2006/03/02 16:35:20 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 //#ifdef WITH_ROOT
62   fManuMap(kTRUE)
63 //#else  
64 //  fManuMap()
65 //#endif  
66 {
67     //
68     // Normal ctor
69     //
70         AliDebug(1,Form("this=%p id=%s",this,id));                      
71 }
72
73 //_____________________________________________________________________________
74 AliMpSlat::~AliMpSlat()
75 {
76   //
77   // Dtor.
78   //
79                 AliDebug(1,Form("this=%p fId=%s",this,fId.Data()));                     
80 }
81
82 //_____________________________________________________________________________
83 void
84 AliMpSlat::Add(AliMpPCB* pcbType, const TArrayI& manuList) 
85 {
86   //
87   // Adds a PCB to this slat. The manuList specifies the ids of the manu
88   // that compose the PCB. The manuList ordering is important, as the 
89   // assumption is that it's ordered counter-clockwise, starting from
90   // the lower-left of the PCB.
91   //
92   Int_t ixOffset = 0;
93   if ( GetSize() )
94         {
95                 ixOffset = GetPCB(GetSize()-1)->Ixmax()+1;
96         }
97   else
98   {
99     ixOffset = pcbType->Ixmin();
100   }
101   Double_t xOffset = DX()*2;
102   AliMpPCB* pcb = pcbType->Clone(manuList,ixOffset,xOffset);
103 #ifdef WITH_ROOT
104   fPCBs.AddLast(pcb);
105 #else
106   fPCBs.push_back(pcb);
107 #endif  
108   fDY = TMath::Max(pcb->DY(),fDY);
109   fDX += pcb->DX();
110   fNofPadsX += pcb->GetNofPadsX();
111   fMaxNofPadsY = std::max(fMaxNofPadsY,pcb->GetNofPadsY());
112   for ( AliMpPCB::Size_t i = 0; i < pcb->GetSize(); ++i )
113         {
114                 AliMpMotifPosition* mp = pcb->GetMotifPosition(i);
115                 Int_t manuID = mp->GetID();
116     // Before inserting a new key, check if it's already there
117 //#ifdef WITH_ROOT
118     TObject* there = fManuMap.GetValue(manuID);
119     if ( there == 0 )
120     {
121       fManuMap.Add(manuID,(TObject*)mp);
122     }
123     else
124     {
125       AliError(Form("ManuID %d is duplicated for PCB %s",manuID,pcbType->GetID()));      
126     }
127 //#else
128 //  fManuMap[manuID] = mp;
129 //#endif  
130         }
131   fPosition.Set(DX(),DY());
132 }
133
134 //_____________________________________________________________________________
135 TVector2
136 AliMpSlat::Dimensions() const
137 {
138   //
139   // Returns the half-sizes of the slat.
140   //
141   return TVector2(DX(),DY());
142 }
143
144 //_____________________________________________________________________________
145 Double_t
146 AliMpSlat::DX() const
147 {
148   //
149   // Returns the x-half-size of the slat.
150   //
151   return fDX;
152 }
153
154 //_____________________________________________________________________________
155 Double_t
156 AliMpSlat::DY() const
157 {
158   //
159   // Returns the y-half-size of the slat.
160   //
161   return fDY;
162 }
163
164 //_____________________________________________________________________________
165 AliMpMotifPosition*
166 AliMpSlat::FindMotifPosition(Int_t manuID) const
167 {
168   //
169   // Returns the motifPosition referenced by it manuID
170   //
171 //#ifdef WITH_ROOT
172   return static_cast<AliMpMotifPosition*>(fManuMap.GetValue(manuID));
173 //#else
174 //  std::map<int,AliMpMotifPosition*>::const_iterator it = fManuMap.find(manuID);
175 //  if ( it != fManuMap.end() )
176 //      {
177 //            return it->second;
178 //      }
179 //  else
180 //  {
181 //    return 0;
182 //  }
183 //#endif      
184 }
185
186 //_____________________________________________________________________________
187 AliMpMotifPosition*
188 AliMpSlat::FindMotifPosition(Int_t ix, Int_t iy) const
189 {
190   //
191   // 1. Find the PCB containing ix (iy not needed for this)
192   // 2. Forward the request to the PCB, using pcb local indices.
193         //
194   const AliMpPCB* pcb = FindPCB(ix);
195   if ( pcb )
196         {
197                 return pcb->FindMotifPosition(ix,iy);
198         }
199   else
200         {
201                 return 0;
202         }
203 }
204
205 //_____________________________________________________________________________
206 AliMpMotifPosition*
207 AliMpSlat::FindMotifPosition(Double_t x, Double_t y) const
208 {
209   //
210   // Returns the motifPosition containing position (x,y)
211   //
212   const AliMpPCB* pcb = FindPCB(x,y);
213   if (pcb)
214         {
215                 return pcb->FindMotifPosition(x,y);
216         }
217   else
218         {
219                 return 0;
220         }
221 }
222
223 //_____________________________________________________________________________
224 AliMpPCB*
225 AliMpSlat::FindPCB(Int_t ix) const
226 {
227   //
228   // Returns the PCB containing x-integer-position ix
229   //
230   for ( Size_t i = 0; i < GetSize(); ++i ) 
231         {
232                 AliMpPCB* pcb = GetPCB(i);
233                 if ( ix >= pcb->Ixmin() && ix <= pcb->Ixmax() )
234                 {
235                         return pcb;
236                 }
237         }
238   return 0;
239 }
240
241 //_____________________________________________________________________________
242 Int_t
243 AliMpSlat::FindPCBIndex(Int_t ix) const
244 {
245   //
246   // Returns the index of the PCB containing x-integer-position ix.
247   //
248   for ( Size_t i = 0; i < GetSize(); ++i ) 
249         {
250                 AliMpPCB* pcb = GetPCB(i);
251                 if ( ix >= pcb->Ixmin() && ix <= pcb->Ixmax() )
252                 {
253                         return i;
254                 }
255         }
256   return -1;
257 }
258
259 //_____________________________________________________________________________
260 AliMpPCB*
261 AliMpSlat::FindPCB(Double_t x, Double_t y) const
262 {
263   //
264   // Returns the PCB containing position (x,y)
265   //
266   for ( Size_t i = 0; i < GetSize(); ++i ) 
267         {
268                 AliMpPCB* pcb = GetPCB(i);
269                 if ( x >= pcb->Xmin() && x < pcb->Xmax() &&
270                                  y >= pcb->Ymin() && y < pcb->Ymax() )
271                 {
272                         return pcb;
273                 }
274         }
275   return 0;
276 }
277
278 //_____________________________________________________________________________
279 Int_t
280 AliMpSlat::FindPCBIndex(Double_t x, Double_t y) const
281 {
282   //
283   // Returns the index of the PCB containing position (x,y)
284   //
285   for ( Size_t i = 0; i < GetSize(); ++i ) 
286         {
287                 AliMpPCB* pcb = GetPCB(i);
288                 if ( x >= pcb->Xmin() && x < pcb->Xmax() &&
289                                  y >= pcb->Ymin() && y < pcb->Ymax() )
290                 {
291                         return i;
292                 }
293         }
294   return -1;
295 }
296
297 //_____________________________________________________________________________
298 void
299 AliMpSlat::ForcePosition(const TVector2& pos)
300 {
301   //
302   // Force the position to be different from (DX(),DY()).
303   // Normally only used by triggerSlats (for layers).
304   // Beware that this method must be called once all PCB have been added,
305   // as the Add() method resets the position.
306   //
307   fPosition = pos;
308 }
309
310 //_____________________________________________________________________________
311 void
312 AliMpSlat::GetAllMotifPositionsIDs(TArrayI& ecn) const
313 {
314   ecn.Set(GetNofElectronicCards());
315 //#ifdef WITH_ROOT
316   TExMapIter it(fManuMap.GetIterator());
317   Long_t key;
318   Long_t value;
319   Int_t n(0);
320   while ( it.Next(key,value) == kTRUE )
321   {
322     ecn.AddAt((Int_t)(key),n);
323     ++n;
324   }
325 //#else
326   // missing here
327 //#endif      
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 AliMpPlaneType
431 AliMpSlat::PlaneType() const
432 {
433   return fPlaneType;
434 }
435
436 //_____________________________________________________________________________
437 TVector2
438 AliMpSlat::Position() const
439 {
440   return fPosition;
441 }
442
443 //_____________________________________________________________________________
444 void
445 AliMpSlat::Print(Option_t* option) const
446 {
447   //
448   // Prints the slat characteristics.
449   //
450   cout << "SLAT " << GetID() <<  " 1/2 DIM = (" << DX() << "," << DY() << ")"
451   << " POS = " << Position().X() << "," << Position().Y()
452         << " NPADSX = " << GetNofPadsX() 
453   << " MAXNPADSY = " << GetMaxNofPadsY()
454   << " NPCBs=" << GetSize() << endl;
455   
456   TString soption(option);
457   
458   if ( soption.Contains("P") )
459         {
460     for ( Size_t i = 0; i < GetSize() ; ++i )
461                 {
462       cout << "    ";
463                         if ( option )
464             {
465                                 fPCBs[i]->Print(option+1);
466             }
467                         else
468             {
469               fPCBs[i]->Print();
470             }
471                 }
472         }
473   
474   if ( soption.Contains("M") || soption.Contains("L") )
475   {
476     cout << fManuMap.GetSize() << " ";
477     cout << "Electronic card (manu or local board) Ids : ";
478     
479     TExMapIter iter(fManuMap.GetIterator());
480     Long_t key, value;
481     while ( iter.Next(key,value) )
482     {
483       cout << key << " ";
484     }
485     cout << endl;
486   }
487 }