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