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