Geant4 11.3.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4CrossSectionDataSetRegistry.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//
32// File name: G4CrossSectionDataSetRegistry
33//
34// Author V.Ivanchenko 24.01.2009
35//
36// Modifications:
37//
38
39#include "G4ios.hh"
40
46
47// Needed for running with 'static' libraries to pull the references of the
48// declared factories
68
69G4ThreadLocal G4CrossSectionDataSetRegistry* G4CrossSectionDataSetRegistry::instance = nullptr;
70
72{
73 if(nullptr == instance) {
75 instance = inst.Instance();
76 }
77 return instance;
78}
79
81{}
82
87
89{
90 std::size_t n = xSections.size();
91 for (std::size_t i=0; i<n; ++i) {
92 G4VCrossSectionDataSet* p = xSections[i];
93 if(nullptr != p) {
94 delete p;
95 xSections[i] = nullptr;
96 }
97 }
98 n = xComponents.size();
99 for (std::size_t i=0; i<n; ++i) {
100 auto p = xComponents[i];
101 if(nullptr != p) {
102 delete p;
103 xComponents[i] = nullptr;
104 }
105 }
106}
107
109{
110 if(nullptr == p) { return; }
111 for (auto & xsec : xSections) {
112 if(xsec == p) { return; }
113 }
114 xSections.push_back(p);
115}
116
118{
119 if(nullptr == p) { return; }
120 std::size_t n = xSections.size();
121 for (std::size_t i=0; i<n; ++i) {
122 if(xSections[i] == p) {
123 xSections[i] = nullptr;
124 return;
125 }
126 }
127}
128
130{
131 if(nullptr == p) { return; }
132 for (auto & xsec : xComponents) {
133 if(xsec == p) { return; }
134 }
135 xComponents.push_back(p);
136}
137
139{
140 if(nullptr == p) { return; }
141 std::size_t n = xComponents.size();
142 for (std::size_t i=0; i<n; ++i) {
143 if(xComponents[i] == p) {
144 xComponents[i] = nullptr;
145 return;
146 }
147 }
148}
149
150void
152{
153 if(nullptr == p) { return; }
154 std::size_t n = xComponents.size();
155 for (std::size_t i=0; i<n; ++i) {
156 if(xComponents[i] == p) {
157 delete p;
158 return;
159 }
160 }
161}
162
165 G4bool warning)
166{
167 for (auto & xsec : xSections) {
168 if(nullptr != xsec && xsec->GetName() == name) { return xsec; }
169 }
170 // check if factory exists...
171 //
174 // This throws if factory is not found, add second parameter
175 // to false to avoid this
176 G4VBaseXSFactory* factory = factories->GetFactory(name, warning );
177 if ( factory ) {
178 return factory->Instantiate();
179 } else {
180 G4VCrossSectionDataSet* ptr = nullptr;
181 return ptr;
182 }
183}
184
187{
188 for (auto & xsec : xComponents) {
189 if(nullptr != xsec && xsec->GetName() == name) { return xsec; }
190 }
191 G4VComponentCrossSection* ptr = nullptr;
192 return ptr;
193}
#define G4_REFERENCE_XS_FACTORY(cross_section)
bool G4bool
Definition G4Types.hh:86
void DeRegister(G4VCrossSectionDataSet *)
G4VCrossSectionDataSet * GetCrossSectionDataSet(const G4String &name, G4bool warning=false)
G4VComponentCrossSection * GetComponentCrossSection(const G4String &name)
G4CrossSectionDataSetRegistry(G4CrossSectionDataSetRegistry &)=delete
void Register(G4VCrossSectionDataSet *)
static G4CrossSectionDataSetRegistry * Instance()
void DeleteComponent(G4VComponentCrossSection *)
static G4CrossSectionFactoryRegistry * Instance()
G4VBaseXSFactory * GetFactory(const G4String &name, G4bool abortIfNotFound=true) const
virtual G4VCrossSectionDataSet * Instantiate()=0
#define G4ThreadLocal
Definition tls.hh:77