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