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