Using AliMpDEManager for detElemId -> chamberId
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometry.cxx
CommitLineData
75678bb3 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * SigmaEffect_thetadegrees *
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 purpeateose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16// $Id$
17//
f7006443 18// ----------------------------
75678bb3 19// Class AliMUONGeometry
20// ----------------------------
21// Manager class for geometry construction via geometry builders.
75678bb3 22// Author: Ivana Hrivnacova, IPN Orsay
23
75678bb3 24#include "AliMUONGeometry.h"
25#include "AliMUONGeometryTransformer.h"
26#include "AliMUONGeometryModule.h"
7ecf374b 27#include "AliMUONStringIntMap.h"
e5df8ea1 28#include "AliMUONGeometryStore.h"
7ecf374b 29
75678bb3 30#include "AliLog.h"
31
7ecf374b 32#include <TObjArray.h>
33#include <Riostream.h>
34#include <TSystem.h>
35
36#include <iostream>
75678bb3 37
a9aad96e 38/// \cond CLASSIMP
75678bb3 39ClassImp(AliMUONGeometry)
a9aad96e 40/// \endcond
75678bb3 41
42//______________________________________________________________________________
43AliMUONGeometry::AliMUONGeometry(Bool_t isOwner)
44 : TObject(),
45 fModules(0),
46 fTransformer(0)
47
48{
49/// Standard constructor
50
51 // Create array for geometry modules
52 fModules = new TObjArray();
53 fModules->SetOwner(isOwner);
54
55 // Geometry parametrisation
56 fTransformer = new AliMUONGeometryTransformer(false);
57}
58
59//______________________________________________________________________________
60AliMUONGeometry::AliMUONGeometry()
61 : TObject(),
62 fModules(0),
63 fTransformer(0)
64{
65/// Default constructor
66}
67
68//______________________________________________________________________________
75678bb3 69AliMUONGeometry::~AliMUONGeometry()
70{
71/// Destructor
72
73 delete fModules;
74 delete fTransformer;
75}
76
75678bb3 77//
78// private methods
79//
80
81//______________________________________________________________________________
82TString AliMUONGeometry::ComposePath(const TString& volName,
83 Int_t copyNo) const
84{
a9aad96e 85/// Compose path from given volName and copyNo
75678bb3 86
87 TString path(volName);
88 path += ".";
89 path += copyNo;
90
91 return path;
92}
93
94//______________________________________________________________________________
95void AliMUONGeometry::FillData3(const TString& sensVolumePath,
96 Int_t detElemId)
97{
a9aad96e 98/// Fill the mapping of the sensitive volume path to the detection element.
75678bb3 99
100 // Module Id
e5df8ea1 101 Int_t moduleId = AliMUONGeometryStore::GetModuleId(detElemId);
75678bb3 102
103 // Get module
104 AliMUONGeometryModule* module
105 = (AliMUONGeometryModule*)fModules->At(moduleId);
106
107 if ( !module ) {
108 AliWarningStream()
109 << "Geometry module for det element " << detElemId << " not defined."
110 << endl;
111 return;
112 }
113
114 // Get module sensitive volumes map
7ecf374b 115 AliMUONStringIntMap* svMap = module->GetSVMap();
75678bb3 116
117 // Map the sensitive volume to detection element
118 svMap->Add(sensVolumePath, detElemId);
119}
120
121//______________________________________________________________________________
122TString AliMUONGeometry::ReadData3(ifstream& in)
123{
a9aad96e 124/// Read SV maps from a file.
125/// Return true, if reading finished correctly.
75678bb3 126
127 TString key("SV");
128 while ( key == TString("SV") ) {
129
130 // Input data
131 TString volumePath;
132 Int_t detElemId;
133
134 in >> volumePath;
135 in >> detElemId;
136
137 //cout << "volumePath=" << volumePath << " "
138 // << "detElemId=" << detElemId
139 // << endl;
140
141 // Fill data
142 FillData3(volumePath, detElemId);
143
144 // Go to next line
145 in >> key;
146 }
147
148 return key;
149}
150
151//______________________________________________________________________________
152void AliMUONGeometry::WriteData3(ofstream& out) const
153{
a9aad96e 154/// Write association of sensitive volumes and detection elements
155/// from the sensitive volume map
75678bb3 156
157 for (Int_t i=0; i<fModules->GetEntriesFast(); i++) {
158 AliMUONGeometryModule* geometry
159 = (AliMUONGeometryModule*)fModules->At(i);
7ecf374b 160 AliMUONStringIntMap* svMap
75678bb3 161 = geometry->GetSVMap();
162
7ecf374b 163 svMap->Print("SV", out);
75678bb3 164 out << endl;
165 }
166}
167
168//
169// public functions
170//
171
172//_____________________________________________________________________________
173void AliMUONGeometry::AddModule(AliMUONGeometryModule* module)
174{
a9aad96e 175/// Add the geometry module to the array
75678bb3 176
177 fModules->Add(module);
178
179 if (module)
180 fTransformer->AddModuleTransformer(module->GetTransformer());
181}
182
183//______________________________________________________________________________
184Bool_t
185AliMUONGeometry::ReadSVMap(const TString& fileName)
186{
a9aad96e 187/// Read the sensitive volume maps from a file.
188/// Return true, if reading finished correctly.
75678bb3 189
190 // No reading
191 // if builder is not associated with any geometry module
192 if (fModules->GetEntriesFast() == 0) return false;
193
194 // File path
195 TString filePath = gSystem->Getenv("ALICE_ROOT");
196 filePath += "/MUON/data/";
197 filePath += fileName;
198
199 // Open input file
200 ifstream in(filePath, ios::in);
201 if (!in) {
202 cerr << filePath << endl;
203 AliFatal("File not found.");
204 return false;
205 }
206
207 TString key;
208 in >> key;
209 while ( !in.eof() ) {
210 if (key == TString("SV"))
211 key = ReadData3(in);
212 else {
213 AliFatal(Form("%s key not recognized", key.Data()));
214 return false;
215 }
216 }
217
218 return true;
219}
220
221//______________________________________________________________________________
222Bool_t
223AliMUONGeometry::WriteSVMap(const TString& fileName) const
224{
a9aad96e 225/// Write sensitive volume map into a file.
226/// Return true, if writing finished correctly.
75678bb3 227
228 // No writing
229 // if builder is not associated with any geometry module
230 if (fModules->GetEntriesFast() == 0) return false;
231
232 // File path
233 TString filePath = gSystem->Getenv("ALICE_ROOT");
234 filePath += "/MUON/data/";
235 filePath += fileName;
236
237 // Open input file
238 ofstream out(filePath, ios::out);
239 if (!out) {
240 cerr << filePath << endl;
241 AliError("File not found.");
242 return false;
243 }
244#if !defined (__DECCXX)
245 out.setf(std::ios::fixed);
246#endif
247 WriteData3(out);
248
249 return true;
250}
251
252//_____________________________________________________________________________
253const AliMUONGeometryModule*
254AliMUONGeometry::GetModule(Int_t index, Bool_t warn) const
255{
256/// Return the geometry module specified by index
257
258 if (index < 0 || index >= fModules->GetEntriesFast()) {
259 if (warn) {
260 AliWarningStream()
261 << "Index: " << index << " outside limits" << std::endl;
262 }
263 return 0;
264 }
265
266 return (const AliMUONGeometryModule*) fModules->At(index);
267}
268
269//_____________________________________________________________________________
270const AliMUONGeometryModule*
271AliMUONGeometry::GetModuleByDEId(Int_t detElemId, Bool_t warn) const
272{
a9aad96e 273/// Return the geometry module specified by detElemId
75678bb3 274
275 // Get module index
e5df8ea1 276 Int_t index = AliMUONGeometryStore::GetModuleId(detElemId);
75678bb3 277
278 return GetModule(index, warn);
279}