Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G3EleTable.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//
28
29#include <sstream>
30
31#include "G3EleTable.hh"
32
33#include "G4Types.hh"
35#include "G4SystemOfUnits.hh"
36#include "G4ios.hh"
37
39{
40 // create an array of pointers to elements
41 _Ele = new G4Element*[_MaxEle];
42 LoadUp();
43}
44
46{
47 delete [] _Ele;
48}
49
52{
53 G4double A = 0.;
54 char name[20], sym[3];
55 G4int index = (G4int) Z-1;
56 if (!parse(Z, name, sym, A))
57 {
58 G4String na(name);
59 G4String sy(sym);
60 if (_Ele[index] == nullptr)
61 {
62 if ( A == 0. )
63 {
64 // Cannot create element with A = 0.
65 G4String text = "Failed to get element Z = " + std::to_string(Z);
66 G4Exception("G3EleTable::GetEle", "G3toG40016", FatalException, text);
67 }
68 // add an element to the element table here
69 _Ele[index] = new G4Element(na, sy, Z, A*g/mole);
70 }
71 }
72 return _Ele[index];
73}
74
75G4int
76G3EleTable::parse(G4double& Z, char* name, char* sym, G4double& A)
77{
78 G4int rc = 0;
79 if (Z>0 && Z <=_MaxEle)
80 {
81 G4int z = (G4int) Z-1;
82 G4String str(_EleNames[z]);
83 char* cstr = new char [str.length()+1];
84 std::strcpy(cstr, str.c_str());
85 char* p = std::strtok(cstr," ");
86 std::strcpy(name, p);
87 p = std::strtok(NULL," ");
88 std::strcpy(sym, p);
89 p = std::strtok(NULL," ");
90 std::istringstream in(p);
91 in >> A;
92 delete [] cstr;
93 }
94 else
95 {
96 rc = -1;
97 }
98 return rc;
99}
100
101void
102G3EleTable::LoadUp()
103{
104 // initialize element pointers to 0
105 for (G4int j=0; j<_MaxEle; ++j)
106 {
107 _Ele[j]=nullptr;
108 }
109}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
const G4int Z[17]
const G4double A[17]
virtual ~G3EleTable()
Definition: G3EleTable.cc:45
G4Element * GetEle(G4double Z)
Definition: G3EleTable.cc:51