New class - container of AliMUONGeometryModule objects;
[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//
18// Class AliMUONGeometry
19// ----------------------------
20// Manager class for geometry construction via geometry builders.
21//
22// Author: Ivana Hrivnacova, IPN Orsay
23
24#include <iostream>
25
26#include <TObjArray.h>
27#include <Riostream.h>
28#include <TSystem.h>
29
30#include "AliMUONGeometry.h"
31#include "AliMUONGeometryTransformer.h"
32#include "AliMUONGeometryModule.h"
33#include "AliMUONGeometrySVMap.h"
34#include "AliMUONGeometryDEIndexing.h"
35#include "AliLog.h"
36
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
124 Int_t moduleId
125 = AliMUONGeometryDEIndexing::GetModuleId(detElemId);
126
127 // Get module
128 AliMUONGeometryModule* module
129 = (AliMUONGeometryModule*)fModules->At(moduleId);
130
131 if ( !module ) {
132 AliWarningStream()
133 << "Geometry module for det element " << detElemId << " not defined."
134 << endl;
135 return;
136 }
137
138 // Get module sensitive volumes map
139 AliMUONGeometrySVMap* svMap = module->GetSVMap();
140
141 // Map the sensitive volume to detection element
142 svMap->Add(sensVolumePath, detElemId);
143}
144
145//______________________________________________________________________________
146TString AliMUONGeometry::ReadData3(ifstream& in)
147{
148// Reads SV maps from a file
149// Returns true, if reading finished correctly.
150// ---
151
152 TString key("SV");
153 while ( key == TString("SV") ) {
154
155 // Input data
156 TString volumePath;
157 Int_t detElemId;
158
159 in >> volumePath;
160 in >> detElemId;
161
162 //cout << "volumePath=" << volumePath << " "
163 // << "detElemId=" << detElemId
164 // << endl;
165
166 // Fill data
167 FillData3(volumePath, detElemId);
168
169 // Go to next line
170 in >> key;
171 }
172
173 return key;
174}
175
176//______________________________________________________________________________
177void AliMUONGeometry::WriteData3(ofstream& out) const
178{
179// Writes association of sensitive volumes and detection elements
180// from the sensitive volume map
181// ---
182
183 for (Int_t i=0; i<fModules->GetEntriesFast(); i++) {
184 AliMUONGeometryModule* geometry
185 = (AliMUONGeometryModule*)fModules->At(i);
186 AliMUONGeometrySVMap* svMap
187 = geometry->GetSVMap();
188
189 svMap->WriteMap(out);
190 out << endl;
191 }
192}
193
194//
195// public functions
196//
197
198//_____________________________________________________________________________
199void AliMUONGeometry::AddModule(AliMUONGeometryModule* module)
200{
201/// Add the geometrymodule to the array
202
203 fModules->Add(module);
204
205 if (module)
206 fTransformer->AddModuleTransformer(module->GetTransformer());
207}
208
209//______________________________________________________________________________
210Bool_t
211AliMUONGeometry::ReadSVMap(const TString& fileName)
212{
213// Reads the sensitive volume maps from a file
214// Returns true, if reading finished correctly.
215// ---
216
217 // No reading
218 // if builder is not associated with any geometry module
219 if (fModules->GetEntriesFast() == 0) return false;
220
221 // File path
222 TString filePath = gSystem->Getenv("ALICE_ROOT");
223 filePath += "/MUON/data/";
224 filePath += fileName;
225
226 // Open input file
227 ifstream in(filePath, ios::in);
228 if (!in) {
229 cerr << filePath << endl;
230 AliFatal("File not found.");
231 return false;
232 }
233
234 TString key;
235 in >> key;
236 while ( !in.eof() ) {
237 if (key == TString("SV"))
238 key = ReadData3(in);
239 else {
240 AliFatal(Form("%s key not recognized", key.Data()));
241 return false;
242 }
243 }
244
245 return true;
246}
247
248//______________________________________________________________________________
249Bool_t
250AliMUONGeometry::WriteSVMap(const TString& fileName) const
251{
252// Writes sensitive volume map into a file
253// Returns true, if writing finished correctly.
254// ---
255
256 // No writing
257 // if builder is not associated with any geometry module
258 if (fModules->GetEntriesFast() == 0) return false;
259
260 // File path
261 TString filePath = gSystem->Getenv("ALICE_ROOT");
262 filePath += "/MUON/data/";
263 filePath += fileName;
264
265 // Open input file
266 ofstream out(filePath, ios::out);
267 if (!out) {
268 cerr << filePath << endl;
269 AliError("File not found.");
270 return false;
271 }
272#if !defined (__DECCXX)
273 out.setf(std::ios::fixed);
274#endif
275 WriteData3(out);
276
277 return true;
278}
279
280//_____________________________________________________________________________
281const AliMUONGeometryModule*
282AliMUONGeometry::GetModule(Int_t index, Bool_t warn) const
283{
284/// Return the geometry module specified by index
285
286 if (index < 0 || index >= fModules->GetEntriesFast()) {
287 if (warn) {
288 AliWarningStream()
289 << "Index: " << index << " outside limits" << std::endl;
290 }
291 return 0;
292 }
293
294 return (const AliMUONGeometryModule*) fModules->At(index);
295}
296
297//_____________________________________________________________________________
298const AliMUONGeometryModule*
299AliMUONGeometry::GetModuleByDEId(Int_t detElemId, Bool_t warn) const
300{
301/// Return the geometry module specified by index
302
303 // Get module index
304 Int_t index = AliMUONGeometryDEIndexing::GetModuleId(detElemId);
305
306 return GetModule(index, warn);
307}