]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSlat.cxx
Changing __sparc to __sun to compile on solarisCC5
[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   fDX(0), 
40   fDY(0),
41   fNofPadsX(0), 
42   fMaxNofPadsY(0)
43 {
44     //
45     // Empty ctor.
46     //
47   AliDebug(1,Form("this=%p Empty ctor",this));
48 }
49
50 //_____________________________________________________________________________
51 AliMpSlat::AliMpSlat(const char* id)
52 : TObject(), 
53   fId(id), 
54   fDX(0), 
55   fDY(0),
56   fNofPadsX(0), 
57   fMaxNofPadsY(0)
58 {
59     //
60     // Normal ctor
61     //
62         AliDebug(1,Form("this=%p id=%s",this,id));                      
63 }
64
65 //_____________________________________________________________________________
66 AliMpSlat::~AliMpSlat()
67 {
68   //
69   // Dtor.
70   //
71                 AliDebug(1,Form("this=%p fId=%s",this,fId.Data()));                     
72 }
73
74 //_____________________________________________________________________________
75 void
76 AliMpSlat::Add(AliMpPCB* pcbType, const TArrayI& manuList) 
77 {
78   //
79   // Adds a PCB to this slat. The manuList speficy the ids of the manu
80   // that compose the PCB. The manuList ordering is important, as the 
81   // assumption is that it's ordered counter-clockwise, starting from
82   // the lower-left of the PCB.
83   //
84   Int_t ixOffset = 0;
85   if ( GetSize() )
86         {
87                 ixOffset = GetPCB(GetSize()-1)->Ixmax()+1;
88         }
89   Double_t xOffset = DX()*2;
90   AliMpPCB* pcb = pcbType->Clone(manuList,ixOffset,xOffset);
91 #ifdef WITH_ROOT
92   fPCBs.AddLast(pcb);
93 #else
94   fPCBs.push_back(pcb);
95 #endif  
96   fDY = pcb->DY();
97   fDX += pcb->DX();
98   fNofPadsX += pcb->GetNofPadsX();
99   fMaxNofPadsY = std::max(fMaxNofPadsY,pcb->GetNofPadsY());
100   for ( AliMpPCB::Size_t i = 0; i < pcb->GetSize(); ++i )
101         {
102                 AliMpMotifPosition* mp = pcb->GetMotifPosition(i);
103                 Int_t manuID = mp->GetID();
104     // Before inserting a new key, check if it's already there
105 #ifdef WITH_ROOT
106     Long_t there = fManuMap.GetValue((Long_t)manuID);
107     if ( there == 0 )
108     {
109       fManuMap.Add((Long_t)manuID,(Long_t)mp);
110     }
111     else
112     {
113       AliError(Form("ManuID %d is duplicated for PCB %s",manuID,pcbType->GetID()));      
114     }
115 #else
116   fManuMap[manuID] = mp;
117 #endif  
118         }
119 }
120
121 //_____________________________________________________________________________
122 TVector2
123 AliMpSlat::Dimensions() const
124 {
125   //
126   // Returns the half-sizes of the slat.
127   //
128   return TVector2(DX(),DY());
129 }
130
131 //_____________________________________________________________________________
132 Double_t
133 AliMpSlat::DX() const
134 {
135   //
136   // Returns the x-half-size of the slat.
137   //
138   return fDX;
139 }
140
141 //_____________________________________________________________________________
142 Double_t
143 AliMpSlat::DY() const
144 {
145   //
146   // Returns the y-half-size of the slat.
147   //
148   return fDY;
149 }
150
151 //_____________________________________________________________________________
152 AliMpMotifPosition*
153 AliMpSlat::FindMotifPosition(Int_t manuID) const
154 {
155   //
156   // Returns the motifPosition referenced by it manuID
157   //
158 #ifdef WITH_ROOT
159   Long_t rv = fManuMap.GetValue((Long_t)manuID);
160   if ( rv )
161   {
162     return (AliMpMotifPosition*)(rv);
163   }
164   else
165   {
166     return 0;
167   }
168 #else
169   std::map<int,AliMpMotifPosition*>::const_iterator it = fManuMap.find(manuID);
170   if ( it != fManuMap.end() )
171       {
172               return it->second;
173       }
174   else
175   {
176     return 0;
177   }
178 #endif      
179 }
180
181 //_____________________________________________________________________________
182 AliMpMotifPosition*
183 AliMpSlat::FindMotifPosition(Int_t ix, Int_t iy) const
184 {
185   //
186   // 1. Find the PCB containing ix (iy not needed for this)
187   // 2. Forward the request to the PCB, using pcb local indices.
188         //
189   const AliMpPCB* pcb = FindPCB(ix);
190   if ( pcb )
191         {
192                 return pcb->FindMotifPosition(ix,iy);
193         }
194   else
195         {
196                 return 0;
197         }
198 }
199
200 //_____________________________________________________________________________
201 AliMpMotifPosition*
202 AliMpSlat::FindMotifPosition(Double_t x, Double_t y) const
203 {
204   //
205   // Returns the motifPosition containing position (x,y)
206   //
207   const AliMpPCB* pcb = FindPCB(x,y);
208   if (pcb)
209         {
210                 return pcb->FindMotifPosition(x,y);
211         }
212   else
213         {
214                 return 0;
215         }
216 }
217
218 //_____________________________________________________________________________
219 AliMpPCB*
220 AliMpSlat::FindPCB(Int_t ix) const
221 {
222   //
223   // Returns the PCB containing x-integer-position ix
224   //
225   for ( Size_t i = 0; i < GetSize(); ++i ) 
226         {
227                 AliMpPCB* pcb = GetPCB(i);
228                 if ( ix >= pcb->Ixmin() && ix <= pcb->Ixmax() )
229                 {
230                         return pcb;
231                 }
232         }
233   return 0;
234 }
235
236 //_____________________________________________________________________________
237 Int_t
238 AliMpSlat::FindPCBIndex(Int_t ix) const
239 {
240   //
241   // Returns the index of 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 i;
249                 }
250         }
251   return -1;
252 }
253
254 //_____________________________________________________________________________
255 AliMpPCB*
256 AliMpSlat::FindPCB(Double_t x, Double_t y) const
257 {
258   //
259   // Returns the PCB containing position (x,y)
260   //
261   for ( Size_t i = 0; i < GetSize(); ++i ) 
262         {
263                 AliMpPCB* pcb = GetPCB(i);
264                 if ( x >= pcb->Xmin() && x < pcb->Xmax() &&
265                                  y >= pcb->Ymin() && y < pcb->Ymax() )
266                 {
267                         return pcb;
268                 }
269         }
270   return 0;
271 }
272
273 //_____________________________________________________________________________
274 Int_t
275 AliMpSlat::FindPCBIndex(Double_t x, Double_t y) const
276 {
277   //
278   // Returns the index of the PCB containing position (x,y)
279   //
280   for ( Size_t i = 0; i < GetSize(); ++i ) 
281         {
282                 AliMpPCB* pcb = GetPCB(i);
283                 if ( x >= pcb->Xmin() && x < pcb->Xmax() &&
284                                  y >= pcb->Ymin() && y < pcb->Ymax() )
285                 {
286                         return i;
287                 }
288         }
289   return -1;
290 }
291
292 //_____________________________________________________________________________
293 const char*
294 AliMpSlat::GetID() const
295 {
296   //
297   // Returns the name of this slat.
298   //
299   return fId.Data();
300 }
301
302 //_____________________________________________________________________________
303 Int_t 
304 AliMpSlat::GetMaxNofPadsY() const
305 {
306   //
307   // Returns the maximum number of pads to be found in this slat y-direction.
308   // 
309   return fMaxNofPadsY;
310 }
311
312 //_____________________________________________________________________________
313 Int_t
314 AliMpSlat::GetNofPadsX() const
315 {
316   //
317   // Returns the number of pad in x-direction.
318   //
319   return fNofPadsX;
320 }
321
322 //_____________________________________________________________________________
323 AliMpPCB*
324 AliMpSlat::GetPCB(AliMpSlat::Size_t i) const
325 {
326   //
327   // Returns the i-th PCB of this slat.
328   //
329 #ifdef WITH_ROOT
330   if ( i >= fPCBs.GetEntriesFast() ) return 0;
331   return (AliMpPCB*)fPCBs[i];
332 #else
333   if ( i >= fPCBs.size() ) return 0;
334   return fPCBs[i];
335 #endif  
336 }
337
338 //_____________________________________________________________________________
339 AliMpSlat::Size_t
340 AliMpSlat::GetSize() const
341 {
342   //
343   // Returns the number of PCB in this slat.
344   //
345 #ifdef WITH_ROOT
346   return fPCBs.GetEntriesFast();
347 #else
348   return fPCBs.size();
349 #endif  
350 }
351
352 //_____________________________________________________________________________
353 void
354 AliMpSlat::Print(Option_t* option) const
355 {
356   //
357   // Prints the slat characteristics.
358   //
359   cout << "SLAT " << GetID() <<  " 1/2 DIM = (" << DX() << "," << DY() << ")"
360         << " NPADSX = " << GetNofPadsX() << " NPCBs=" << GetSize() << endl;
361   
362   if ( option && option[0] == 'P' )
363         {
364     for ( Size_t i = 0; i < GetSize() ; ++i )
365                 {
366       cout << "    ";
367                         if ( option )
368             {
369                                 fPCBs[i]->Print(option+1);
370             }
371                         else
372             {
373               fPCBs[i]->Print();
374             }
375                 }
376         }
377 }