]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometry.cxx
Fixed compiler warnings:
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometry.cxx
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 ClassImp(AliMUONGeometry)
45 /// \endcond
46  
47 //______________________________________________________________________________
48 AliMUONGeometry::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
61   fTransformer = new AliMUONGeometryTransformer();
62   fTransformer->SetOwner(false); 
63 }
64
65 //______________________________________________________________________________
66 AliMUONGeometry::AliMUONGeometry() 
67   : TObject(),
68     fModules(0),
69     fTransformer(0)
70 {
71 /// Default constructor
72
73
74 //______________________________________________________________________________
75 AliMUONGeometry::~AliMUONGeometry()
76 {
77 /// Destructor
78
79   delete fModules;
80   delete fTransformer;
81 }
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   TString path(volName);
94   path += ".";
95   path += copyNo;
96   
97   return path;
98 }  
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   Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
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
121   AliMUONStringIntMap* svMap = module->GetSVMap();     
122
123   // Map the sensitive volume to detection element
124   svMap->Add(sensVolumePath, detElemId); 
125 }                  
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   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 //______________________________________________________________________________
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   for (Int_t i=0; i<fModules->GetEntriesFast(); i++) {
164     AliMUONGeometryModule* geometry 
165       = (AliMUONGeometryModule*)fModules->At(i);
166     AliMUONStringIntMap* svMap
167       = geometry->GetSVMap();
168
169     svMap->Print("SV", out);
170     out << endl;  
171   }    
172 }
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   fModules->Add(module);
184
185   if (module)
186     fTransformer->AddModuleTransformer(module->GetTransformer());
187 }
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   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 //______________________________________________________________________________
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   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 //_____________________________________________________________________________
259 const AliMUONGeometryModule* 
260 AliMUONGeometry::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 //_____________________________________________________________________________
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   Int_t index = AliMpDEManager::GetGeomModuleId(detElemId);
283
284   return GetModule(index, warn);
285 }