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