]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpSegmentation.cxx
Raw2SDigits() restored and improved.
[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(),
ab167304 108 fDataStreams(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(),
ab167304 149 fDataStreams(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
cddd101e 212 if ( stationType == AliMp::kStation1 || stationType == AliMp::kStation2 ) {
ab167304 213 AliMpSectorReader reader(fDataStreams, stationType, planeType);
cf9a1555 214 AliMpSector* sector = reader.BuildSector();
69417637 215 mpSegmentation = new AliMpSectorSegmentation(sector, true);
cf9a1555 216 }
cddd101e 217 else if ( stationType == AliMp::kStation345 ) {
183279c1 218 AliMpSt345Reader reader(fDataStreams,fSlatMotifMap);
f54f81ea 219 AliMpSlat* slat = reader.ReadSlat(deTypeName, planeType);
69417637 220 mpSegmentation = new AliMpSlatSegmentation(slat, true);
cf9a1555 221 }
cddd101e 222 else if ( stationType == AliMp::kStationTrigger ) {
183279c1 223 AliMpTriggerReader reader(fDataStreams,fSlatMotifMap);
f54f81ea 224 AliMpTrigger* trigger = reader.ReadSlat(deTypeName, planeType);
69417637 225 mpSegmentation = new AliMpTriggerSegmentation(trigger, true);
cf9a1555 226 }
227 else
228 AliErrorStream() << "Unknown station type" << endl;
229
630711ed 230 if ( mpSegmentation ) fMpSegmentations.Add(deSegName, mpSegmentation);
f54f81ea 231
1a3b5b04 232// StdoutToAliDebug(3, fSlatMotifMap.Print(););
f54f81ea 233
cf9a1555 234 return mpSegmentation;
235}
b802839b 236
237//_____________________________________________________________________________
69417637 238AliMpExMap*
239AliMpSegmentation::FillElCardsMap(Int_t detElemId)
b802839b 240{
69417637 241/// Fill the map of electronic cards IDs to segmentations for
242/// given detElemId
490da820 243
69417637 244 AliDebugStream(2) << "detElemId=" << detElemId << endl;;
b802839b 245
630711ed 246 AliMpExMap* mde = new AliMpExMap;
69417637 247 mde->SetOwner(kFALSE);
248 fElCardsMap.Add(detElemId,mde);
249
250 const AliMpVSegmentation* seg[2];
251 TArrayI ecn[2];
252
cddd101e 253 for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++cathode )
b802839b 254 {
cddd101e 255 seg[cathode] = GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
69417637 256 seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
69417637 257 for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
258 {
259 mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
260 }
261 }
262
630711ed 263 assert( mde->GetSize() > 0 );
264
69417637 265 return mde;
630711ed 266
b802839b 267}
69417637 268
269//
270// public methods
271//
272
cf9a1555 273//______________________________________________________________________________
69417637 274const AliMpVSegmentation*
275AliMpSegmentation::GetMpSegmentation(
cddd101e 276 Int_t detElemId, AliMp::CathodType cath, Bool_t warn) const
cf9a1555 277{
69417637 278/// Return mapping segmentation for given detElemId and cath
279
280 // Check detElemId & cath
cddd101e 281 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, false) ) {
69417637 282
283 if ( warn ) {
284 AliWarningStream()
cddd101e 285 << "Invalid detElemId " << detElemId << endl;
69417637 286 }
287 return 0;
288 }
289
cddd101e 290 // If segmentation is already built, just return it
291 //
292 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
293 TString deSegName = detElement->GetSegName(cath);
294 TObject* object = fMpSegmentations.Get(deSegName);
69417637 295 if ( ! object ) {
296 // Should never happen
297 AliErrorStream()
298 << "Segmentation for detElemId/cathod "
299 << detElemId << ", " << cath << " not defined" << endl;
300 return 0;
301 }
302
303 return static_cast<AliMpVSegmentation*>(object);
304}
cf9a1555 305
69417637 306//_____________________________________________________________________________
307const AliMpVSegmentation*
308AliMpSegmentation::GetMpSegmentationByElectronics(
309 Int_t detElemId, Int_t ecId, Bool_t warn) const
310{
311/// Return mapping segmentation for given detElemId and electronic card Id
312/// (motif position Id)
313
314 AliMpExMap* m = static_cast<AliMpExMap*>(fElCardsMap.GetValue(detElemId));
315
316 if (!m) {
317 // Should never happen
318 AliErrorStream()
319 << "Cannot find the el cards map for detElemId " << detElemId << endl;
320 return 0;
321 }
322
323 TObject* object = m->GetValue(ecId);
324 if ( ! object ) {
325 if ( warn ) {
326 AliErrorStream()
327 << "Segmentation for electronic card "
328 << ecId << " not found" << endl;
329 }
330 return 0;
331 }
332
333 return static_cast<AliMpVSegmentation*>(object);
334}
f3ed9a44 335
336//_____________________________________________________________________________
337const AliMpSector*
338AliMpSegmentation::GetSector(const AliMpVSegmentation* kSegmentation,
339 Bool_t warn) const
340{
341/// Return sector for given mapping segmentation.
342/// If segmentation is not of sector type, zero is returned
343/// and an Error is issued if warn is set true (default).
344
345 if ( ! kSegmentation ) return 0;
346
347 if ( kSegmentation->StationType() != AliMp::kStation12 ) {
348 if ( warn ) {
349 AliErrorStream()
350 << "Segmentation is not of sector type" << endl;
351 }
352 return 0;
353 }
354
355 return
356 static_cast<const AliMpSectorSegmentation*>(kSegmentation)->GetSector();
357}
358
359//_____________________________________________________________________________
360const AliMpSector*
361AliMpSegmentation::GetSector(Int_t detElemId, AliMp::CathodType cath,
362 Bool_t warn) const
363{
364/// Return sector for given detElemId and cath.
365/// If segmentation is not of sector type, zero is returned
366/// and an Error is issued if warn is set true (default).
367
368 return GetSector(GetMpSegmentation(detElemId, cath, warn), warn);
369}
370
371//_____________________________________________________________________________
372const AliMpSector*
373AliMpSegmentation::GetSectorByElectronics(Int_t detElemId, Int_t elCardID,
374 Bool_t warn) const
375{
376/// Return sector for given detElemId and elCardID.
377/// If segmentation is not of sector type, zero is returned
378/// and an Error is issued if warn is set true (default).
379
380 return GetSector(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);
381}
382
383//_____________________________________________________________________________
384const AliMpSlat*
385AliMpSegmentation::GetSlat(const AliMpVSegmentation* kSegmentation,
386 Bool_t warn) const
387{
388/// Return slat for given mapping segmentation.
389/// If segmentation is not of slat type, zero is returned
390/// and an Error is issued if warn is set true (default).
391
392 if ( ! kSegmentation ) return 0;
393
394 if ( kSegmentation->StationType() != AliMp::kStation345 ) {
395 if ( warn ) {
396 AliErrorStream()
397 << "Segmentation is not of slat type" << endl;
398 }
399 return 0;
400 }
401
402 return
403 static_cast<const AliMpSlatSegmentation*>(kSegmentation)->Slat();
404}
405
406//_____________________________________________________________________________
407const AliMpSlat*
408AliMpSegmentation::GetSlat(Int_t detElemId, AliMp::CathodType cath,
409 Bool_t warn) const
410{
411/// Return slat for given detElemId and cath.
412/// If segmentation is not of slat type, zero is returned
413/// and an Error is issued if warn is set true (default).
414
415 return GetSlat(GetMpSegmentation(detElemId, cath, warn), warn);
416}
417
418//_____________________________________________________________________________
419const AliMpSlat*
420AliMpSegmentation::GetSlatByElectronics(Int_t detElemId, Int_t elCardID,
421 Bool_t warn) const
422{
423/// Return slat for given detElemId and elCardID.
424/// If segmentation is not of slat type, zero is returned
425/// and an Error is issued if warn is set true (default).
426
427 return GetSlat(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);
428}
429
430//_____________________________________________________________________________
431const AliMpTrigger*
432AliMpSegmentation::GetTrigger(const AliMpVSegmentation* kSegmentation,
433 Bool_t warn) const
434{
435/// Return trigger for given mapping segmentation.
436/// If segmentation is not of trigger type, zero is returned
437/// and an Error is issued if warn is set true (default).
438
439 if ( ! kSegmentation ) return 0;
440
441 if ( kSegmentation->StationType() != AliMp::kStationTrigger ) {
442 if ( warn ) {
443 AliErrorStream()
444 << "Segmentation is not of trigger type" << endl;
445 }
446 return 0;
447 }
448
449 return
450 static_cast<const AliMpTriggerSegmentation*>(kSegmentation)->Slat();
451}
452
453//_____________________________________________________________________________
454const AliMpTrigger*
455AliMpSegmentation::GetTrigger(Int_t detElemId, AliMp::CathodType cath,
456 Bool_t warn) const
457{
458/// Return trigger for given detElemId and cath.
459/// If segmentation is not of trigger type, zero is returned
460/// and an Error is issued if warn is set true (default).
461
462 return GetTrigger(GetMpSegmentation(detElemId, cath, warn), warn);
463}
464
465//_____________________________________________________________________________
466const AliMpTrigger*
467AliMpSegmentation::GetTriggerByElectronics(Int_t detElemId, Int_t elCardID,
468 Bool_t warn) const
469{
470/// Return trigger for given detElemId and elCardID.
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 return GetTrigger(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);
475}