Change description related to CDB
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSlat.cxx
CommitLineData
dee1d5f1 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$
c9da0af9 17// $MpId: AliMpSlat.cxx,v 1.4 2006/03/02 16:35:20 ivana Exp $
dee1d5f1 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
33ClassImp(AliMpSlat)
34
35//_____________________________________________________________________________
36AliMpSlat::AliMpSlat()
37: TObject(),
38 fId(""),
19b51aad 39 fPlaneType(kNonBendingPlane),
dee1d5f1 40 fDX(0),
41 fDY(0),
42 fNofPadsX(0),
19b51aad 43 fMaxNofPadsY(0),
44 fManuMap()
dee1d5f1 45{
46 //
47 // Empty ctor.
48 //
49 AliDebug(1,Form("this=%p Empty ctor",this));
50}
51
52//_____________________________________________________________________________
19b51aad 53AliMpSlat::AliMpSlat(const char* id, AliMpPlaneType bendingOrNonBending)
dee1d5f1 54: TObject(),
55 fId(id),
19b51aad 56 fPlaneType(bendingOrNonBending),
dee1d5f1 57 fDX(0),
58 fDY(0),
59 fNofPadsX(0),
19b51aad 60 fMaxNofPadsY(0),
0f60374b 61//#ifdef WITH_ROOT
19b51aad 62 fManuMap(kTRUE)
0f60374b 63//#else
64// fManuMap()
65//#endif
dee1d5f1 66{
67 //
68 // Normal ctor
69 //
70 AliDebug(1,Form("this=%p id=%s",this,id));
71}
72
73//_____________________________________________________________________________
74AliMpSlat::~AliMpSlat()
75{
76 //
77 // Dtor.
78 //
79 AliDebug(1,Form("this=%p fId=%s",this,fId.Data()));
80}
81
82//_____________________________________________________________________________
83void
84AliMpSlat::Add(AliMpPCB* pcbType, const TArrayI& manuList)
85{
86 //
c9da0af9 87 // Adds a PCB to this slat. The manuList specifies the ids of the manu
dee1d5f1 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 }
19b51aad 97 else
98 {
99 ixOffset = pcbType->Ixmin();
100 }
dee1d5f1 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
19b51aad 108 fDY = TMath::Max(pcb->DY(),fDY);
dee1d5f1 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
0f60374b 117//#ifdef WITH_ROOT
19b51aad 118 TObject* there = fManuMap.GetValue(manuID);
dee1d5f1 119 if ( there == 0 )
120 {
19b51aad 121 fManuMap.Add(manuID,(TObject*)mp);
dee1d5f1 122 }
123 else
124 {
125 AliError(Form("ManuID %d is duplicated for PCB %s",manuID,pcbType->GetID()));
126 }
0f60374b 127//#else
128// fManuMap[manuID] = mp;
129//#endif
dee1d5f1 130 }
19b51aad 131 fPosition.Set(DX(),DY());
dee1d5f1 132}
133
134//_____________________________________________________________________________
135TVector2
136AliMpSlat::Dimensions() const
137{
138 //
139 // Returns the half-sizes of the slat.
140 //
141 return TVector2(DX(),DY());
142}
143
144//_____________________________________________________________________________
145Double_t
146AliMpSlat::DX() const
147{
148 //
149 // Returns the x-half-size of the slat.
150 //
151 return fDX;
152}
153
154//_____________________________________________________________________________
155Double_t
156AliMpSlat::DY() const
157{
158 //
159 // Returns the y-half-size of the slat.
160 //
161 return fDY;
162}
163
164//_____________________________________________________________________________
165AliMpMotifPosition*
166AliMpSlat::FindMotifPosition(Int_t manuID) const
167{
168 //
169 // Returns the motifPosition referenced by it manuID
170 //
0f60374b 171//#ifdef WITH_ROOT
c9da0af9 172 return static_cast<AliMpMotifPosition*>(fManuMap.GetValue(manuID));
0f60374b 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
dee1d5f1 184}
185
186//_____________________________________________________________________________
187AliMpMotifPosition*
188AliMpSlat::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//_____________________________________________________________________________
206AliMpMotifPosition*
207AliMpSlat::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//_____________________________________________________________________________
224AliMpPCB*
225AliMpSlat::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//_____________________________________________________________________________
242Int_t
243AliMpSlat::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//_____________________________________________________________________________
260AliMpPCB*
261AliMpSlat::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//_____________________________________________________________________________
279Int_t
280AliMpSlat::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
19b51aad 297//_____________________________________________________________________________
298void
299AliMpSlat::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//_____________________________________________________________________________
311void
c9da0af9 312AliMpSlat::GetAllMotifPositionsIDs(TArrayI& ecn) const
19b51aad 313{
314 ecn.Set(GetNofElectronicCards());
0f60374b 315//#ifdef WITH_ROOT
19b51aad 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 }
0f60374b 325//#else
326 // missing here
327//#endif
19b51aad 328}
329
dee1d5f1 330//_____________________________________________________________________________
331const char*
332AliMpSlat::GetID() const
333{
334 //
335 // Returns the name of this slat.
336 //
337 return fId.Data();
338}
339
340//_____________________________________________________________________________
341Int_t
342AliMpSlat::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
16e8fffd 350//_____________________________________________________________________________
351Int_t
352AliMpSlat::GetMaxPadIndexX() const
353{
354 AliMpPCB* last = GetPCB(GetSize()-1);
355 if (last)
356 {
357 return last->Ixmax();
358 }
359 return 0;
360}
361
19b51aad 362//_____________________________________________________________________________
363const char*
364AliMpSlat::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//_____________________________________________________________________________
383Int_t
384AliMpSlat::GetNofElectronicCards() const
385{
386 return fManuMap.GetSize();
387}
388
dee1d5f1 389//_____________________________________________________________________________
390Int_t
391AliMpSlat::GetNofPadsX() const
392{
393 //
394 // Returns the number of pad in x-direction.
395 //
396 return fNofPadsX;
397}
398
399//_____________________________________________________________________________
400AliMpPCB*
401AliMpSlat::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//_____________________________________________________________________________
416AliMpSlat::Size_t
417AliMpSlat::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
c9da0af9 429//_____________________________________________________________________________
430AliMpPlaneType
431AliMpSlat::PlaneType() const
432{
433 return fPlaneType;
434}
435
19b51aad 436//_____________________________________________________________________________
437TVector2
438AliMpSlat::Position() const
439{
440 return fPosition;
441}
442
dee1d5f1 443//_____________________________________________________________________________
444void
445AliMpSlat::Print(Option_t* option) const
446{
447 //
448 // Prints the slat characteristics.
449 //
450 cout << "SLAT " << GetID() << " 1/2 DIM = (" << DX() << "," << DY() << ")"
19b51aad 451 << " POS = " << Position().X() << "," << Position().Y()
452 << " NPADSX = " << GetNofPadsX()
453 << " MAXNPADSY = " << GetMaxNofPadsY()
454 << " NPCBs=" << GetSize() << endl;
455
456 TString soption(option);
dee1d5f1 457
19b51aad 458 if ( soption.Contains("P") )
dee1d5f1 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 }
19b51aad 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 }
dee1d5f1 487}