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