Removing unused enum member to avoid warnings with gcc 3.2.3
[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
38ClassImp(AliMUONGeometry)
39
40//______________________________________________________________________________
41AliMUONGeometry::AliMUONGeometry(Bool_t isOwner)
42 : TObject(),
43 fModules(0),
44 fTransformer(0)
45
46{
47/// Standard constructor
48
49 // Create array for geometry modules
50 fModules = new TObjArray();
51 fModules->SetOwner(isOwner);
52
53 // Geometry parametrisation
54 fTransformer = new AliMUONGeometryTransformer(false);
55}
56
57//______________________________________________________________________________
58AliMUONGeometry::AliMUONGeometry()
59 : TObject(),
60 fModules(0),
61 fTransformer(0)
62{
63/// Default constructor
64}
65
66//______________________________________________________________________________
67AliMUONGeometry::AliMUONGeometry(const AliMUONGeometry& right)
68 : TObject(right)
69{
70/// Copy constructor (not implemented)
71
72 AliFatal("Copy constructor not provided.");
73}
74
75//______________________________________________________________________________
76AliMUONGeometry::~AliMUONGeometry()
77{
78/// Destructor
79
80 delete fModules;
81 delete fTransformer;
82}
83
84//______________________________________________________________________________
85AliMUONGeometry&
86AliMUONGeometry::operator=(const AliMUONGeometry& right)
87{
88/// Assignement operator (not implemented)
89
90 // check assignement to self
91 if (this == &right) return *this;
92
93 AliFatal("Assignement operator not provided.");
94
95 return *this;
96}
97
98//
99// private methods
100//
101
102//______________________________________________________________________________
103TString AliMUONGeometry::ComposePath(const TString& volName,
104 Int_t copyNo) const
105{
106// Compose path from given volName and copyNo
107// ---
108
109 TString path(volName);
110 path += ".";
111 path += copyNo;
112
113 return path;
114}
115
116//______________________________________________________________________________
117void AliMUONGeometry::FillData3(const TString& sensVolumePath,
118 Int_t detElemId)
119{
120// Fill the mapping of the sensitive volume path to the detection element.
121// ---
122
123 // Module Id
e5df8ea1 124 Int_t moduleId = AliMUONGeometryStore::GetModuleId(detElemId);
75678bb3 125
126 // Get module
127 AliMUONGeometryModule* module
128 = (AliMUONGeometryModule*)fModules->At(moduleId);
129
130 if ( !module ) {
131 AliWarningStream()
132 << "Geometry module for det element " << detElemId << " not defined."
133 << endl;
134 return;
135 }
136
137 // Get module sensitive volumes map
7ecf374b 138 AliMUONStringIntMap* svMap = module->GetSVMap();
75678bb3 139
140 // Map the sensitive volume to detection element
141 svMap->Add(sensVolumePath, detElemId);
142}
143
144//______________________________________________________________________________
145TString AliMUONGeometry::ReadData3(ifstream& in)
146{
147// Reads SV maps from a file
148// Returns true, if reading finished correctly.
149// ---
150
151 TString key("SV");
152 while ( key == TString("SV") ) {
153
154 // Input data
155 TString volumePath;
156 Int_t detElemId;
157
158 in >> volumePath;
159 in >> detElemId;
160
161 //cout << "volumePath=" << volumePath << " "
162 // << "detElemId=" << detElemId
163 // << endl;
164
165 // Fill data
166 FillData3(volumePath, detElemId);
167
168 // Go to next line
169 in >> key;
170 }
171
172 return key;
173}
174
175//______________________________________________________________________________
176void AliMUONGeometry::WriteData3(ofstream& out) const
177{
178// Writes association of sensitive volumes and detection elements
179// from the sensitive volume map
180// ---
181
182 for (Int_t i=0; i<fModules->GetEntriesFast(); i++) {
183 AliMUONGeometryModule* geometry
184 = (AliMUONGeometryModule*)fModules->At(i);
7ecf374b 185 AliMUONStringIntMap* svMap
75678bb3 186 = geometry->GetSVMap();
187
7ecf374b 188 svMap->Print("SV", out);
75678bb3 189 out << endl;
190 }
191}
192
193//
194// public functions
195//
196
197//_____________________________________________________________________________
198void AliMUONGeometry::AddModule(AliMUONGeometryModule* module)
199{
200/// Add the geometrymodule to the array
201
202 fModules->Add(module);
203
204 if (module)
205 fTransformer->AddModuleTransformer(module->GetTransformer());
206}
207
208//______________________________________________________________________________
209Bool_t
210AliMUONGeometry::ReadSVMap(const TString& fileName)
211{
212// Reads the sensitive volume maps from a file
213// Returns true, if reading finished correctly.
214// ---
215
216 // No reading
217 // if builder is not associated with any geometry module
218 if (fModules->GetEntriesFast() == 0) return false;
219
220 // File path
221 TString filePath = gSystem->Getenv("ALICE_ROOT");
222 filePath += "/MUON/data/";
223 filePath += fileName;
224
225 // Open input file
226 ifstream in(filePath, ios::in);
227 if (!in) {
228 cerr << filePath << endl;
229 AliFatal("File not found.");
230 return false;
231 }
232
233 TString key;
234 in >> key;
235 while ( !in.eof() ) {
236 if (key == TString("SV"))
237 key = ReadData3(in);
238 else {
239 AliFatal(Form("%s key not recognized", key.Data()));
240 return false;
241 }
242 }
243
244 return true;
245}
246
247//______________________________________________________________________________
248Bool_t
249AliMUONGeometry::WriteSVMap(const TString& fileName) const
250{
251// Writes sensitive volume map into a file
252// Returns true, if writing finished correctly.
253// ---
254
255 // No writing
256 // if builder is not associated with any geometry module
257 if (fModules->GetEntriesFast() == 0) return false;
258
259 // File path
260 TString filePath = gSystem->Getenv("ALICE_ROOT");
261 filePath += "/MUON/data/";
262 filePath += fileName;
263
264 // Open input file
265 ofstream out(filePath, ios::out);
266 if (!out) {
267 cerr << filePath << endl;
268 AliError("File not found.");
269 return false;
270 }
271#if !defined (__DECCXX)
272 out.setf(std::ios::fixed);
273#endif
274 WriteData3(out);
275
276 return true;
277}
278
279//_____________________________________________________________________________
280const AliMUONGeometryModule*
281AliMUONGeometry::GetModule(Int_t index, Bool_t warn) const
282{
283/// Return the geometry module specified by index
284
285 if (index < 0 || index >= fModules->GetEntriesFast()) {
286 if (warn) {
287 AliWarningStream()
288 << "Index: " << index << " outside limits" << std::endl;
289 }
290 return 0;
291 }
292
293 return (const AliMUONGeometryModule*) fModules->At(index);
294}
295
296//_____________________________________________________________________________
297const AliMUONGeometryModule*
298AliMUONGeometry::GetModuleByDEId(Int_t detElemId, Bool_t warn) const
299{
300/// Return the geometry module specified by index
301
302 // Get module index
e5df8ea1 303 Int_t index = AliMUONGeometryStore::GetModuleId(detElemId);
75678bb3 304
305 return GetModule(index, warn);
306}