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