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