]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometry.cxx
New class AliESDEvent, backward compatibility with the old AliESD (Christian)
[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 #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();
58   fTransformer->SetOwner(false); 
59 }
60
61 //______________________________________________________________________________
62 AliMUONGeometry::AliMUONGeometry() 
63   : TObject(),
64     fModules(0),
65     fTransformer(0)
66 {
67 /// Default constructor
68
69
70 //______________________________________________________________________________
71 AliMUONGeometry::~AliMUONGeometry()
72 {
73 /// Destructor
74
75   delete fModules;
76   delete fTransformer;
77 }
78
79 //
80 // private methods
81 //
82
83 //______________________________________________________________________________
84 TString  AliMUONGeometry::ComposePath(const TString& volName, 
85                                        Int_t copyNo) const
86 {
87 /// Compose path from given volName and copyNo
88
89   TString path(volName);
90   path += ".";
91   path += copyNo;
92   
93   return path;
94 }  
95
96 //______________________________________________________________________________
97 void AliMUONGeometry::FillData3(const TString& sensVolumePath, 
98                                 Int_t detElemId)
99 {
100 /// Fill the mapping of the sensitive volume path to the detection element.
101
102   // Module Id
103   Int_t moduleId = AliMpDEManager::GetGeomModuleId(detElemId);
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
117   AliMUONStringIntMap* svMap = module->GetSVMap();     
118
119   // Map the sensitive volume to detection element
120   svMap->Add(sensVolumePath, detElemId); 
121 }                  
122   
123 //______________________________________________________________________________
124 TString  AliMUONGeometry::ReadData3(ifstream& in)
125 {
126 /// Read SV maps from a file.
127 /// Return true, if reading finished correctly.
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 //______________________________________________________________________________
154 void AliMUONGeometry::WriteData3(ofstream& out) const
155 {
156 /// Write association of sensitive volumes and detection elements
157 /// from the sensitive volume map
158
159   for (Int_t i=0; i<fModules->GetEntriesFast(); i++) {
160     AliMUONGeometryModule* geometry 
161       = (AliMUONGeometryModule*)fModules->At(i);
162     AliMUONStringIntMap* svMap
163       = geometry->GetSVMap();
164
165     svMap->Print("SV", out);
166     out << endl;  
167   }    
168 }
169
170 //
171 // public functions
172 //
173
174 //_____________________________________________________________________________
175 void AliMUONGeometry::AddModule(AliMUONGeometryModule* module)
176 {
177 /// Add the geometry module to the array
178
179   fModules->Add(module);
180
181   if (module)
182     fTransformer->AddModuleTransformer(module->GetTransformer());
183 }
184
185 //______________________________________________________________________________
186 Bool_t  
187 AliMUONGeometry::ReadSVMap(const TString& fileName)
188 {
189 /// Read the sensitive volume maps from a file.
190 /// Return true, if reading finished correctly.
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 //______________________________________________________________________________
224 Bool_t  
225 AliMUONGeometry::WriteSVMap(const TString& fileName) const
226 {
227 /// Write sensitive volume map into a file.
228 /// Return true, if writing finished correctly.
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 //_____________________________________________________________________________
255 const AliMUONGeometryModule* 
256 AliMUONGeometry::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 //_____________________________________________________________________________
272 const AliMUONGeometryModule* 
273 AliMUONGeometry::GetModuleByDEId(Int_t detElemId, Bool_t warn) const
274 {
275 /// Return the geometry module specified by detElemId
276
277   // Get module index
278   Int_t index = AliMpDEManager::GetGeomModuleId(detElemId);
279
280   return GetModule(index, warn);
281 }