source: trunk/source/persistency/ascii/src/G4tgrMaterialFactory.cc @ 1035

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

dossiers oublies

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