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