AliRoot Core  d69033e (d69033e)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMpSegmentation.cxx
Go to the documentation of this file.
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: AliMpSegmentation.cxx,v 1.7 2006/05/24 13:58:34 ivana Exp $
18 // Category: management
19 
20 //-----------------------------------------------------------------------------
21 // Class AliMpSegmentation
22 // -----------------------
23 // Singleton container class for mapping segmentations
24 // Authors: Ivana Hrivnacova, IPN Orsay
25 // Laurent Aphecetche, SUBATECH
26 //-----------------------------------------------------------------------------
27 
28 #include "AliMpSegmentation.h"
29 
30 #include "AliMpDataStreams.h"
31 #include "AliMpDetElement.h"
32 #include "AliMpDEStore.h"
33 #include "AliMpDEManager.h"
34 #include "AliMpDEIterator.h"
35 #include "AliMpExMap.h"
36 #include "AliMpFastSegmentation.h"
37 //#include "AliMpFastSegmentationV2.h"
38 #include "AliMpSector.h"
39 #include "AliMpSectorReader.h"
41 #include "AliMpSlat.h"
42 #include "AliMpSlatSegmentation.h"
43 #include "AliMpSt345Reader.h"
44 #include "AliMpTrigger.h"
45 #include "AliMpTriggerReader.h"
47 #include "AliMpCathodType.h"
48 #include "AliMpSlatMotifMap.h"
49 
50 
51 #include "AliLog.h"
52 
53 #include <Riostream.h>
54 #include <TMap.h>
55 #include <TObjString.h>
56 #include <TSystem.h>
57 #include <TClass.h>
58 
59 #include <cassert>
60 
64 
65 AliMpSegmentation* AliMpSegmentation::fgInstance = 0;
66 
67 //
68 // static methods
69 //
70 
71 //______________________________________________________________________________
72 AliMpSegmentation* AliMpSegmentation::Instance(Bool_t warn)
73 {
75 
76  if ( ! fgInstance && warn ) {
77  AliWarningClass("Segmentation has not been loaded");
78  }
79 
80  return fgInstance;
81 }
82 
83 //______________________________________________________________________________
85  Bool_t warn)
86 {
89 
90  if ( fgInstance ) {
91  if ( warn )
92  AliWarningClass("Segmentation has been already loaded");
93  return fgInstance;
94  }
95 
96  if ( dataStreams.GetReadFromFiles() )
97  AliInfoClass("Reading segmentation from ASCII files.");
98 
99  fgInstance = new AliMpSegmentation(dataStreams);
100  return fgInstance;
101 }
102 
103 //
104 // ctors, dtor
105 //
106 
107 //______________________________________________________________________________
109 : TObject(),
110  fDetElements(0),
111  fMpSegmentations(true),
112  fElCardsMap(),
113  fSlatMotifMap(new AliMpSlatMotifMap)
114 {
116 
117  AliDebug(1,"");
118 
119  fElCardsMap.SetOwner(kTRUE);
120 
121  // Load DE data
122  if ( ! AliMpDEStore::Instance(false) )
123  AliMpDEStore::ReadData(dataStreams);
125 
126  // Create mapping segmentations for all detection elements
127  AliMpDEIterator it;
128  for ( it.First(); ! it.IsDone(); it.Next() )
129  {
130  Int_t n(0);
131 
132  for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; ++cath )
133  {
134  if ( CreateMpSegmentation(dataStreams,
135  it.CurrentDEId(), AliMp::GetCathodType(cath)) ) ++n;
136  }
137 
138  if ( n == 2 && // should always be the case except when we play with the CreateMpSegmentation method...
140  {
141  // Fill el cards map for all detection elements
142  // of tracking chambers
144  }
145  }
146 }
147 
148 //______________________________________________________________________________
150 : TObject(),
151  fDetElements(0),
152  fMpSegmentations(),
153  fElCardsMap(ioCtor),
154  fSlatMotifMap(0)
155 {
157 
158  AliDebug(1,"");
159 
160  fgInstance = this;
161 }
162 
163 //______________________________________________________________________________
165 {
167 
168  AliDebug(1,"");
169 
170  delete fDetElements;
171 
172  // Segmentations are deleted with fMpSegmentations
173  // El cards arrays are deleted with fElCardsMap
174 
175  delete fSlatMotifMap;
176 
177  fgInstance = 0;
178 }
179 
180 //
181 // private methods
182 //
183 
184 //______________________________________________________________________________
187  Int_t detElemId, AliMp::CathodType cath)
188 {
191 
192  // Check detElemId & cath
193  if ( ! AliMpDEManager::IsValidDetElemId(detElemId, true) ) return 0;
194 
195  // If segmentation is already built, just return it
196  //
197  AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
198  TString deSegName = detElement->GetSegName(cath);
199  TObject* object = fMpSegmentations.Get(deSegName);
200  if ( object ) return (AliMpVSegmentation*)object;
201 
202  AliDebugStream(3)
203  << "Creating segmentation for detElemId=" << detElemId
204  << " cath=" << cath << endl;
205 
206  // Read mapping data and create segmentation
207  //
208  AliMp::StationType stationType = detElement->GetStationType();
209  AliMp::PlaneType planeType = detElement->GetPlaneType(cath);
210  TString deTypeName = detElement->GetSegType();
211 
212  AliMpVSegmentation* mpSegmentation = 0;
213 
214  if ( stationType == AliMp::kStation12 ) {
215  AliMq::Station12Type station12Type = detElement->GetStation12Type();
216  AliMpSectorReader reader(station12Type, planeType);
217  AliMpSector* sector = reader.BuildSector(dataStreams);
218  mpSegmentation = new AliMpFastSegmentation(new AliMpSectorSegmentation(sector, true));
219  }
220  else if ( stationType == AliMp::kStation345 ) {
222  AliMpSlat* slat = reader.ReadSlat(dataStreams, deTypeName, planeType);
223  mpSegmentation = new AliMpFastSegmentation(new AliMpSlatSegmentation(slat, true));
224  }
225  else if ( stationType == AliMp::kStationTrigger ) {
227  AliMpTrigger* trigger = reader.ReadSlat(dataStreams, deTypeName, planeType);
228  mpSegmentation = new AliMpTriggerSegmentation(trigger, true);
229  }
230  else
231  AliErrorStream() << "Unknown station type" << endl;
232 
233  if ( mpSegmentation ) fMpSegmentations.Add(deSegName, mpSegmentation);
234 
235 // StdoutToAliDebug(3, fSlatMotifMap.Print(););
236 
237  return mpSegmentation;
238 }
239 
240 //_____________________________________________________________________________
241 AliMpExMap*
243 {
246 
247  AliDebugStream(2) << "detElemId=" << detElemId << endl;;
248 
249  AliMpExMap* mde = new AliMpExMap;
250  mde->SetOwner(kFALSE);
251  fElCardsMap.Add(detElemId,mde);
252 
253  const AliMpVSegmentation* seg[2];
254  TArrayI ecn[2];
255 
256  for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++cathode )
257  {
258  seg[cathode] = GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
259  seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
260  for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
261  {
262  mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
263  }
264  }
265 
266  assert( mde->GetSize() > 0 );
267 
268  return mde;
269 
270 }
271 
272 //
273 // public methods
274 //
275 
276 //______________________________________________________________________________
277 const AliMpVSegmentation*
279  Int_t detElemId, AliMp::CathodType cath, Bool_t warn) const
280 {
282 
283  // Check detElemId & cath
284  if ( ! AliMpDEManager::IsValidDetElemId(detElemId, false) ) {
285 
286  if ( warn ) {
287  AliWarningStream()
288  << "Invalid detElemId " << detElemId << endl;
289  }
290  return 0;
291  }
292 
293  // If segmentation is already built, just return it
294  //
295  AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
296  TString deSegName = detElement->GetSegName(cath);
297  TObject* object = fMpSegmentations.Get(deSegName);
298  if ( ! object ) {
299  // Should never happen
300  AliErrorStream()
301  << "Segmentation for detElemId/cathod "
302  << detElemId << ", " << cath << " not defined" << endl;
303  return 0;
304  }
305 
306  return static_cast<AliMpVSegmentation*>(object);
307 }
308 
309 //_____________________________________________________________________________
310 const AliMpVSegmentation*
312  Int_t detElemId, Int_t ecId, Bool_t warn) const
313 {
316 
317  AliMpExMap* m = static_cast<AliMpExMap*>(fElCardsMap.GetValue(detElemId));
318 
319  if (!m) {
320  // Should never happen
321  AliErrorStream()
322  << "Cannot find the el cards map for detElemId " << detElemId << endl;
323  return 0;
324  }
325 
326  TObject* object = m->GetValue(ecId);
327  if ( ! object ) {
328  if ( warn ) {
329  AliErrorStream()
330  << "Segmentation for electronic card "
331  << ecId << " not found" << endl;
332  }
333  return 0;
334  }
335 
336  return static_cast<AliMpVSegmentation*>(object);
337 }
338 
339 //_____________________________________________________________________________
340 const AliMpSector*
342  Bool_t warn) const
343 {
347 
348  if ( ! kSegmentation ) return 0;
349 
350  if ( kSegmentation->StationType() != AliMp::kStation12 ) {
351  if ( warn ) {
352  AliErrorStream()
353  << "Segmentation is not of sector type" << endl;
354  }
355  return 0;
356  }
357 
358  // If fast segmentation
359  const AliMpFastSegmentation* fseg
360  = dynamic_cast<const AliMpFastSegmentation*>(kSegmentation);
361  if ( fseg ) {
362  return
363  static_cast<const AliMpSectorSegmentation*>(fseg->GetHelper())->GetSector();
364  }
365 
366  // If fast segmentation V2
367 /*
368  const AliMpFastSegmentationV2* fsegV2
369  = dynamic_cast<const AliMpFastSegmentationV2*>(kSegmentation);
370  if ( fsegV2 ) {
371  return
372  static_cast<const AliMpSectorSegmentation*>(fsegV2->GetHelper())->GetSector();
373  }
374 */
375  // If sector segmentation
376  const AliMpSectorSegmentation* sseg
377  = dynamic_cast<const AliMpSectorSegmentation*>(kSegmentation);
378  if ( sseg ) {
379  return sseg->GetSector();
380  }
381 
382  // Should not get to this line
383  AliErrorStream() << "Segemntation type not identified." << endl;
384  return 0;
385 }
386 
387 //_____________________________________________________________________________
388 const AliMpSector*
390  Bool_t warn) const
391 {
395 
396  return GetSector(GetMpSegmentation(detElemId, cath, warn), warn);
397 }
398 
399 //_____________________________________________________________________________
400 const AliMpSector*
401 AliMpSegmentation::GetSectorByElectronics(Int_t detElemId, Int_t elCardID,
402  Bool_t warn) const
403 {
407 
408  return GetSector(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);
409 }
410 
411 //_____________________________________________________________________________
412 const AliMpSlat*
414  Bool_t warn) const
415 {
419 
420  if ( ! kSegmentation ) return 0;
421 
422  if ( kSegmentation->StationType() != AliMp::kStation345 ) {
423  if ( warn ) {
424  AliErrorStream()
425  << "Segmentation is not of slat type" << endl;
426  }
427  return 0;
428  }
429 
430  // If fast segmentation
431  const AliMpFastSegmentation* fseg
432  = dynamic_cast<const AliMpFastSegmentation*>(kSegmentation);
433  if ( fseg ) {
434  return
435  static_cast<const AliMpSlatSegmentation*>(fseg->GetHelper())->Slat();
436  }
437 
438  // If fast segmentation V2
439 /*
440  const AliMpFastSegmentationV2* fsegV2
441  = dynamic_cast<const AliMpFastSegmentationV2*>(kSegmentation);
442  if ( fsegV2 ) {
443  return
444  static_cast<const AliMpSlatSegmentation*>(fsegV2->GetHelper())->Slat();
445  }
446 */
447  // If slat segmentation
448  const AliMpSlatSegmentation* sseg
449  = dynamic_cast<const AliMpSlatSegmentation*>(kSegmentation);
450 
451  if ( sseg ) {
452  return sseg->Slat();
453  }
454 
455  // Should not get to this line
456  AliErrorStream() << "Segemntation type not identified." << endl;
457  return 0;
458 }
459 
460 //_____________________________________________________________________________
461 const AliMpSlat*
463  Bool_t warn) const
464 {
468 
469  return GetSlat(GetMpSegmentation(detElemId, cath, warn), warn);
470 }
471 
472 //_____________________________________________________________________________
473 const AliMpSlat*
474 AliMpSegmentation::GetSlatByElectronics(Int_t detElemId, Int_t elCardID,
475  Bool_t warn) const
476 {
480 
481  return GetSlat(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);
482 }
483 
484 //_____________________________________________________________________________
485 const AliMpTrigger*
487  Bool_t warn) const
488 {
492 
493  if ( ! kSegmentation ) return 0;
494 
495  if ( kSegmentation->StationType() != AliMp::kStationTrigger ) {
496  if ( warn ) {
497  AliErrorStream()
498  << "Segmentation is not of trigger type" << endl;
499  }
500  return 0;
501  }
502 
503  // If slat segmentation
504  const AliMpTriggerSegmentation* tseg
505  = dynamic_cast<const AliMpTriggerSegmentation*>(kSegmentation);
506  if ( tseg ) {
507  return tseg->Slat();
508  }
509 
510  // If fast segmentation
511  const AliMpFastSegmentation* fseg
512  = dynamic_cast<const AliMpFastSegmentation*>(kSegmentation);
513 
514  if ( fseg ) {
515  return
516  static_cast<const AliMpTriggerSegmentation*>(fseg->GetHelper())->Slat();
517  }
518 
519  // If fast segmentation V2
520 /*
521  const AliMpFastSegmentationV2* fsegV2
522  = dynamic_cast<const AliMpFastSegmentationV2*>(kSegmentation);
523 
524  if ( fsegV2 ) {
525  return
526  static_cast<const AliMpTriggerSegmentation*>(fsegV2->GetHelper())->Slat();
527  }
528 */
529 
530  // Should not get to this line
531  AliErrorStream() << "Segemntation type not identified." << endl;
532  return 0;
533 }
534 
535 //_____________________________________________________________________________
536 const AliMpTrigger*
538  Bool_t warn) const
539 {
543 
544  return GetTrigger(GetMpSegmentation(detElemId, cath, warn), warn);
545 }
546 
547 //_____________________________________________________________________________
548 const AliMpTrigger*
549 AliMpSegmentation::GetTriggerByElectronics(Int_t detElemId, Int_t elCardID,
550  Bool_t warn) const
551 {
555 
556  return GetTrigger(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);
557 }
Singleton container class for mapping segmentations.
const AliMpSlat * Slat() const
The iterator over detection elements.
const AliMpVSegmentation * GetMpSegmentation(Int_t detElemId, AliMp::CathodType cath, Bool_t warn=true) const
station 1,2 (quadrants)
AliMpSlatMotifMap * fSlatMotifMap
Map of motif, motifTypes to avoid duplications and allow proper deletion.
Read trigger slat ASCII files.
AliMpVSegmentation * GetHelper() const
Return helper class.
static AliMpDEStore * Instance(Bool_t warn=true)
AliMpVSegmentation * CreateMpSegmentation(const AliMpDataStreams &dataStreams, Int_t detElemId, AliMp::CathodType cath)
const AliMpSector * GetSector() const
Return the sector.
AliMpSegmentation(TRootIOCtor *ioCtor)
const AliMpSlat * GetSlatByElectronics(Int_t detElemId, Int_t elCardID, Bool_t warn=true) const
AliMq::Station12Type GetStation12Type() const
Bool_t IsDone() const
const AliMpSlat * GetSlat(const AliMpVSegmentation *kSegmentation, Bool_t warn=true) const
AliMp::StationType GetStationType() const
station 3,4,5 (slats)
Bool_t Add(const TString &first, TObject *second)
static AliMpSegmentation * ReadData(const AliMpDataStreams &dataStreams, Bool_t warn=true)
Class that takes care of reading the sector data.
const AliMpVSegmentation * GetMpSegmentationByElectronics(Int_t detElemId, Int_t elCardID, Bool_t warn=true) const
AliMpSector * BuildSector(const AliMpDataStreams &dataStreams)
Int_t CurrentDEId() const
A slat (building block of stations 3, 4 and 5)
Definition: AliMpSlat.h:51
The class defines the electronics properties of detection element.
const AliMpTrigger * Slat() const
A container to keep track of allocated motifs and motifTypes for slats (both St345 and trigger ones)...
TString GetSegName(AliMp::CathodType cath) const
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
Int_t GetSize() const
Definition: AliMpExMap.cxx:340
A trigger slat.
Definition: AliMpTrigger.h:37
virtual AliMp::StationType StationType() const =0
Return the station type.
const AliMpSector * GetSector(const AliMpVSegmentation *kSegmentation, Bool_t warn=true) const
AliMpSlat * ReadSlat(const AliMpDataStreams &dataStreams, const char *slatType, AliMp::PlaneType planeType)
Implementation of AliMpVSegmentation for trigger slats.
const AliMpSector * GetSectorByElectronics(Int_t detElemId, Int_t elCardID, Bool_t warn=true) const
AliMpExMap * FillElCardsMap(Int_t detElemId)
static AliMpDEStore * ReadData(const AliMpDataStreams &dataStreams, Bool_t warn=true)
static AliMp::StationType GetStationType(Int_t detElemId)
AliMp::PlaneType GetPlaneType(AliMp::CathodType cath) const
AliMpExMap fElCardsMap
Map of el. cards IDs to segmentations.
TObject * GetValue(Int_t keyFirst, Int_t keySecond) const
Definition: AliMpExMap.cxx:365
Read slat and pcb ASCII files.
AliMp::CathodType GetCathodType(Int_t cathodNumber)
Convert integer number in enum;.
TObject * Get(const TString &first) const
A sector (quadrant) of the MUON chamber of stations 1 and 2.
Definition: AliMpSector.h:34
void Add(Int_t keyFirst, Int_t keySecond, TObject *object)
Definition: AliMpExMap.cxx:292
Implementation of AliMpVSegmentation for St345 slats.
void SetOwner(Bool_t owner)
Definition: AliMpExMap.cxx:332
A segmentation of the sector.
The abstract base class for the segmentation.
trigger stations (slats)
AliMpTrigger * ReadSlat(const AliMpDataStreams &dataStreams, const char *slatType, AliMp::PlaneType planeType)
AliMpStringObjMap fMpSegmentations
Map of mapping segmentations to DE seg names.
static AliMpDetElement * GetDetElement(Int_t detElemId, Bool_t warn=true)
Fast version of AliMpVSegmentation.
AliMpDEStore * fDetElements
Detection element store.
const AliMpTrigger * GetTrigger(const AliMpVSegmentation *kSegmentation, Bool_t warn=true) const
static Bool_t IsValidDetElemId(Int_t detElemId, Bool_t warn=false)
const AliMpTrigger * GetTriggerByElectronics(Int_t detElemId, Int_t elCardID, Bool_t warn=true) const
Bool_t GetReadFromFiles() const
TString GetSegType() const
Return segmentation type name.
static AliMpSegmentation * fgInstance
Singleton instance.
Helper class making Root persistent TExMap.
Definition: AliMpExMap.h:28
Mapping data streams provider.
virtual void GetAllElectronicCardIDs(TArrayI &ecn) const =0
Fill the given array with the electronic card IDs.