AliRoot Core  da88d91 (da88d91)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMUONGeometry.cxx
Go to the documentation of this file.
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"
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;
46 
47 //______________________________________________________________________________
49  : TObject(),
50  fModules(0),
51  fTransformer(0)
52 
53 {
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 //______________________________________________________________________________
67  : TObject(),
68  fModules(0),
69  fTransformer(0)
70 {
72 }
73 
74 //______________________________________________________________________________
76 {
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 {
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 {
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 {
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 {
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 //_____________________________________________________________________________
180 {
182 
183  fModules->Add(module);
184 
185  if (module)
187 }
188 
189 //______________________________________________________________________________
190 Bool_t
191 AliMUONGeometry::ReadSVMap(const TString& fileName)
192 {
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 {
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 {
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 {
280 
281  // Get module index
282  Int_t index = AliMpDEManager::GetGeomModuleId(detElemId);
283 
284  return GetModule(index, warn);
285 }
virtual ~AliMUONGeometry()
AliMUONStringIntMap * GetSVMap() const
Return sensitive volume map.
TString ComposePath(const TString &volName, Int_t copyNo) const
void AddModule(AliMUONGeometryModule *module)
#define TObjArray
Top container class for geometry transformations.
Bool_t WriteSVMap(const TString &fileName) const
const char * path
static Int_t GetGeomModuleId(Int_t detElemId, Bool_t warn=true)
const AliMUONGeometryModule * GetModuleByDEId(Int_t detElemId, Bool_t warn=true) const
AliMUONGeometryModuleTransformer * GetTransformer() const
Return transformer.
Substitutes map <string, int> which ALICE does not allow to use.
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
void WriteData3(ofstream &out) const
Container class for geometry modules.
virtual void Print(const char *="") const
void FillData3(const TString &sensVolumePath, Int_t detElemId)
TString ReadData3(ifstream &in)
TObjArray * fModules
Array of geometry modules.
Bool_t Add(const TString &first, Int_t second)
const AliMUONGeometryModule * GetModule(Int_t index, Bool_t warn=true) const
Geometry parameters for detector module.
void AddModuleTransformer(AliMUONGeometryModuleTransformer *transformer)
Bool_t ReadSVMap(const TString &fileName)
AliMUONGeometryTransformer * fTransformer
Geometry transformer.