Correct use of ROOT_INCLUDE_DIR
[u/mrichter/AliRoot.git] / MUON / MUONmapping / AliMpSegmentation.cxx
CommitLineData
cf9a1555 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
490da820 16// $Id$
69417637 17// $MpId: AliMpSegmentation.cxx,v 1.7 2006/05/24 13:58:34 ivana Exp $
490da820 18// Category: management
700013f0 19
3d1463c8 20//-----------------------------------------------------------------------------
69417637 21// Class AliMpSegmentation
490da820 22// -----------------------
69417637 23// Singleton container class for mapping segmentations
490da820 24// Authors: Ivana Hrivnacova, IPN Orsay
2c605e66 25// Laurent Aphecetche, SUBATECH
3d1463c8 26//-----------------------------------------------------------------------------
cf9a1555 27
69417637 28#include "AliMpSegmentation.h"
b802839b 29
228fd720 30#include "AliMpDataStreams.h"
cddd101e 31#include "AliMpDetElement.h"
24f9bd97 32#include "AliMpDEStore.h"
cf9a1555 33#include "AliMpDEManager.h"
69417637 34#include "AliMpDEIterator.h"
b802839b 35#include "AliMpExMap.h"
7a170a5c 36#include "AliMpFastSegmentation.h"
6e97fbb8 37//#include "AliMpFastSegmentationV2.h"
cf9a1555 38#include "AliMpSector.h"
39#include "AliMpSectorReader.h"
40#include "AliMpSectorSegmentation.h"
41#include "AliMpSlat.h"
cf9a1555 42#include "AliMpSlatSegmentation.h"
b802839b 43#include "AliMpSt345Reader.h"
cf9a1555 44#include "AliMpTrigger.h"
45#include "AliMpTriggerReader.h"
46#include "AliMpTriggerSegmentation.h"
cddd101e 47#include "AliMpCathodType.h"
dede1525 48#include "AliMpSlatMotifMap.h"
49
2c605e66 50
51#include "AliLog.h"
52
cf9a1555 53#include <Riostream.h>
cf9a1555 54#include <TMap.h>
b802839b 55#include <TObjString.h>
56#include <TSystem.h>
5f377a9a 57#include <TClass.h>
cf9a1555 58
630711ed 59#include <cassert>
60
13985652 61/// \cond CLASSIMP
69417637 62ClassImp(AliMpSegmentation)
13985652 63/// \endcond
cf9a1555 64
69417637 65AliMpSegmentation* AliMpSegmentation::fgInstance = 0;
66
67//
68// static methods
69//
70
71//______________________________________________________________________________
5f377a9a 72AliMpSegmentation* AliMpSegmentation::Instance(Bool_t warn)
69417637 73{
5f377a9a 74/// Return its instance
69417637 75
5f377a9a 76 if ( ! fgInstance && warn ) {
77 AliWarningClass("Segmentation has not been loaded");
78 }
69417637 79
80 return fgInstance;
81}
82
5f377a9a 83//______________________________________________________________________________
ab167304 84AliMpSegmentation* AliMpSegmentation::ReadData(const AliMpDataStreams& dataStreams,
d2d10ee1 85 Bool_t warn)
5f377a9a 86{
87/// Load the sementation from ASCII data files
d2d10ee1 88/// and return its instance
5f377a9a 89
90 if ( fgInstance ) {
91 if ( warn )
92 AliWarningClass("Segmentation has been already loaded");
93 return fgInstance;
94 }
95
d2d10ee1 96 if ( dataStreams.GetReadFromFiles() )
97 AliInfoClass("Reading segmentation from ASCII files.");
5f377a9a 98
d2d10ee1 99 fgInstance = new AliMpSegmentation(dataStreams);
5f377a9a 100 return fgInstance;
101}
102
69417637 103//
104// ctors, dtor
105//
0cfc27d7 106
cf9a1555 107//______________________________________________________________________________
ab167304 108AliMpSegmentation::AliMpSegmentation(const AliMpDataStreams& dataStreams)
b802839b 109: TObject(),
24f9bd97 110 fDetElements(0),
183279c1 111 fMpSegmentations(true),
630711ed 112 fElCardsMap(),
183279c1 113 fSlatMotifMap(new AliMpSlatMotifMap)
cf9a1555 114{
5f377a9a 115/// Standard constructor - segmentation is loaded from ASCII data files
69417637 116
117 AliDebug(1,"");
24f9bd97 118
183279c1 119 fElCardsMap.SetOwner(kTRUE);
120
24f9bd97 121 // Load DE data
122 if ( ! AliMpDEStore::Instance(false) )
ab167304 123 AliMpDEStore::ReadData(dataStreams);
24f9bd97 124 fDetElements = AliMpDEStore::Instance();
d2d10ee1 125
69417637 126 // Create mapping segmentations for all detection elements
69417637 127 AliMpDEIterator it;
630711ed 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 {
21027e5a 134 if ( CreateMpSegmentation(dataStreams,
135 it.CurrentDEId(), AliMp::GetCathodType(cath)) ) ++n;
f54f81ea 136 }
630711ed 137
138 if ( n == 2 && // should always be the case except when we play with the CreateMpSegmentation method...
139 AliMpDEManager::GetStationType(it.CurrentDEId()) != AliMp::kStationTrigger ) // only for tracker
140 {
141 // Fill el cards map for all detection elements
142 // of tracking chambers
143 FillElCardsMap(it.CurrentDEId());
144 }
145 }
cf9a1555 146}
147
148//______________________________________________________________________________
630711ed 149AliMpSegmentation::AliMpSegmentation(TRootIOCtor* ioCtor)
69417637 150: TObject(),
24f9bd97 151 fDetElements(0),
69417637 152 fMpSegmentations(),
630711ed 153 fElCardsMap(ioCtor),
dede1525 154 fSlatMotifMap(0)
69417637 155{
156/// Constructor for IO
157
cddd101e 158 AliDebug(1,"");
159
69417637 160 fgInstance = this;
161}
cf9a1555 162
69417637 163//______________________________________________________________________________
164AliMpSegmentation::~AliMpSegmentation()
cf9a1555 165{
166/// Destructor
167
b802839b 168 AliDebug(1,"");
490da820 169
24f9bd97 170 delete fDetElements;
171
69417637 172 // Segmentations are deleted with fMpSegmentations
173 // El cards arrays are deleted with fElCardsMap
490da820 174
183279c1 175 delete fSlatMotifMap;
176
69417637 177 fgInstance = 0;
490da820 178}
179
180//
69417637 181// private methods
cf9a1555 182//
183
184//______________________________________________________________________________
185AliMpVSegmentation*
21027e5a 186AliMpSegmentation::CreateMpSegmentation(const AliMpDataStreams& dataStreams,
187 Int_t detElemId, AliMp::CathodType cath)
cf9a1555 188{
189/// Create mapping segmentation for given detElemId and cath
190/// or return it if it was already built
191
192 // Check detElemId & cath
cddd101e 193 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, true) ) return 0;
cf9a1555 194
195 // If segmentation is already built, just return it
196 //
cddd101e 197 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
198 TString deSegName = detElement->GetSegName(cath);
199 TObject* object = fMpSegmentations.Get(deSegName);
cf9a1555 200 if ( object ) return (AliMpVSegmentation*)object;
201
0cfc27d7 202 AliDebugStream(3)
203 << "Creating segmentation for detElemId=" << detElemId
204 << " cath=" << cath << endl;
b802839b 205
cf9a1555 206 // Read mapping data and create segmentation
207 //
cddd101e 208 AliMp::StationType stationType = detElement->GetStationType();
209 AliMp::PlaneType planeType = detElement->GetPlaneType(cath);
210 TString deTypeName = detElement->GetSegType();
cf9a1555 211
212 AliMpVSegmentation* mpSegmentation = 0;
213
4e51cfd2 214 if ( stationType == AliMp::kStation12 ) {
215 AliMq::Station12Type station12Type = detElement->GetStation12Type();
21027e5a 216 AliMpSectorReader reader(station12Type, planeType);
217 AliMpSector* sector = reader.BuildSector(dataStreams);
7a170a5c 218 mpSegmentation = new AliMpFastSegmentation(new AliMpSectorSegmentation(sector, true));
cf9a1555 219 }
cddd101e 220 else if ( stationType == AliMp::kStation345 ) {
21027e5a 221 AliMpSt345Reader reader(fSlatMotifMap);
222 AliMpSlat* slat = reader.ReadSlat(dataStreams, deTypeName, planeType);
7a170a5c 223 mpSegmentation = new AliMpFastSegmentation(new AliMpSlatSegmentation(slat, true));
cf9a1555 224 }
cddd101e 225 else if ( stationType == AliMp::kStationTrigger ) {
21027e5a 226 AliMpTriggerReader reader(fSlatMotifMap);
227 AliMpTrigger* trigger = reader.ReadSlat(dataStreams, deTypeName, planeType);
69417637 228 mpSegmentation = new AliMpTriggerSegmentation(trigger, true);
cf9a1555 229 }
230 else
231 AliErrorStream() << "Unknown station type" << endl;
232
630711ed 233 if ( mpSegmentation ) fMpSegmentations.Add(deSegName, mpSegmentation);
f54f81ea 234
1a3b5b04 235// StdoutToAliDebug(3, fSlatMotifMap.Print(););
f54f81ea 236
cf9a1555 237 return mpSegmentation;
238}
b802839b 239
240//_____________________________________________________________________________
69417637 241AliMpExMap*
242AliMpSegmentation::FillElCardsMap(Int_t detElemId)
b802839b 243{
69417637 244/// Fill the map of electronic cards IDs to segmentations for
245/// given detElemId
490da820 246
69417637 247 AliDebugStream(2) << "detElemId=" << detElemId << endl;;
b802839b 248
630711ed 249 AliMpExMap* mde = new AliMpExMap;
69417637 250 mde->SetOwner(kFALSE);
251 fElCardsMap.Add(detElemId,mde);
252
253 const AliMpVSegmentation* seg[2];
254 TArrayI ecn[2];
255
cddd101e 256 for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++cathode )
b802839b 257 {
cddd101e 258 seg[cathode] = GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
69417637 259 seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
69417637 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
630711ed 266 assert( mde->GetSize() > 0 );
267
69417637 268 return mde;
630711ed 269
b802839b 270}
69417637 271
272//
273// public methods
274//
275
cf9a1555 276//______________________________________________________________________________
69417637 277const AliMpVSegmentation*
278AliMpSegmentation::GetMpSegmentation(
cddd101e 279 Int_t detElemId, AliMp::CathodType cath, Bool_t warn) const
cf9a1555 280{
69417637 281/// Return mapping segmentation for given detElemId and cath
282
283 // Check detElemId & cath
cddd101e 284 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, false) ) {
69417637 285
286 if ( warn ) {
287 AliWarningStream()
cddd101e 288 << "Invalid detElemId " << detElemId << endl;
69417637 289 }
290 return 0;
291 }
292
cddd101e 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);
69417637 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}
cf9a1555 308
69417637 309//_____________________________________________________________________________
310const AliMpVSegmentation*
311AliMpSegmentation::GetMpSegmentationByElectronics(
312 Int_t detElemId, Int_t ecId, Bool_t warn) const
313{
314/// Return mapping segmentation for given detElemId and electronic card Id
315/// (motif position Id)
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}
f3ed9a44 338
339//_____________________________________________________________________________
340const AliMpSector*
341AliMpSegmentation::GetSector(const AliMpVSegmentation* kSegmentation,
342 Bool_t warn) const
343{
344/// Return sector for given mapping segmentation.
345/// If segmentation is not of sector type, zero is returned
346/// and an Error is issued if warn is set true (default).
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 }
7a170a5c 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
6e97fbb8 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*/
7a170a5c 375 // If sector segmentation
376 const AliMpSectorSegmentation* sseg
377 = dynamic_cast<const AliMpSectorSegmentation*>(kSegmentation);
378 if ( sseg ) {
379 return sseg->GetSector();
380 }
f3ed9a44 381
7a170a5c 382 // Should not get to this line
383 AliErrorStream() << "Segemntation type not identified." << endl;
384 return 0;
f3ed9a44 385}
386
387//_____________________________________________________________________________
388const AliMpSector*
389AliMpSegmentation::GetSector(Int_t detElemId, AliMp::CathodType cath,
390 Bool_t warn) const
391{
392/// Return sector for given detElemId and cath.
393/// If segmentation is not of sector type, zero is returned
394/// and an Error is issued if warn is set true (default).
395
396 return GetSector(GetMpSegmentation(detElemId, cath, warn), warn);
397}
398
399//_____________________________________________________________________________
400const AliMpSector*
401AliMpSegmentation::GetSectorByElectronics(Int_t detElemId, Int_t elCardID,
402 Bool_t warn) const
403{
404/// Return sector for given detElemId and elCardID.
405/// If segmentation is not of sector type, zero is returned
406/// and an Error is issued if warn is set true (default).
407
408 return GetSector(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);
409}
410
411//_____________________________________________________________________________
412const AliMpSlat*
413AliMpSegmentation::GetSlat(const AliMpVSegmentation* kSegmentation,
414 Bool_t warn) const
415{
416/// Return slat for given mapping segmentation.
417/// If segmentation is not of slat type, zero is returned
418/// and an Error is issued if warn is set true (default).
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
7a170a5c 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
6e97fbb8 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*/
7a170a5c 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;
f3ed9a44 458}
459
460//_____________________________________________________________________________
461const AliMpSlat*
462AliMpSegmentation::GetSlat(Int_t detElemId, AliMp::CathodType cath,
463 Bool_t warn) const
464{
465/// Return slat for given detElemId and cath.
466/// If segmentation is not of slat type, zero is returned
467/// and an Error is issued if warn is set true (default).
468
469 return GetSlat(GetMpSegmentation(detElemId, cath, warn), warn);
470}
471
472//_____________________________________________________________________________
473const AliMpSlat*
474AliMpSegmentation::GetSlatByElectronics(Int_t detElemId, Int_t elCardID,
475 Bool_t warn) const
476{
477/// Return slat for given detElemId and elCardID.
478/// If segmentation is not of slat type, zero is returned
479/// and an Error is issued if warn is set true (default).
480
481 return GetSlat(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);
482}
483
484//_____________________________________________________________________________
485const AliMpTrigger*
486AliMpSegmentation::GetTrigger(const AliMpVSegmentation* kSegmentation,
487 Bool_t warn) const
488{
489/// Return trigger for given mapping segmentation.
490/// If segmentation is not of trigger type, zero is returned
491/// and an Error is issued if warn is set true (default).
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
7a170a5c 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
6e97fbb8 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
7a170a5c 530 // Should not get to this line
531 AliErrorStream() << "Segemntation type not identified." << endl;
532 return 0;
f3ed9a44 533}
534
535//_____________________________________________________________________________
536const AliMpTrigger*
537AliMpSegmentation::GetTrigger(Int_t detElemId, AliMp::CathodType cath,
538 Bool_t warn) const
539{
540/// Return trigger for given detElemId and cath.
541/// If segmentation is not of trigger type, zero is returned
542/// and an Error is issued if warn is set true (default).
543
544 return GetTrigger(GetMpSegmentation(detElemId, cath, warn), warn);
545}
546
547//_____________________________________________________________________________
548const AliMpTrigger*
549AliMpSegmentation::GetTriggerByElectronics(Int_t detElemId, Int_t elCardID,
550 Bool_t warn) const
551{
552/// Return trigger for given detElemId and elCardID.
553/// If segmentation is not of trigger type, zero is returned
554/// and an Error is issued if warn is set true (default).
555
556 return GetTrigger(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);
557}