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