Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ElementData.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// GEANT4 Class file
29//
30// Description: Data structure for cross sections, shell cross sections
31// isotope cross sections
32//
33// Author: V.Ivanchenko 10.03.2011
34//
35// Modifications:
36//
37//----------------------------------------------------------------------------
38
39#include "G4ElementData.hh"
42
44 : maxNumElm(length)
45{
46 elmData.resize((std::size_t)maxNumElm, nullptr);
48 fRegistry->RegisterMe(this);
49}
50
52{
53 for (auto const & p : elmData) { delete p; }
54 elmData.clear();
55
56 for (auto const & p : elm2Data) {
57 delete p;
58 }
59 elm2Data.clear();
60
61 for (auto const & p : compData) {
62 if (nullptr != p ) {
63 for (auto const & q : *p) { delete q.second; }
64 delete p;
65 }
66 }
67 compData.clear();
68
69 for (auto const & p : comp2D) {
70 if (nullptr != p ) {
71 for (auto const & q : *p) { delete q.second; }
72 delete p;
73 }
74 }
75 comp2D.clear();
76 fRegistry->RemoveMe(this);
77}
78
79void G4ElementData::Reserve1D(std::size_t n)
80{
81 if (!elmData.empty()) { return; }
82 elmData.reserve(n);
83 compData.reserve(n);
84}
85
86void G4ElementData::Reserve2D(std::size_t n)
87{
88 if (!elm2Data.empty()) { return; }
89 elm2Data.reserve(n);
90 comp2D.reserve(n);
91}
92
94{
95 if (Z < 0 || Z >= maxNumElm) {
96 DataError(Z, "InitialiseForElement");
97 return;
98 }
99 delete elmData[Z];
100 elmData[Z] = v;
101}
102
104{
105 if (Z < 0 || Z >= maxNumElm) {
106 DataError(Z, "InitialiseFor2DElement");
107 return;
108 }
109 if (elm2Data.empty()) {
110 elm2Data.resize((std::size_t)maxNumElm, nullptr);
111 }
112 delete elm2Data[Z];
113 elm2Data[Z] = v;
114}
115
117{
118 if (Z < 0 || Z >= maxNumElm) {
119 DataError(Z, "InitialiseForComponent");
120 return;
121 }
122 if (compData.empty()) {
123 compData.resize((std::size_t)maxNumElm, nullptr);
124 }
125 delete compData[Z];
126 compData[Z] = new std::vector<std::pair<G4int, G4PhysicsVector*> >;
127 if (0 < nComponents) { compData[Z]->reserve((std::size_t)nComponents); }
128}
129
131{
132 if (Z < 0 || Z >= maxNumElm) {
133 DataError(Z, "InitialiseFor2DComponent");
134 return;
135 }
136 if (comp2D.empty()) {
137 comp2D.resize((std::size_t)maxNumElm, nullptr);
138 }
139 delete comp2D[Z];
140 comp2D[Z] = new std::vector<std::pair<G4int, G4Physics2DVector*> >;
141 if (0 < nComponents) { comp2D[Z]->reserve((std::size_t)nComponents); }
142}
143
145{
146 if (Z < 0 || Z >= maxNumElm) {
147 DataError(Z, "AddComponent");
148 return;
149 }
150 if (compData.empty()) {
151 compData.resize((std::size_t)maxNumElm, nullptr);
152 }
153 if (nullptr == compData[Z]) {
154 compData[Z] = new std::vector<std::pair<G4int, G4PhysicsVector*> >;
155 }
156 compData[Z]->emplace_back(id, v);
157}
158
160{
161 if (Z < 0 || Z >= maxNumElm) {
162 DataError(Z, "Add2DComponent");
163 return;
164 }
165 if (comp2D.empty()) {
166 compData.resize((std::size_t)maxNumElm, nullptr);
167 }
168 if (nullptr == comp2D[Z]) {
169 comp2D[Z] = new std::vector<std::pair<G4int, G4Physics2DVector*> >;
170 }
171 comp2D[Z]->emplace_back(id, v);
172}
173
175{
176 auto ptr = new G4PhysicsFreeVector(ne);
177 InitialiseForElement(iz, ptr);
178 return ptr;
179}
180
182{
183 auto ptr = new G4Physics2DVector(ny, ne);
184 InitialiseForElement(iz, ptr);
185 return ptr;
186}
187
188void G4ElementData::DataError(G4int Z, const G4String& type)
189{
190 G4cout << "G4ElementData::" << type << " ERROR for G4ElementData <"
191 << name << "> Z = " << Z << " is out of range!" << G4endl;
192 G4Exception("G4ElementData", "mat603", FatalException, "Wrong data handling");
193}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
static G4ElementDataRegistry * Instance()
void InitialiseFor2DComponent(G4int Z, G4int nComponents=0)
void Reserve2D(std::size_t)
void Reserve1D(std::size_t)
void Add2DComponent(G4int Z, G4int id, G4Physics2DVector *v)
void InitialiseForComponent(G4int Z, G4int nComponents=0)
void InitialiseForElement(G4int Z, G4PhysicsVector *v)
G4ElementData(G4int length=99)
void AddComponent(G4int Z, G4int id, G4PhysicsVector *v)
G4Physics2DVector * New2DVector(G4int Z, G4int ny, G4int ne)
G4PhysicsVector * New1DVector(G4int Z, G4int ne)