Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4tgrMaterialFactory.cc
Go to the documentation of this file.
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 //
27 // $Id: G4tgrMaterialFactory.cc 66872 2013-01-15 01:25:57Z japost $
28 //
29 //
30 // class G4tgrMaterialFactory
31 
32 // History:
33 // - Created. P.Arce, CIEMAT (November 2007)
34 // -------------------------------------------------------------------------
35 
36 #include "G4tgrMaterialFactory.hh"
37 #include "G4tgrUtils.hh"
38 #include "G4tgrElementSimple.hh"
40 #include "G4tgrMaterialSimple.hh"
41 #include "G4tgrMaterialMixture.hh"
42 #include "G4tgrFileReader.hh"
43 #include "G4tgrMessenger.hh"
44 
45 
46 G4ThreadLocal G4tgrMaterialFactory* G4tgrMaterialFactory::theInstance = 0;
47 
48 
49 //-------------------------------------------------------------
50 G4tgrMaterialFactory::G4tgrMaterialFactory()
51 {
52 }
53 
54 
55 //-------------------------------------------------------------
57 {
58  if( !theInstance )
59  {
60  theInstance = new G4tgrMaterialFactory;
61  }
62  return theInstance;
63 }
64 
65 
66 //-------------------------------------------------------------
68 {
69  G4mstgrisot::iterator isotcite;
70  for( isotcite = theG4tgrIsotopes.begin();
71  isotcite != theG4tgrIsotopes.end(); isotcite++)
72  {
73  delete (*isotcite).second;
74  }
75  theG4tgrIsotopes.clear();
76 
77  G4mstgrelem::iterator elemcite;
78  for( elemcite = theG4tgrElements.begin();
79  elemcite != theG4tgrElements.end(); elemcite++)
80  {
81  delete (*elemcite).second;
82  }
83  theG4tgrElements.clear();
84 
85  G4mstgrmate::iterator matcite;
86  for( matcite = theG4tgrMaterials.begin();
87  matcite != theG4tgrMaterials.end(); matcite++)
88  {
89  delete (*matcite).second;
90  }
91  theG4tgrMaterials.clear();
92  delete theInstance;
93 }
94 
95 
96 //-------------------------------------------------------------
98 G4tgrMaterialFactory::AddIsotope( const std::vector<G4String>& wl )
99 {
100  //---------- Look if isotope exists
101  if( FindIsotope( G4tgrUtils::GetString(wl[1]) ) != 0 )
102  {
103  ErrorAlreadyExists("isotope", wl );
104  }
105 
106  G4tgrIsotope* isot = new G4tgrIsotope( wl );
107  theG4tgrIsotopes[isot->GetName()] = isot;
108 
109  return isot;
110 }
111 
112 //-------------------------------------------------------------
114 G4tgrMaterialFactory::AddElementSimple( const std::vector<G4String>& wl )
115 {
116  //---------- Look if element exists
117  if( FindElement( G4tgrUtils::GetString(wl[1]) ) != 0 )
118  {
119  ErrorAlreadyExists("element", wl );
120  }
121 
122  G4tgrElementSimple* elem = new G4tgrElementSimple( wl );
123  theG4tgrElements[elem->GetName()] = elem;
124 
125  return elem;
126 }
127 
128 
129 //-------------------------------------------------------------
131 G4tgrMaterialFactory::AddElementFromIsotopes( const std::vector<G4String>& wl )
132 {
133  //---------- Look if element exists
134  if( FindElement( G4tgrUtils::GetString(wl[1]) ) != 0 )
135  {
136  ErrorAlreadyExists("element", wl );
137  }
138 
140  theG4tgrElements[elem->GetName()] = elem;
141 
142  return elem;
143 }
144 
145 
146 //-------------------------------------------------------------
148 G4tgrMaterialFactory::AddMaterialSimple( const std::vector<G4String>& wl )
149 {
150 #ifdef G4VERBOSE
152  {
153  G4cout << " G4tgrMaterialFactory::AddMaterialSimple" << wl[1] << G4endl;
154  }
155 #endif
156 
157  //---------- Look if material exists
158  if( FindMaterial( G4tgrUtils::GetString(wl[1]) ) != 0 )
159  {
160  ErrorAlreadyExists("material simple", wl );
161  }
162 
163  G4tgrMaterialSimple* mate = new G4tgrMaterialSimple("MaterialSimple", wl );
164 
165  //---------- register this material
166  theG4tgrMaterials[ mate->GetName() ] = mate;
167 
168  return mate;
169 }
170 
171 
172 //-------------------------------------------------------------
174 G4tgrMaterialFactory::AddMaterialMixture( const std::vector<G4String>& wl,
175  const G4String& mixtType )
176 {
177 #ifdef G4VERBOSE
179  {
180  G4cout << " G4tgrMaterialFactory::AddMaterialMixture " << wl[1] << G4endl;
181  }
182 #endif
183 
184  //---------- Look if material already exists
185  if( FindMaterial( G4tgrUtils::GetString(wl[1]) ) != 0 )
186  {
187  ErrorAlreadyExists("material mixture", wl );
188  }
189 
190  G4tgrMaterialMixture* mate;
191  mate = new G4tgrMaterialMixture( mixtType, wl );
192 
193  //---------- register this material
194  theG4tgrMaterials[ mate->GetName() ] = mate;
195 
196  return mate;
197 }
198 
199 
200 //-------------------------------------------------------------
202 {
203 #ifdef G4VERBOSE
205  {
206  G4cout << " G4tgrMaterialFactory::FindIsotope() - " << name << G4endl;
207  }
208 #endif
209 
210  G4mstgrisot::const_iterator cite;
211  cite = theG4tgrIsotopes.find( name );
212  if( cite == theG4tgrIsotopes.end() )
213  {
214  return 0;
215  }
216  else
217  {
218 #ifdef G4VERBOSE
220  {
221  G4cout << " G4tgrIsotope found: "
222  << ( (*cite).second )->GetName() << G4endl;
223  }
224 #endif
225  return (*cite).second;
226  }
227 }
228 
229 
230 //-------------------------------------------------------------
232 {
233 #ifdef G4VERBOSE
235  {
236  G4cout << " G4tgrMaterialFactory::FindElement() - " << name << G4endl;
237  }
238 #endif
239  G4mstgrelem::const_iterator cite;
240  cite = theG4tgrElements.find( name );
241  if( cite == theG4tgrElements.end() )
242  {
243  return 0;
244  }
245  else
246  {
247 #ifdef G4VERBOSE
249  {
250  DumpElementList();
251  G4cout << " G4tgrElement found: "
252  << ( (*cite).second )->GetName() << G4endl;
253  }
254 #endif
255  return (*cite).second;
256  }
257 }
258 
259 
260 //-------------------------------------------------------------
262 {
263 #ifdef G4VERBOSE
265  {
266  G4cout << " G4tgrMaterialFactory::FindMaterial() - " << name << G4endl;
267  }
268 #endif
269  G4mstgrmate::const_iterator cite;
270  cite = theG4tgrMaterials.find( name );
271  if( cite == theG4tgrMaterials.end() )
272  {
273  return 0;
274  }
275  else
276  {
277  return (*cite).second;
278  }
279 }
280 
281 
282 //-------------------------------------------------------------
284 {
285  G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrIsotope's List " << G4endl;
286  G4mstgrisot::const_iterator cite;
287  for(cite = theG4tgrIsotopes.begin(); cite != theG4tgrIsotopes.end(); cite++)
288  {
289  G4cout << " ISOT: " << (*cite).second->GetName() << G4endl;
290  }
291 }
292 
293 
294 //-------------------------------------------------------------
296 {
297  G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrElement's List " << G4endl;
298  G4mstgrelem::const_iterator cite;
299  for(cite = theG4tgrElements.begin(); cite != theG4tgrElements.end(); cite++)
300  {
301  G4cout << " ELEM: " << (*cite).second->GetName() << G4endl;
302  }
303 }
304 
305 
306 //-------------------------------------------------------------
308 {
309  G4cout << " @@@@@@@@@@@@@@@@ DUMPING G4tgrMaterial's List " << G4endl;
310  G4mstgrmate::const_iterator cite;
311  for(cite = theG4tgrMaterials.begin(); cite != theG4tgrMaterials.end(); cite++)
312  {
313  G4tgrMaterial* mate = (*cite).second;
314  G4cout << " MATE: " << mate->GetName() << " Type: " << mate->GetType()
315  << " NoComponents= " << mate->GetNumberOfComponents() << G4endl;
316  }
317 }
318 
319 
320 //-------------------------------------------------------------
321 void G4tgrMaterialFactory::
322 ErrorAlreadyExists(const G4String& object,
323  const std::vector<G4String>& wl, const G4bool bNoRepeating )
324 {
325  G4String msg = object + G4String(" repeated");
326  if( bNoRepeating )
327  {
328  G4tgrUtils::DumpVS( wl, (G4String("!!!! EXITING: ") + msg).c_str() );
329  G4Exception("G4tgrMaterialFactory", "FatalError",
330  FatalException, "Aborting...");
331  }
332  else
333  {
334 #ifdef G4VERBOSE
336  {
337  G4tgrUtils::DumpVS( wl, (G4String("!! WARNING: ") + msg).c_str() );
338  }
339 #endif
340  }
341 }
G4tgrElementFromIsotopes * AddElementFromIsotopes(const std::vector< G4String > &wl)
G4tgrIsotope * FindIsotope(const G4String &name) const
G4tgrMaterialSimple * AddMaterialSimple(const std::vector< G4String > &wl)
const XML_Char * name
const G4String & GetName() const
Definition: G4tgrIsotope.hh:60
#define G4ThreadLocal
Definition: tls.hh:52
const G4String & GetName() const
G4GLOB_DLL std::ostream G4cout
static G4int GetVerboseLevel()
G4int GetNumberOfComponents() const
G4tgrMaterial * FindMaterial(const G4String &name) const
bool G4bool
Definition: G4Types.hh:79
const G4String & GetType() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static void DumpVS(const std::vector< G4String > &wl, const char *msg)
Definition: G4tgrUtils.cc:158
static G4String GetString(const G4String &str)
Definition: G4tgrUtils.cc:180
#define G4endl
Definition: G4ios.hh:61
G4tgrMaterialMixture * AddMaterialMixture(const std::vector< G4String > &wl, const G4String &mixtType)
const G4String & GetName() const
Definition: G4tgrElement.hh:52
static G4tgrMaterialFactory * GetInstance()
G4tgrElementSimple * AddElementSimple(const std::vector< G4String > &wl)
G4tgrElement * FindElement(const G4String &name) const
G4tgrIsotope * AddIsotope(const std::vector< G4String > &wl)