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