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