Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CCalMaterialFactory Class Reference

#include <CCalMaterialFactory.hh>

Public Types

enum  MatDescription { byWeight, byVolume, byAtomic }
 

Public Member Functions

 ~CCalMaterialFactory ()
 
G4MaterialfindMaterial (const G4String &) const
 
G4ElementfindElement (const G4String &) const
 
G4ElementaddElement (const G4String &, const G4String &, G4double, G4double, G4double)
 
G4MaterialaddMaterial (const G4String &nam, G4double density, G4int nconst, G4String mats[], G4double prop[], MatDescription md=byWeight)
 
void readElements (const G4String &)
 
void readMaterials (const G4String &)
 

Static Public Member Functions

static CCalMaterialFactorygetInstance (const G4String &, const G4String &)
 
static CCalMaterialFactorygetInstance (const G4String &)
 
static CCalMaterialFactorygetInstance ()
 

Protected Member Functions

void readElements (std::ifstream &)
 
void readMaterials (std::ifstream &)
 

Detailed Description

Definition at line 47 of file CCalMaterialFactory.hh.

Member Enumeration Documentation

Constructor & Destructor Documentation

CCalMaterialFactory::~CCalMaterialFactory ( )

Definition at line 96 of file CCalMaterialFactory.cc.

96  {
97  CCalMaterialTable::iterator ite;
98  for(ite = theCCalMaterials.begin(); ite != theCCalMaterials.end(); ite++ ){
99  delete *ite;
100  }
101  theCCalMaterials.clear();
102  CCalAMaterialTable::iterator itea;
103  for(itea = theCCalAMaterials.begin(); itea != theCCalAMaterials.end();
104  itea++ ){
105  delete *itea;
106  }
107  theCCalAMaterials.clear();
108 }

Member Function Documentation

G4Element * CCalMaterialFactory::addElement ( const G4String name,
const G4String symbol,
G4double  Z,
G4double  A,
G4double  density 
)

Definition at line 162 of file CCalMaterialFactory.cc.

165  {
166 
167  G4Element* theEl = new G4Element(name, symbol, Z, A*g/mole);
168  //Make it also as a material.
169  CCalAMaterial* theMat = new CCalAMaterial(name,A,density);
170  theCCalAMaterials.push_back(theMat);
171 
172 #ifdef ddebug
173  G4cout << "Element " << name << " created!" << G4endl;
174 #endif
175  return theEl;
176 }
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
G4GLOB_DLL std::ostream G4cout
double A(double temperature)
#define G4endl
Definition: G4ios.hh:61
static constexpr double mole
Definition: G4SIunits.hh:286

Here is the call graph for this function:

Here is the caller graph for this function:

G4Material * CCalMaterialFactory::addMaterial ( const G4String nam,
G4double  density,
G4int  nconst,
G4String  mats[],
G4double  prop[],
MatDescription  md = byWeight 
)

Definition at line 179 of file CCalMaterialFactory.cc.

184  {
185  addCCalMaterial(name, density, nconst, mats, prop, md);
186  return findMaterial(name);
187 }
const XML_Char * name
Definition: expat.h:151
G4Material * findMaterial(const G4String &) const

Here is the call graph for this function:

G4Element * CCalMaterialFactory::findElement ( const G4String mat) const

Definition at line 149 of file CCalMaterialFactory.cc.

