]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpSegmentation.cxx
New LinkDef (cmake)
[u/mrichter/AliRoot.git] / MUON / mapping / 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"
cf9a1555 37#include "AliMpSector.h"
38#include "AliMpSectorReader.h"
39#include "AliMpSectorSegmentation.h"
40#include "AliMpSlat.h"
cf9a1555 41#include "AliMpSlatSegmentation.h"
b802839b 42#include "AliMpSt345Reader.h"
cf9a1555 43#include "AliMpTrigger.h"
44#include "AliMpTriggerReader.h"
45#include "AliMpTriggerSegmentation.h"
cddd101e 46#include "AliMpCathodType.h"
dede1525 47#include "AliMpSlatMotifMap.h"
48
2c605e66 49
50#include "AliLog.h"
51
cf9a1555 52#include <Riostream.h>
cf9a1555 53#include <TMap.h>
b802839b 54#include <TObjString.h>
55#include <TSystem.h>
5f377a9a 56#include <TClass.h>
cf9a1555 57
630711ed 58#include <cassert>
59
13985652 60/// \cond CLASSIMP
69417637 61ClassImp(AliMpSegmentation)
13985652 62/// \endcond
cf9a1555 63
69417637 64AliMpSegmentation* AliMpSegmentation::fgInstance = 0;
65
66//
67// static methods
68//
69
70//______________________________________________________________________________
5f377a9a 71AliMpSegmentation* AliMpSegmentation::Instance(Bool_t warn)
69417637 72{
5f377a9a 73/// Return its instance
69417637 74
5f377a9a 75 if ( ! fgInstance && warn ) {
76 AliWarningClass("Segmentation has not been loaded");
77 }
69417637 78
79 return fgInstance;
80}
81
5f377a9a 82//______________________________________________________________________________
ab167304 83AliMpSegmentation* AliMpSegmentation::ReadData(const AliMpDataStreams& dataStreams,
84 Bool_t warn)
5f377a9a 85{
86/// Load the sementation from ASCII data files
87/// and return its instance
88
89 if ( fgInstance ) {
90 if ( warn )
91 AliWarningClass("Segmentation has been already loaded");
92 return fgInstance;
93 }
94
ab167304 95 if ( dataStreams.GetReadFromFiles() )
228fd720 96 AliInfoClass("Reading segmentation from ASCII files.");
5f377a9a 97
ab167304 98 fgInstance = new AliMpSegmentation(dataStreams);
5f377a9a 99 return fgInstance;
100}
101
69417637 102//
103// ctors, dtor
104//
0cfc27d7 105
cf9a1555 106//______________________________________________________________________________
ab167304 107AliMpSegmentation::AliMpSegmentation(const AliMpDataStreams& dataStreams)
b802839b 108: TObject(),
7d5d0cc5 109 fkDataStreams(dataStreams),
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();
69417637 125
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 {
134 if ( CreateMpSegmentation(it.CurrentDEId(), AliMp::GetCathodType(cath)) ) ++n;
f54f81ea 135 }
630711ed 136
137 if ( n == 2 && // should always be the case except when we play with the CreateMpSegmentation method...
138 AliMpDEManager::GetStationType(it.CurrentDEId()) != AliMp::kStationTrigger ) // only for tracker
139 {
140 // Fill el cards map for all detection elements
141 // of tracking chambers
142 FillElCardsMap(it.CurrentDEId());
143 }
144 }
cf9a1555 145}
146
cf9a1555 147//______________________________________________________________________________
630711ed 148AliMpSegmentation::AliMpSegmentation(TRootIOCtor* ioCtor)
69417637 149: TObject(),
7d5d0cc5 150 fkDataStreams(ioCtor),
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
cf9a1555 180//
69417637 181// private methods
cf9a1555 182//
183
184//______________________________________________________________________________
185AliMpVSegmentation*
cddd101e 186AliMpSegmentation::CreateMpSegmentation(Int_t detElemId, AliMp::CathodType cath)
cf9a1555 187{
188/// Create mapping segmentation for given detElemId and cath
189/// or return it if it was already built
190
191 // Check detElemId & cath
cddd101e 192 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, true) ) return 0;
cf9a1555 193
194 // If segmentation is already built, just return it
195 //
cddd101e 196 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
197 TString deSegName = detElement->GetSegName(cath);
198 TObject* object = fMpSegmentations.Get(deSegName);
cf9a1555 199 if ( object ) return (AliMpVSegmentation*)object;
200
0cfc27d7 201 AliDebugStream(3)
202 << "Creating segmentation for detElemId=" << detElemId
203 << " cath=" << cath << endl;
b802839b 204
cf9a1555 205 // Read mapping data and create segmentation
206 //
cddd101e 207 AliMp::StationType stationType = detElement->GetStationType();
208 AliMp::PlaneType planeType = detElement->GetPlaneType(cath);
209 TString deTypeName = detElement->GetSegType();
cf9a1555 210
211 AliMpVSegmentation* mpSegmentation = 0;
212
4e51cfd2 213 if ( stationType == AliMp::kStation12 ) {
214 AliMq::Station12Type station12Type = detElement->GetStation12Type();
7d5d0cc5 215 AliMpSectorReader reader(fkDataStreams, station12Type, planeType);
cf9a1555 216 AliMpSector* sector = reader.BuildSector();
7a170a5c 217 mpSegmentation = new AliMpFastSegmentation(new AliMpSectorSegmentation(sector, true));
cf9a1555 218 }
cddd101e 219 else if ( stationType == AliMp::kStation345 ) {
7d5d0cc5 220 AliMpSt345Reader reader(fkDataStreams,fSlatMotifMap);
f54f81ea 221 AliMpSlat* slat = reader.ReadSlat(deTypeName, planeType);
7a170a5c 222 mpSegmentation = new AliMpFastSegmentation(new AliMpSlatSegmentation(slat, true));
cf9a1555 223 }
cddd101e 224 else if ( stationType == AliMp::kStationTrigger ) {
7d5d0cc5 225 AliMpTriggerReader reader(fkDataStreams,fSlatMotifMap);
f54f81ea 226 AliMpTrigger* trigger = reader.ReadSlat(deTypeName, planeType);
69417637 227 mpSegmentation = new AliMpTriggerSegmentation(trigger, true);
cf9a1555 228 }
229 else
230 AliErrorStream() << "Unknown station type" << endl;
231
630711ed 232 if ( mpSegmentation ) fMpSegmentations.Add(deSegName, mpSegmentation);
f54f81ea 233
1a3b5b04 234// StdoutToAliDebug(3, fSlatMotifMap.Print(););
f54f81ea 235
cf9a1555 236 return mpSegmentation;
237}
b802839b 238
239//_____________________________________________________________________________
69417637 240AliMpExMap*
241AliMpSegmentation::FillElCardsMap(Int_t detElemId)
b802839b 242{
69417637 243/// Fill the map of electronic cards IDs to segmentations for
244/// given detElemId
490da820 245
69417637 246 AliDebugStream(2) << "detElemId=" << detElemId << endl;;
b802839b 247
630711ed 248 AliMpExMap* mde = new AliMpExMap;
69417637 249 mde->SetOwner(kFALSE);
250 fElCardsMap.Add(detElemId,mde);
251
252 const AliMpVSegmentation* seg[2];
253 TArrayI ecn[2];
254
cddd101e 255 for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++cathode )
b802839b 256 {
cddd101e 257 seg[cathode] = GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
69417637 258 seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
69417637 259 for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
260 {
261 mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
262 }
263 }
264
630711ed 265 assert( mde->GetSize() > 0 );
266
69417637 267 return mde;
630711ed 268
b802839b 269}
69417637 270
271//
272// public methods
273//
274
cf9a1555 275//______________________________________________________________________________
69417637 276const AliMpVSegmentation*
277AliMpSegmentation::GetMpSegmentation(
cddd101e 278 Int_t detElemId, AliMp::CathodType cath, Bool_t warn) const
cf9a1555 279{
69417637 280/// Return mapping segmentation for given detElemId and cath
281
282 // Check detElemId & cath
cddd101e 283 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, false) ) {
69417637 284
285 if ( warn ) {
286 AliWarningStream()
cddd101e 287 << "Invalid detElemId " << detElemId << endl;
69417637 288 }
289 return 0;
290 }
291
cddd101e 292 // If segmentation is already built, just return it
293 //
294 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
295 TString deSegName = detElement->GetSegName(cath);
296 TObject* object = fMpSegmentations.Get(deSegName);
69417637 297 if ( ! object ) {
298 // Should never happen
299 AliErrorStream()
300 << "Segmentation for detElemId/cathod "
301 << detElemId << ", " << cath << " not defined" << endl;
302 return 0;
303 }
304
305 return static_cast<AliMpVSegmentation*>(object);
306}
cf9a1555 307
69417637 308//_____________________________________________________________________________
309const AliMpVSegmentation*
310AliMpSegmentation::GetMpSegmentationByElectronics(
311 Int_t detElemId, Int_t ecId, Bool_t warn) const
312{
313/// Return mapping segmentation for given detElemId and electronic card Id
314/// (motif position Id)
315
316 AliMpExMap* m = static_cast<AliMpExMap*>(fElCardsMap.GetValue(detElemId));
317
318 if (!m) {
319 // Should never happen
320 AliErrorStream()
321 << "Cannot find the el cards map for detElemId " << detElemId << endl;
322 return 0;
323 }
324
325 TObject* object = m->GetValue(ecId);
326 if ( ! object ) {
327 if ( warn ) {
328 AliErrorStream()
329 << "Segmentation for electronic card "
330 << ecId << " not found" << endl;
331 }
332 return 0;
333 }
334
335 return static_cast<AliMpVSegmentation*>(object);
336}
f3ed9a44 337
338//_____________________________________________________________________________
339const AliMpSector*
340AliMpSegmentation::GetSector(const AliMpVSegmentation* kSegmentation,
341 Bool_t warn) const
342{
343/// Return sector for given mapping segmentation.
344/// If segmentation is not of sector type, zero is returned
345/// and an Error is issued if warn is set true (default).
346
347 if ( ! kSegmentation ) return 0;
348
349 if ( kSegmentation->StationType() != AliMp::kStation12 ) {
350 if ( warn ) {
351 AliErrorStream()
352 << "Segmentation is not of sector type" << endl;
353 }
354 return 0;
355 }
7a170a5c 356
357 // If fast segmentation
358 const AliMpFastSegmentation* fseg
359 = dynamic_cast<const AliMpFastSegmentation*>(kSegmentation);
360 if ( fseg ) {
361 return
362 static_cast<const AliMpSectorSegmentation*>(fseg->GetHelper())->GetSector();
363 }
364
365 // If sector segmentation
366 const AliMpSectorSegmentation* sseg
367 = dynamic_cast<const AliMpSectorSegmentation*>(kSegmentation);
368 if ( sseg ) {
369 return sseg->GetSector();
370 }
f3ed9a44 371
7a170a5c 372 // Should not get to this line
373 AliErrorStream() << "Segemntation type not identified." << endl;
374 return 0;
f3ed9a44 375}
376
377//_____________________________________________________________________________
378const AliMpSector*
379AliMpSegmentation::GetSector(Int_t detElemId, AliMp::CathodType cath,
380 Bool_t warn) const
381{
382/// Return sector for given detElemId and cath.
383/// If segmentation is not of sector type, zero is returned
384/// and an Error is issued if warn is set true (default).
385
386 return GetSector(GetMpSegmentation(detElemId, cath, warn), warn);
387}
388
389//_____________________________________________________________________________
390const AliMpSector*
391AliMpSegmentation::GetSectorByElectronics(Int_t detElemId, Int_t elCardID,
392 Bool_t warn) const
393{
394/// Return sector for given detElemId and elCardID.
395/// If segmentation is not of sector type, zero is returned
396/// and an Error is issued if warn is set true (default).
397
398 return GetSector(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);
399}
400
401//_____________________________________________________________________________
402const AliMpSlat*
403AliMpSegmentation::GetSlat(const AliMpVSegmentation* kSegmentation,
404 Bool_t warn) const
405{
406/// Return slat for given mapping segmentation.
407/// If segmentation is not of slat type, zero is returned
408/// and an Error is issued if warn is set true (default).
409
410 if ( ! kSegmentation ) return 0;
411
412 if ( kSegmentation->StationType() != AliMp::kStation345 ) {
413 if ( warn ) {
414 AliErrorStream()
415 << "Segmentation is not of slat type" << endl;
416 }
417 return 0;
418 }
419
7a170a5c 420 // If fast segmentation
421 const AliMpFastSegmentation* fseg
422 = dynamic_cast<const AliMpFastSegmentation*>(kSegmentation);
423 if ( fseg ) {
424 return
425 static_cast<const AliMpSlatSegmentation*>(fseg->GetHelper())->Slat();
426 }
427
428 // If slat segmentation
429 const AliMpSlatSegmentation* sseg
430 = dynamic_cast<const AliMpSlatSegmentation*>(kSegmentation);
431
432 if ( sseg ) {
433 return sseg->Slat();
434 }
435
436 // Should not get to this line
437 AliErrorStream() << "Segemntation type not identified." << endl;
438 return 0;
f3ed9a44 439}
440
441//_____________________________________________________________________________
442const AliMpSlat*
443AliMpSegmentation::GetSlat(Int_t detElemId, AliMp::CathodType cath,
444 Bool_t warn) const
445{
446/// Return slat for given detElemId and cath.
447/// If segmentation is not of slat type, zero is returned
448/// and an Error is issued if warn is set true (default).
449
450 return GetSlat(GetMpSegmentation(detElemId, cath, warn), warn);
451}
452
453//_____________________________________________________________________________
454const AliMpSlat*
455AliMpSegmentation::GetSlatByElectronics(Int_t detElemId, Int_t elCardID,
456 Bool_t warn) const
457{
458/// Return slat for given detElemId and elCardID.
459/// If segmentation is not of slat type, zero is returned
460/// and an Error is issued if warn is set true (default).
461
462 return GetSlat(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);
463}
464
465//_____________________________________________________________________________
466const AliMpTrigger*
467AliMpSegmentation::GetTrigger(const AliMpVSegmentation* kSegmentation,
468 Bool_t warn) const
469{
470/// Return trigger for given mapping segmentation.
471/// If segmentation is not of trigger type, zero is returned
472/// and an Error is issued if warn is set true (default).
473
474 if ( ! kSegmentation ) return 0;
475
476 if ( kSegmentation->StationType() != AliMp::kStationTrigger ) {
477 if ( warn ) {
478 AliErrorStream()
479 << "Segmentation is not of trigger type" << endl;
480 }
481 return 0;
482 }
483
7a170a5c 484 // If slat segmentation
485 const AliMpTriggerSegmentation* tseg
486 = dynamic_cast<const AliMpTriggerSegmentation*>(kSegmentation);
487 if ( tseg ) {
488 return tseg->Slat();
489 }
490
491 // If fast segmentation
492 const AliMpFastSegmentation* fseg
493 = dynamic_cast<const AliMpFastSegmentation*>(kSegmentation);
494
495 if ( fseg ) {
496 return
497 static_cast<const AliMpTriggerSegmentation*>(fseg->GetHelper())->Slat();
498 }
499
500 // Should not get to this line
501 AliErrorStream() << "Segemntation type not identified." << endl;
502 return 0;
f3ed9a44 503}
504
505//_____________________________________________________________________________
506const AliMpTrigger*
507AliMpSegmentation::GetTrigger(Int_t detElemId, AliMp::CathodType cath,
508 Bool_t warn) const
509{
510/// Return trigger for given detElemId and cath.
511/// If segmentation is not of trigger type, zero is returned
512/// and an Error is issued if warn is set true (default).
513
514 return GetTrigger(GetMpSegmentation(detElemId, cath, warn), warn);
515}
516
517//_____________________________________________________________________________
518const AliMpTrigger*
519AliMpSegmentation::GetTriggerByElectronics(Int_t detElemId, Int_t elCardID,
520 Bool_t warn) const
521{
522/// Return trigger for given detElemId and elCardID.
523/// If segmentation is not of trigger type, zero is returned
524/// and an Error is issued if warn is set true (default).
525
526 return GetTrigger(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);
527}