]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpSegmentation.cxx
Corrected GetNeighbours() (Laurent)
[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
490da820 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
cf9a1555 26
69417637 27#include "AliMpSegmentation.h"
b802839b 28
cddd101e 29#include "AliMpDetElement.h"
cf9a1555 30#include "AliMpDEManager.h"
69417637 31#include "AliMpDEIterator.h"
b802839b 32#include "AliMpExMap.h"
cf9a1555 33#include "AliMpSector.h"
34#include "AliMpSectorReader.h"
35#include "AliMpSectorSegmentation.h"
36#include "AliMpSlat.h"
cf9a1555 37#include "AliMpSlatSegmentation.h"
b802839b 38#include "AliMpSt345Reader.h"
cf9a1555 39#include "AliMpTrigger.h"
40#include "AliMpTriggerReader.h"
41#include "AliMpTriggerSegmentation.h"
cddd101e 42#include "AliMpCathodType.h"
2c605e66 43
44#include "AliLog.h"
45
cf9a1555 46#include <Riostream.h>
cf9a1555 47#include <TMap.h>
b802839b 48#include <TObjString.h>
49#include <TSystem.h>
cf9a1555 50
13985652 51/// \cond CLASSIMP
69417637 52ClassImp(AliMpSegmentation)
13985652 53/// \endcond
cf9a1555 54
69417637 55AliMpSegmentation* AliMpSegmentation::fgInstance = 0;
56
57//
58// static methods
59//
60
61//______________________________________________________________________________
62AliMpSegmentation* AliMpSegmentation::Instance()
63{
64/// Create the sementation if it does not yet exist
65/// and return its instance
66
67 if ( ! fgInstance )
68 fgInstance = new AliMpSegmentation();
69
70 return fgInstance;
71}
72
73//
74// ctors, dtor
75//
0cfc27d7 76
cf9a1555 77//______________________________________________________________________________
69417637 78AliMpSegmentation::AliMpSegmentation()
b802839b 79: TObject(),
69417637 80 fMpSegmentations(true),
f54f81ea 81 fElCardsMap(true),
82 fSlatMotifMap()
cf9a1555 83{
69417637 84/// Standard constructor
85
86 AliDebug(1,"");
87 fElCardsMap.SetOwner(true);
88
89 // Create mapping segmentations for all detection elements
cddd101e 90 for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; cath ++ ) {
69417637 91 AliMpDEIterator it;
cddd101e 92 for ( it.First(); ! it.IsDone(); it.Next() ) {
93 CreateMpSegmentation(it.CurrentDEId(), AliMp::GetCathodType(cath));
69417637 94 }
95 }
96
97 // Fill el cards map for all detection elements
98 // of tracking chambers
99 AliMpDEIterator it;
cddd101e 100 for ( it.First(); ! it.IsDone(); it.Next() ) {
101 if ( AliMpDEManager::GetStationType(it.CurrentDEId()) != AliMp::kStationTrigger ) {
102 FillElCardsMap(it.CurrentDEId());
f54f81ea 103 }
69417637 104 }
cf9a1555 105}
106
cf9a1555 107//______________________________________________________________________________
69417637 108AliMpSegmentation::AliMpSegmentation(TRootIOCtor* /*ioCtor*/)
109: TObject(),
110 fMpSegmentations(),
f54f81ea 111 fElCardsMap(),
112 fSlatMotifMap()
69417637 113{
114/// Constructor for IO
115
cddd101e 116 AliDebug(1,"");
117
69417637 118 fgInstance = this;
119}
cf9a1555 120
69417637 121//______________________________________________________________________________
122AliMpSegmentation::~AliMpSegmentation()
cf9a1555 123{
124/// Destructor
125
b802839b 126 AliDebug(1,"");
490da820 127
69417637 128 // Segmentations are deleted with fMpSegmentations
129 // El cards arrays are deleted with fElCardsMap
490da820 130
69417637 131 fgInstance = 0;
490da820 132}
133
cf9a1555 134//
69417637 135// private methods
cf9a1555 136//
137
138//______________________________________________________________________________
139AliMpVSegmentation*
cddd101e 140AliMpSegmentation::CreateMpSegmentation(Int_t detElemId, AliMp::CathodType cath)
cf9a1555 141{
142/// Create mapping segmentation for given detElemId and cath
143/// or return it if it was already built
144
145 // Check detElemId & cath
cddd101e 146 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, true) ) return 0;
cf9a1555 147
148 // If segmentation is already built, just return it
149 //
cddd101e 150 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
151 TString deSegName = detElement->GetSegName(cath);
152 TObject* object = fMpSegmentations.Get(deSegName);
cf9a1555 153 if ( object ) return (AliMpVSegmentation*)object;
154
0cfc27d7 155 AliDebugStream(3)
156 << "Creating segmentation for detElemId=" << detElemId
157 << " cath=" << cath << endl;
b802839b 158
cf9a1555 159 // Read mapping data and create segmentation
160 //
cddd101e 161 AliMp::StationType stationType = detElement->GetStationType();
162 AliMp::PlaneType planeType = detElement->GetPlaneType(cath);
163 TString deTypeName = detElement->GetSegType();
cf9a1555 164
165 AliMpVSegmentation* mpSegmentation = 0;
166
cddd101e 167 if ( stationType == AliMp::kStation1 || stationType == AliMp::kStation2 ) {
cf9a1555 168 AliMpSectorReader reader(stationType, planeType);
169 AliMpSector* sector = reader.BuildSector();
69417637 170 mpSegmentation = new AliMpSectorSegmentation(sector, true);
cf9a1555 171 }
cddd101e 172 else if ( stationType == AliMp::kStation345 ) {
f54f81ea 173 AliMpSt345Reader reader(fSlatMotifMap);
174 AliMpSlat* slat = reader.ReadSlat(deTypeName, planeType);
69417637 175 mpSegmentation = new AliMpSlatSegmentation(slat, true);
cf9a1555 176 }
cddd101e 177 else if ( stationType == AliMp::kStationTrigger ) {
f54f81ea 178 AliMpTriggerReader reader(fSlatMotifMap);
179 AliMpTrigger* trigger = reader.ReadSlat(deTypeName, planeType);
69417637 180 mpSegmentation = new AliMpTriggerSegmentation(trigger, true);
cf9a1555 181 }
182 else
183 AliErrorStream() << "Unknown station type" << endl;
184
cddd101e 185 fMpSegmentations.Add(deSegName, mpSegmentation);
f54f81ea 186
cddd101e 187 StdoutToAliDebug(3, fSlatMotifMap.Print(););
f54f81ea 188
cf9a1555 189 return mpSegmentation;
190}
b802839b 191
192//_____________________________________________________________________________
69417637 193AliMpExMap*
194AliMpSegmentation::FillElCardsMap(Int_t detElemId)
b802839b 195{
69417637 196/// Fill the map of electronic cards IDs to segmentations for
197/// given detElemId
490da820 198
69417637 199 AliDebugStream(2) << "detElemId=" << detElemId << endl;;
b802839b 200
69417637 201 AliMpExMap* mde = new AliMpExMap(true);
202 mde->SetOwner(kFALSE);
203 fElCardsMap.Add(detElemId,mde);
204
205 const AliMpVSegmentation* seg[2];
206 TArrayI ecn[2];
207
208 // Do it in 2 steps to be able to set the AliMpExMap size once for all,
209 // to avoid annoying warning message in case of dynamical resizing.
210 // (not critical).
cddd101e 211 for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++cathode )
b802839b 212 {
cddd101e 213 seg[cathode] = GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
69417637 214 seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
b802839b 215 }
216
69417637 217 mde->SetSize(ecn[0].GetSize()+ecn[1].GetSize());
218
cddd101e 219 for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++ cathode )
69417637 220 {
221 for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
222 {
223 mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
224 }
225 }
226
227 return mde;
b802839b 228}
69417637 229
230//
231// public methods
232//
233
cf9a1555 234//______________________________________________________________________________
69417637 235const AliMpVSegmentation*
236AliMpSegmentation::GetMpSegmentation(
cddd101e 237 Int_t detElemId, AliMp::CathodType cath, Bool_t warn) const
cf9a1555 238{
69417637 239/// Return mapping segmentation for given detElemId and cath
240
241 // Check detElemId & cath
cddd101e 242 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, false) ) {
69417637 243
244 if ( warn ) {
245 AliWarningStream()
cddd101e 246 << "Invalid detElemId " << detElemId << endl;
69417637 247 }
248 return 0;
249 }
250
cddd101e 251 // If segmentation is already built, just return it
252 //
253 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
254 TString deSegName = detElement->GetSegName(cath);
255 TObject* object = fMpSegmentations.Get(deSegName);
69417637 256 if ( ! object ) {
257 // Should never happen
258 AliErrorStream()
259 << "Segmentation for detElemId/cathod "
260 << detElemId << ", " << cath << " not defined" << endl;
261 return 0;
262 }
263
264 return static_cast<AliMpVSegmentation*>(object);
265}
cf9a1555 266
69417637 267//_____________________________________________________________________________
268const AliMpVSegmentation*
269AliMpSegmentation::GetMpSegmentationByElectronics(
270 Int_t detElemId, Int_t ecId, Bool_t warn) const
271{
272/// Return mapping segmentation for given detElemId and electronic card Id
273/// (motif position Id)
274
275 AliMpExMap* m = static_cast<AliMpExMap*>(fElCardsMap.GetValue(detElemId));
276
277 if (!m) {
278 // Should never happen
279 AliErrorStream()
280 << "Cannot find the el cards map for detElemId " << detElemId << endl;
281 return 0;
282 }
283
284 TObject* object = m->GetValue(ecId);
285 if ( ! object ) {
286 if ( warn ) {
287 AliErrorStream()
288 << "Segmentation for electronic card "
289 << ecId << " not found" << endl;
290 }
291 return 0;
292 }
293
294 return static_cast<AliMpVSegmentation*>(object);
295}