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.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /persistency/ascii/src/G4tgbMaterialMgr.cc (Version 11.3.0) and /persistency/ascii/src/G4tgbMaterialMgr.cc (Version 9.0.p1)


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