Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4EmDataHandler.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// GEANT4 Class file
30//
31// File name: G4EmDataHandler
32//
33// Author: V. Ivanchenko
34//
35// Creation date: 16 August 2017
36//
37// Modifications:
38//
39// -------------------------------------------------------------------
40//
41//
42
43#include "G4EmDataHandler.hh"
44#include "G4EmDataRegistry.hh"
46#include "G4EmParameters.hh"
48
49//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50
52 : tLength(n), fName(nam)
53{
54 data.resize(n, nullptr);
55 fMaxXS = new std::vector<G4double>;
56 fXSpeaks = new std::vector<G4TwoPeaksXS*>;
57 fRegistry = G4EmDataRegistry::Instance();
58 fRegistry->Register(this);
59}
60
61//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
62
64{
65 if (!fUseBaseParticleTable && 0 < tLength) {
66 for (std::size_t i=0; i<tLength; ++i) {
67 CleanTable(i);
68 }
69 data.clear();
70 tLength = 0;
71 delete fMaxXS;
72 fMaxXS = nullptr;
73 delete fXSpeaks;
74 fXSpeaks = nullptr;
75 }
76 if (!fElemSelectors.empty()) {
77 for (auto const & ptr : fElemSelectors) {
78 if (nullptr != ptr) {
79 for (auto const & p : *ptr) { delete p; }
80 ptr->clear();
81 delete ptr;
82 }
83 }
84 fElemSelectors.clear();
85 }
86 fRegistry->DeRegister(this);
87}
88
89//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
90
92{
93 // update table pointer but not delete previous
94 if (idx < tLength) {
95 data[idx] = ptr;
96 } else {
97 G4cout << "### G4EmDataHandler::UpdateTable fail for idx=" << idx
98 << " length=" << tLength << G4endl;
99 }
100}
101
102//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
103
105{
106 if (idx >= tLength) {
107 for (std::size_t j=tLength; j<=idx; ++j) {
108 data.push_back(nullptr);
109 }
110 tLength = idx + 1;
111 }
112 data[idx] = G4PhysicsTableHelper::PreparePhysicsTable(data[idx]);
113 return data[idx];
114}
115
116//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
117
119{
120 if (idx >= tLength) {
121 for (std::size_t j=tLength; j<=idx; ++j) {
122 data.push_back(nullptr);
123 }
124 tLength = idx + 1;
125 }
127
128 return data[idx];
129}
130
131//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
132
134{
135 if (i < tLength && nullptr != data[i]) {
136 auto ptr = data[i];
137 ptr->clearAndDestroy();
138 for (std::size_t j=0; j<tLength; ++j) {
139 if (ptr == data[j]) { data[j] = nullptr; }
140 }
141 delete ptr;
142 }
143}
144
145//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
146
148 const G4ParticleDefinition* part,
149 const G4String& fname,
150 G4bool ascii)
151{
152 G4bool yes = true;
153 if(nullptr != data[idx]) {
154 yes = data[idx]->StorePhysicsTable(fname, ascii);
155
156 if ( yes ) {
157 G4cout << "### Physics table is stored for "
158 << part->GetParticleName()
159 << " <" << fname << "> " << G4endl;
160 } else {
161 G4cout << "### Fail to store Physics Table for "
162 << part->GetParticleName()
163 << " <" << fname << "> " << G4endl;
164 }
165 }
166 return yes;
167}
168
169//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
170
172 const G4ParticleDefinition* part,
173 const G4String& fname,
174 G4bool ascii, G4bool spline)
175{
176 G4PhysicsTable* table = Table(idx);
177 G4bool yes = G4PhysicsTableHelper::RetrievePhysicsTable(table, fname, ascii, spline);
179 if ( yes ) {
180 if (0 < param->Verbose()) {
181 G4cout << "### Physics table " << idx << " for "
182 << part->GetParticleName()
183 << " is retrieved from <" << fname << ">"
184 << G4endl;
185 }
186 } else if (1 < param->Verbose()) {
187 G4cout << "### Fail to retrieve physics table " << idx << " for "
188 << part->GetParticleName() << " from <"
189 << fname << ">" << G4endl;
190 }
191 return yes;
192}
193
194//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
195
197{
198 masterProcess.push_back(ptr);
199}
200
201//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
202
204{
205 return (idx < masterProcess.size()) ? masterProcess[idx] : nullptr;
206}
207
208//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
209
210void G4EmDataHandler::SetElementSelectors(std::vector<G4EmElementSelector*>* p,
211 std::size_t i)
212{
213 if (i < eLength) {
214 if (fElemSelectors[i] != p) {
215 delete fElemSelectors[i];
216 }
217 fElemSelectors[i] = p;
218 } else {
219 fElemSelectors.push_back(p);
220 ++eLength;
221 }
222}
223
224//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
bool G4bool
Definition G4Types.hh:86
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
void SetMasterProcess(const G4VEmProcess *)
void SetElementSelectors(std::vector< G4EmElementSelector * > *, std::size_t)
G4PhysicsTable * Table(std::size_t idx) const
const G4VEmProcess * GetMasterProcess(size_t idx) const
G4EmDataHandler(std::size_t nTable, const G4String &nam="")
G4bool RetrievePhysicsTable(std::size_t idx, const G4ParticleDefinition *part, const G4String &fname, G4bool ascii, G4bool spline)
G4bool StorePhysicsTable(std::size_t idx, const G4ParticleDefinition *part, const G4String &fname, G4bool ascii)
void UpdateTable(G4PhysicsTable *, std::size_t idx)
void CleanTable(std::size_t idx)
G4PhysicsTable * MakeTable(std::size_t idx)
static G4EmDataRegistry * Instance()
static G4EmParameters * Instance()
G4int Verbose() const
const G4String & GetParticleName() const
static G4PhysicsTable * PreparePhysicsTable(G4PhysicsTable *physTable)
static G4bool RetrievePhysicsTable(G4PhysicsTable *physTable, const G4String &fileName, G4bool ascii, G4bool spline)