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