149  {
150  const G4ElementTable theElements = *(G4Element::GetElementTable());
151  for (unsigned int i=0; i<theElements.size(); i++)
152  if (theElements[i]->GetName()==mat){
153 #ifdef ddebug
154  G4cout << "Element " << mat << " found!" << G4endl;
155 #endif
156  return theElements[i];
157  }
158  return 0;
159 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
std::vector< G4Element * > G4ElementTable
static G4ElementTable * GetElementTable()
Definition: G4Element.cc:398

Here is the call graph for this function:

Here is the caller graph for this function:

G4Material * CCalMaterialFactory::findMaterial ( const G4String mat) const

Definition at line 111 of file CCalMaterialFactory.cc.

111  {
112  G4Material* theMat=findG4Material(mat);
113 
114  if (theMat) {
115 #ifdef ddebug
116  G4cout << "Material " << mat << " already defined. Returning previous "
117  << "instance." << G4endl;
118 #endif
119  return theMat;
120  } else {
121  CCalMaterial* CCalmat=findCCalMaterial(mat);
122  if (CCalmat){
123  G4Material* G4Mat = new G4Material(CCalmat->Name(),
124  CCalmat->Density()*g/cm3,
125  CCalmat->NElements());
126  for(G4int i=0; i<CCalmat->NElements(); i++) {
127  G4Element* elem = findElement(CCalmat->Element(i));
128  if (!elem) {
130  ed << " Could not build material " << mat << "." << G4endl;
131  G4Exception("CCalMaterialFactory::findMaterial()","ccal001",
132  FatalException,ed);
133  }
134  G4Mat->AddElement(elem, CCalmat->Weight(i));
135  }
136 #ifdef ddebug
137  G4cout << "Material " << mat << " has been built successfully." << G4endl;
138 #endif
139  return G4Mat;
140  } else {
141  G4cerr << "ERROR: Material " << mat << " not found in CCal database!!!"
142  << G4endl;
143  return 0;
144  }
145  }
146 }
int NElements() const
Definition: CCalMaterial.hh:53
double Weight(int i) const
Definition: CCalMaterial.hh:55
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4String Name() const
Definition: CCalMaterial.hh:51
int G4int
Definition: G4Types.hh:78
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
G4GLOB_DLL std::ostream G4cout
double Density() const
Definition: CCalMaterial.hh:52
static constexpr double cm3
Definition: G4SIunits.hh:121
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4String Element(int i) const
Definition: CCalMaterial.hh:54
#define G4endl
Definition: G4ios.hh:61
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:362
G4Element * findElement(const G4String &) const
G4GLOB_DLL std::ostream G4cerr

Here is the call graph for this function:

Here is the caller graph for this function:

CCalMaterialFactory * CCalMaterialFactory::getInstance ( const G4String matfile,
const G4String mixfile 
)
static

Definition at line 53 of file CCalMaterialFactory.cc.

54  {
55  if ((matfile=="" || matfile==elementfile) &&
56  (mixfile=="" || mixfile==mixturefile))
57  return getInstance();
58  else if ((matfile != "" && elementfile != "" && matfile != elementfile) ||
59  (mixfile != "" && mixturefile != "" && mixfile != mixturefile)) {
60  G4cerr << "ERROR: Trying to get materials from " << matfile << " and "
61  << mixfile << " while previously were retrieved from "
62  << elementfile << " and " << mixturefile << "." << G4endl;
63  return 0;
64  } else {
65  if (elementfile == "")
66  elementfile=matfile;
67  if (mixturefile == "")
68  mixturefile=mixfile;
69  return getInstance();
70  }
71 }
#define G4endl
Definition: G4ios.hh:61
static CCalMaterialFactory * getInstance()
G4GLOB_DLL std::ostream G4cerr

Here is the call graph for this function:

CCalMaterialFactory * CCalMaterialFactory::getInstance ( const G4String matfile)
static

Definition at line 74 of file CCalMaterialFactory.cc.

74  {
75  return getInstance(matfile,matfile);
76 }
static CCalMaterialFactory * getInstance()

Here is the call graph for this function:

CCalMaterialFactory * CCalMaterialFactory::getInstance ( )
static

Definition at line 79 of file CCalMaterialFactory.cc.

79  {
80  if (elementfile=="" || mixturefile=="") {
81  G4cerr << "ERROR: You haven't defined files to be used for materials in "
82  << "CCalMaterialFactory::getInstance(const G4String&,const G4String&)"
83  << G4endl;
84  return 0;
85  }
86 
87  if (instance==0) {
89  return instance;
90  }
91  else
92  return instance;
93 }
#define G4endl
Definition: G4ios.hh:61
static MCTruthManager * instance
G4GLOB_DLL std::ostream G4cerr

Here is the caller graph for this function:

void CCalMaterialFactory::readElements ( const G4String matfile)

Definition at line 190 of file CCalMaterialFactory.cc.

190  {
191 
192  G4String path = "NULL";
193  if (getenv("CCAL_GLOBALPATH"))
194  path = getenv("CCAL_GLOBALPATH");
195 
196  G4cout << " ==> Opening file " << matfile << " to read elements..." << G4endl;
197  std::ifstream is;
198  bool ok = openGeomFile(is, path, matfile);
199  if (!ok) {
200  G4cerr << "ERROR: Could not open file " << matfile << G4endl;
201  return;
202  }
203 
204  // Find *DO GMAT
205  findDO(is, G4String("GMAT"));
206 
207  readElements(is);
208 
209  is.close();
210 }
void readElements(const G4String &)
bool openGeomFile(std::ifstream &is, const G4String &pathname, const G4String &filename)
Definition: CCalutils.cc:116
std::ifstream & findDO(std::ifstream &, const G4String &)
Definition: CCalutils.cc:72
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr

Here is the call graph for this function:

void CCalMaterialFactory::readElements ( std::ifstream &  is)
protected

Definition at line 346 of file CCalMaterialFactory.cc.

346  {
347  G4String name, symbol;
348 
349  G4cout << " ==> Reading elements... " << G4endl;
350 #ifdef debug
351  G4cout << " Element \tsymbol\tA\tZ\tdensity\tX_0 abs_l"<< G4endl;
352 #endif
353  //There should come the list of materials. #. Defines a comment
354  //*DO defines the beguining of the Mixes block.
355 
356  readName(is,name);
357  while (name != "*ENDDO") {
358  //It should be an element definition
359  G4double A, Z, density;
360  is >> symbol >> A >> Z >> density >> jump;
361 #ifdef debug
362  G4cout << " " << name << " \t" << symbol << "\t"
363  << A << "\t" << Z << "\t" << density << G4endl;
364 #endif
365  addElement(name, symbol, Z, A, density);
366  readName(is,name);
367  };
368  G4cout << " " << G4Element::GetElementTable()->size()
369  << " elements read from file" << G4endl << G4endl;
370 }
const XML_Char * name
Definition: expat.h:151
G4Element * addElement(const G4String &, const G4String &, G4double, G4double, G4double)
std::istream & jump(std::istream &)
Definition: CCalutils.cc:95
std::ifstream & readName(std::ifstream &, G4String &)
Definition: CCalutils.cc:53
G4GLOB_DLL std::ostream G4cout
double A(double temperature)
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
static G4ElementTable * GetElementTable()
Definition: G4Element.cc:398

Here is the call graph for this function:

void CCalMaterialFactory::readMaterials ( const G4String matfile)

Definition at line 213 of file CCalMaterialFactory.cc.

213  {
214 
215  G4String path = "NULL";
216  if (getenv("CCAL_GLOBALPATH"))
217  path = getenv("CCAL_GLOBALPATH");
218 
219  G4cout << " ==> Opening file " << matfile << " to read materials..." << G4endl;
220  std::ifstream is;
221  bool ok = openGeomFile(is, path, matfile);
222  if (!ok) {
223  G4cerr << "ERROR: Could not open file " << matfile << G4endl;
224  return;
225  }
226 
227  // Find *DO GMIX
228  findDO(is, G4String("GMIX"));
229 
230  readMaterials(is);
231 
232  is.close();
233 }
bool openGeomFile(std::ifstream &is, const G4String &pathname, const G4String &filename)
Definition: CCalutils.cc:116
std::ifstream & findDO(std::ifstream &, const G4String &)
Definition: CCalutils.cc:72
G4GLOB_DLL std::ostream G4cout
void readMaterials(const G4String &)
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr

Here is the call graph for this function:

void CCalMaterialFactory::readMaterials ( std::ifstream &  is)
protected

Definition at line 373 of file CCalMaterialFactory.cc.

373  {
374  G4String name, matname;
375 
376  G4cout << " ==> Reading materials... " << G4endl;
377 
378  //Take into account the special case of vacuum...
379 #ifdef debug
380  G4cout <<" \"Vacuum\"" << G4endl;
381 #endif
382  G4double density = universe_mean_density; //from PhysicalConstants.h
383  G4double pressure = 1.E-19*pascal;
384  G4double temperature = 0.1*kelvin;
385  new G4Material("Vacuum", /*Z=*/ 1., /*A=*/ 1.01*g/mole,
386  density, kStateGas, temperature, pressure);
387 
388  //There should come the list of materials. #. Defines a comment
389  //*ENDDO defines the block.
390  readName(is,name);
391  while (name != "*ENDDO") {
392  //It should be a material definition
393  matname=name;
394  G4int nElem;
395  G4double dens;
396  is >> nElem >> dens >> jump;
397 
398 #ifdef debug
399  G4cout <<" " << matname
400  << " made of " << nElem
401  << " elements. Density=" << dens
402  << G4endl;
403 #endif
404 
405  G4int absnelem = std::abs(nElem);
406 
407  G4String* mats = new G4String[absnelem];
408  G4double* weights = new G4double[absnelem];
409 
410  G4double prop;
411  for(int i=0; i<absnelem; i++) {
412  readName(is, name);
413  is >> prop >> jump;
414  mats[i]=name;
415  weights[i]=std::abs(prop);
416  } //for...
417  MatDescription md;
418  if (nElem>0 && prop<0)
419  md = byAtomic;
420  else if (nElem>0)
421  md = byWeight;
422  else
423  md = byVolume;
424 
425  addCCalMaterial(matname, dens, absnelem, mats, weights, md);
426  delete[] mats;
427  delete[] weights;
428 
429  readName(is,name);
430  }; //while
431 
432  G4cout << " " << theCCalMaterials.size() << " materials read from "
433  << mixturefile << G4endl << G4endl;
434 }
const XML_Char * name
Definition: expat.h:151
int universe_mean_density
Definition: hepunit.py:307
std::istream & jump(std::istream &)
Definition: CCalutils.cc:95
int G4int
Definition: G4Types.hh:78
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
std::ifstream & readName(std::ifstream &, G4String &)
Definition: CCalutils.cc:53
G4GLOB_DLL std::ostream G4cout
#define pascal
static constexpr double kelvin
Definition: G4SIunits.hh:281
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
static constexpr double mole
Definition: G4SIunits.hh:286

Here is the call graph for this function:


The documentation for this class was generated from the following files: