source: trunk/source/persistency/ascii/src/G4tgbMaterialMgr.cc@ 1354

Last change on this file since 1354 was 1347, checked in by garnier, 15 years ago

geant4 tag 9.4

File size: 14.5 KB
RevLine 
[1035]1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
[1347]27// $Id: G4tgbMaterialMgr.cc,v 1.7 2010/10/13 15:20:01 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-04-ref-00 $
[1035]29//
30//
31// class G4tgbMaterialMgr
32
33// History:
34// - Created. P.Arce, CIEMAT (November 2007)
35// -------------------------------------------------------------------------
36
37#include "G4tgbMaterialMgr.hh"
38#include "G4tgbMaterialMixtureByWeight.hh"
39#include "G4tgbMaterialMixtureByVolume.hh"
40#include "G4tgbMaterialMixtureByNoAtoms.hh"
41#include "G4tgbMaterialSimple.hh"
42
43#include "G4tgrMaterialFactory.hh"
44#include "G4tgrMaterialSimple.hh"
45#include "G4tgrMaterialMixture.hh"
46#include "G4tgrUtils.hh"
47#include "G4tgrMessenger.hh"
48#include "G4NistManager.hh"
49
50
51G4tgbMaterialMgr* G4tgbMaterialMgr::theInstance = 0;
52
53
54// -------------------------------------------------------------------------
55G4tgbMaterialMgr::G4tgbMaterialMgr()
56{
57}
58
59
60// -------------------------------------------------------------------------
61G4tgbMaterialMgr* G4tgbMaterialMgr::GetInstance()
62{
63 if( !theInstance )
64 {
65 theInstance = new G4tgbMaterialMgr;
66 theInstance->CopyIsotopes();
67 theInstance->CopyElements();
68 theInstance->CopyMaterials();
69 }
70 return theInstance;
71}
72
73
74// -------------------------------------------------------------------------
75G4tgbMaterialMgr::~G4tgbMaterialMgr()
76{
77 G4mstgbisot::const_iterator isotcite;
78 for( isotcite = theG4tgbIsotopes.begin();
79 isotcite != theG4tgbIsotopes.end(); isotcite++)
80 {
81 delete (*isotcite).second;
82 }
83 theG4tgbIsotopes.clear();
84
85 G4mstgbelem::const_iterator elemcite;
86 for( elemcite = theG4tgbElements.begin();
87 elemcite != theG4tgbElements.end(); elemcite++)
88 {
89 delete (*elemcite).second;
90 }
91 theG4tgbElements.clear();
92
93 G4mstgbmate::const_iterator matcite;
94 for( matcite = theG4tgbMaterials.begin();
95 matcite != theG4tgbMaterials.end(); matcite++)
96 {
97 delete (*matcite).second;
98 }
99 theG4tgbMaterials.clear();
100
101 delete theInstance;
102}
103
104
105// -------------------------------------------------------------------------
106void G4tgbMaterialMgr::CopyIsotopes()
107{
108 const G4mstgrisot tgrIsots
109 = G4tgrMaterialFactory::GetInstance()->GetIsotopeList();
110 G4mstgrisot::const_iterator cite;
111 for( cite = tgrIsots.begin(); cite != tgrIsots.end(); cite++ )
112 {
113 G4tgrIsotope* tgr = (*cite).second;
114 G4tgbIsotope* tgb = new G4tgbIsotope( tgr );
115 theG4tgbIsotopes[tgb->GetName()] = tgb;
116 }
117}
118
119
120// -------------------------------------------------------------------------
121void G4tgbMaterialMgr::CopyElements()
122{
123 const G4mstgrelem tgrElems
124 = G4tgrMaterialFactory::GetInstance()->GetElementList();
125 G4mstgrelem::const_iterator cite;
126 for( cite = tgrElems.begin(); cite != tgrElems.end(); cite++ )
127 {
128 G4tgrElement* tgr = (*cite).second;
129 G4tgbElement* tgb = new G4tgbElement( tgr );
130 theG4tgbElements[tgb->GetName()] = tgb;
131 }
132}
133
134
135// -------------------------------------------------------------------------
136void G4tgbMaterialMgr::CopyMaterials()
137{
138 const G4mstgrmate tgrMates
139 = G4tgrMaterialFactory::GetInstance()->GetMaterialList();
140 G4mstgrmate::const_iterator cite;
141 for( cite = tgrMates.begin(); cite != tgrMates.end(); cite++ )
142 {
143 G4tgrMaterial* tgr = (*cite).second;
144 G4tgbMaterial* tgb = 0;
145 if( tgr->GetType() == "MaterialSimple" ) {
146 tgb = new G4tgbMaterialSimple( tgr );
147 } else if( tgr->GetType() == "MaterialMixtureByWeight" ) {
148 tgb = new G4tgbMaterialMixtureByWeight( tgr );
149 } else if( tgr->GetType() == "MaterialMixtureByNoAtoms" ) {
150 tgb = new G4tgbMaterialMixtureByNoAtoms( tgr );
151 } else if( tgr->GetType() == "MaterialMixtureByVolume" ) {
152 tgb = new G4tgbMaterialMixtureByVolume( tgr );
[1347]153 } else {
154 return;
155 }
[1035]156 theG4tgbMaterials[tgb->GetName()] = tgb;
157 }
158}
159
160
161// -------------------------------------------------------------------------
162G4Isotope* G4tgbMaterialMgr::FindOrBuildG4Isotope(const G4String & name)
163{
164 G4Isotope* g4isot = FindBuiltG4Isotope( name );
165 if( g4isot == 0 )
166 {
167 G4tgbIsotope* tgbisot = FindG4tgbIsotope( name );
168 // FindG4tgbIsotope never returns 0, otherwise if not found, crashes
169 g4isot = tgbisot->BuildG4Isotope();
170 // Register it
171 G4String isotname = g4isot->GetName();
172 theG4Isotopes[isotname] = g4isot;
173 }
174 else
175 {
176#ifdef G4VERBOSE
177 if( G4tgrMessenger::GetVerboseLevel() >= 1 )
178 {
179 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Isotope() -"
180 << " G4Isotope already built: " << g4isot->GetName() << G4endl;
181 }
182#endif
183 }
184
185#ifdef G4VERBOSE
186 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
187 {
188 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Isotope() - Isotope: "
189 << name << G4endl;
190 }
191#endif
192 return g4isot;
193}
194
195
196// -------------------------------------------------------------------------
197G4Isotope* G4tgbMaterialMgr::FindBuiltG4Isotope(const G4String & name) const
198{
199 G4Isotope* g4isot = 0;
200
201 G4msg4isot::const_iterator cite = theG4Isotopes.find( name );
202 if( cite != theG4Isotopes.end() )
203 {
204 g4isot = (*cite).second;
205#ifdef G4VERBOSE
206 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
207 {
208 G4cout << " G4tgbMaterialMgr::FindBuiltG4Isotope() - Isotope: "
209 << name << " = " << g4isot << G4endl;
210 }
211#endif
212
213 }
214
215 return g4isot;
216}
217
218
219// -------------------------------------------------------------------------
220G4tgbIsotope* G4tgbMaterialMgr::FindG4tgbIsotope(const G4String & name,
221 G4bool bMustExist ) const
222{
223 G4tgbIsotope* isot = 0;
224
225 G4mstgbisot::const_iterator cite = theG4tgbIsotopes.find( name );
226 if( cite != theG4tgbIsotopes.end() )
227 {
228#ifdef G4VERBOSE
229 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
230 {
231 G4cout << " G4tgbMaterialMgr::FindG4tgbIsotope() -"
232 << " G4tgbIsotope found: " << ( (*cite).second )->GetName()
233 << G4endl;
234 }
235#endif
236 isot = (*cite).second;
237 }
238 if( (isot == 0) && bMustExist )
239 {
240 G4String ErrMessage = "Isotope " + name + " not found !";
241 G4Exception("G4tgbMaterialMgr::FindG4tgbIsotope()",
242 "InvalidSetup", FatalException, ErrMessage);
243 }
244
245 return isot;
246}
247
248
249// -------------------------------------------------------------------------
250G4Element* G4tgbMaterialMgr::FindOrBuildG4Element(const G4String & name,
251 G4bool bMustExist )
252{
253 G4Element* g4elem = FindBuiltG4Element( name );
254 if( g4elem == 0 )
255 {
256 G4tgbElement* tgbelem = FindG4tgbElement( name, false );
257 if( tgbelem == 0)
258 {
259 // If FindG4tgbElement returns 0, look for a G4NISTElement
260 G4cout << " G4NistManager::Instance()->FindOrBuildElement( " << G4endl;
261 g4elem = G4NistManager::Instance()->FindOrBuildElement(name);
262 }
263 else
264 {
265 if( tgbelem->GetType() == "ElementSimple" )
266 {
267 g4elem = tgbelem->BuildG4ElementSimple();
268 }
269 else if( tgbelem->GetType() == "ElementFromIsotopes" )
270 {
271 g4elem = tgbelem->BuildG4ElementFromIsotopes();
272 }
273 else
274 {
275 G4String ErrMessage = "Element type " + tgbelem->GetType()
276 + " does not exist !";
277 G4Exception("G4tgbMaterialMgr::GetG4Element()",
278 "InvalidSetup", FatalException, ErrMessage);
279 }
280 }
281 // Register it
282 if( (g4elem != 0) )
283 {
284 theG4Elements[g4elem->GetName()] = g4elem;
285#ifdef G4VERBOSE
286 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
287 {
288 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Element() - Element: "
289 << name << G4endl;
290 }
291#endif
292 }
293 else
294 {
295 if( bMustExist )
296 {
297 G4String ErrMessage = "Element " + name + " not found !";
298 G4Exception("G4tgbMaterialMgr::FindOrBuildG4Element()",
299 "InvalidSetup", FatalException, ErrMessage);
300 }
301#ifdef G4VERBOSE
302 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
303 {
304 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Element() - Element: "
305 << name << " not found " << G4endl;
306 }
307#endif
308 }
309 }
310 else
311 {
312#ifdef G4VERBOSE
313 if( G4tgrMessenger::GetVerboseLevel() >= 1 )
314 {
315 G4cout << " G4tgbMaterialMgr::GetG4Element() -"
316 << " G4Element already built: " << g4elem->GetName() << G4endl;
317 }
318#endif
319 }
320
321 return g4elem;
322}
323
324
325// -------------------------------------------------------------------------
326G4Element* G4tgbMaterialMgr::FindBuiltG4Element(const G4String & name) const
327{
328 G4Element* g4elem = 0;
329
330 G4msg4elem::const_iterator cite = theG4Elements.find( name );
331 if( cite != theG4Elements.end() )
332 {
333 g4elem = (*cite).second;
334#ifdef G4VERBOSE
335 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
336 {
337 G4cout << " G4tgbMaterialMgr::FindBuiltG4Element() - Element: "
338 << name << " = " << g4elem << G4endl;
339 }
340#endif
341 }
342
343 return g4elem;
344}
345
346
347// -------------------------------------------------------------------------
348G4tgbElement* G4tgbMaterialMgr::FindG4tgbElement(const G4String & name,
349 G4bool bMustExist ) const
350{
351 G4tgbElement* elem = 0;
352
353 G4mstgbelem::const_iterator cite = theG4tgbElements.find( name );
354 if( cite != theG4tgbElements.end() )
355 {
356#ifdef G4VERBOSE
357 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
358 {
359 G4cout << " G4tgbMaterialMgr::FindG4tgbElement() -"
360 << " G4tgbElement found: " << ( (*cite).second )->GetName()
361 << G4endl;
362 }
363#endif
364 elem = (*cite).second;
365 }
366 if( (elem == 0) && bMustExist )
367 {
368 G4String ErrMessage = "Element " + name + " not found !";
369 G4Exception("G4tgbMaterialMgr::FindG4tgbElement()",
370 "InvalidSetup", FatalException, ErrMessage);
371 }
372
373 return elem;
374}
375
376
377// -------------------------------------------------------------------------
378G4Material* G4tgbMaterialMgr::FindOrBuildG4Material(const G4String & name,
379 G4bool bMustExist )
380{
381 G4Material* g4mate = FindBuiltG4Material( name );
382 if( g4mate == 0)
383 {
384 G4tgbMaterial* tgbmate = FindG4tgbMaterial( name, false );
385
386 if( tgbmate == 0)
387 {
388 // if FindG4tgbMaterial() returns 0, look for a G4NISTMaterial
389 g4mate = G4NistManager::Instance()->FindOrBuildMaterial(name);
390 }
391 else
392 {
393 g4mate = tgbmate->BuildG4Material();
394
395 if( tgbmate->GetTgrMate()->GetIonisationMeanExcitationEnergy() != -1. )
396 {
397 g4mate->GetIonisation()->SetMeanExcitationEnergy(tgbmate->
398 GetTgrMate()->GetIonisationMeanExcitationEnergy());
399 }
400 }
401
402 // Register it
403 if( g4mate != 0 )
404 {
405 theG4Materials[g4mate->GetName()] = g4mate;
406#ifdef G4VERBOSE
407 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
408 {
409 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() - Material: "
410 << name << G4endl;
411 }
412#endif
413 }
414 else
415 {
416 if( bMustExist )
417 {
418 G4String ErrMessage = "Material " + name + " not found !";
419 G4Exception("G4tgbMaterialMgr::FindOrBuildG4Material()",
420 "InvalidSetup", FatalException, ErrMessage);
421 }
422#ifdef G4VERBOSE
423 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
424 {
425 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() - Element: "
426 << name << " not found " << G4endl;
427 }
428#endif
429 }
430 }
431 else
432 {
433#ifdef G4VERBOSE
434 if( G4tgrMessenger::GetVerboseLevel() >= 1 )
435 {
436 G4cout << " G4tgbMaterialMgr::FindOrBuildG4Material() -"
437 << " G4Material already built: " << g4mate->GetName() << G4endl;
438 }
439#endif
440 }
441
442 return g4mate;
443}
444
445
446// -------------------------------------------------------------------------
447G4Material* G4tgbMaterialMgr::FindBuiltG4Material(const G4String & name) const
448{
449 G4Material* g4mate = 0;
450 //---------- look for an existing G4Material
451 G4msg4mate::const_iterator cite = theG4Materials.find( name );
452 if( cite != theG4Materials.end() )
453 {
454 g4mate = (*cite).second;
455#ifdef G4VERBOSE
456 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
457 {
458 G4cout << " G4tgbMaterialMgr::FindBuiltG4Material() - Material: "
459 << name << " = " << g4mate << G4endl;
460 }
461#endif
462 }
463
464 return g4mate;
465}
466
467
468// -------------------------------------------------------------------------
469G4tgbMaterial* G4tgbMaterialMgr::FindG4tgbMaterial(const G4String & name,
470 G4bool bMustExist ) const
471{
472 G4tgbMaterial* mate = 0;
473 G4mstgbmate::const_iterator cite = theG4tgbMaterials.find( name );
474 if( cite != theG4tgbMaterials.end() )
475 {
476 mate = (*cite).second;
477#ifdef G4VERBOSE
478 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
479 {
480 G4cout << " G4tgbMaterialMgr::FindG4tgbMaterial() -"
481 << " G4tgbMaterial found: " << ( (*cite).second )->GetName()
482 << " type " << ( (*cite).second )->GetName() << G4endl;
483 }
484#endif
485 }
486
487 if( (mate == 0) && bMustExist )
488 {
489 G4String ErrMessage = "Material " + name + " not found !";
490 G4Exception("G4tgbMaterialMgr::FindG4tgbMaterial()",
491 "InvalidSetup", FatalException, ErrMessage);
492 }
493
494 return mate;
495}
Note: See TracBrowser for help on using the repository browser.