Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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// Neeed for running with 'static' libraries to pull the references of the
48// declared factories
74
75G4ThreadLocal G4CrossSectionDataSetRegistry* G4CrossSectionDataSetRegistry::instance = nullptr;
76
78{
79 if(!instance) {
81 instance = inst.Instance();
82 }
83 return instance;
84}
85
86G4CrossSectionDataSetRegistry::G4CrossSectionDataSetRegistry()
87{}
88
90{
91 Clean();
92}
93
95{
96 size_t n = xSections.size();
97 for (size_t i=0; i<n; ++i) {
98 G4VCrossSectionDataSet* p = xSections[i];
99 if(p) {
100 //std::cout << "Clean x-section #" << i << std::endl;
101 //std::cout << " " << p->GetName() << std::endl;
102 delete p;
103 xSections[i] = nullptr;
104 }
105 }
106 n = xComponents.size();
107 for (size_t i=0; i<n; ++i) {
108 G4VComponentCrossSection* p = xComponents[i];
109 if(p) {
110 //std::cout << "Clean component #" << i << std::endl;
111 //std::cout << " " << p->GetName() << std::endl;
112 delete p;
113 xComponents[i] = nullptr;
114 }
115 }
116}
117
119{
120 if(!p) { return; }
121 for (auto xsec : xSections) {
122 if(xsec == p) { return; }
123 }
124 //G4cout << "Register x-section #" << xSections.size()
125 //<< " " << p->GetName() << G4endl;
126 xSections.push_back(p);
127}
128
130{
131 if(!p) { return; }
132 size_t n = xSections.size();
133 for (size_t i=0; i<n; ++i) {
134 if(xSections[i] == p) {
135 //std::cout << "DeRegister x-section #" << i << std::endl;
136 //std:: cout << " " << p->GetName() << std::endl;
137 xSections[i] = nullptr;
138 return;
139 }
140 }
141}
142
144{
145 if(!p) { return; }
146 for (auto xsec : xComponents) {
147 if(xsec == p) { return; }
148 }
149 //G4cout << "Register component #" << xComponents.size()
150 //<< " " << p->GetName() << G4endl;
151 xComponents.push_back(p);
152}
153
155{
156 if(!p) { return; }
157 size_t n = xComponents.size();
158 for (size_t i=0; i<n; ++i) {
159 if(xComponents[i] == p) {
160 //std::cout << "DeRegister component #" << i << std::endl;
161 //std::cout << " " << p->GetName() << std::endl;
162 xComponents[i] = nullptr;
163 return;
164 }
165 }
166}
167
168void
170{
171 if(!p) { return; }
172 size_t n = xComponents.size();
173 for (size_t i=0; i<n; ++i) {
174 if(xComponents[i] == p) {
175 //std::cout << "Delete component #" << i << std::endl;
176 //std::cout << " " << p->GetName() << std::endl;
177 delete p;
178 return;
179 }
180 }
181}
182
185 G4bool warning)
186{
187 for (auto xsec : xSections) {
188 if(xsec && xsec->GetName() == name) { return xsec; }
189 }
190 // check if factory exists...
191 //
194 // This throws if factory is not found, add second parameter
195 // to false to avoid this
196 G4VBaseXSFactory* factory = factories->GetFactory(name, warning );
197 if ( factory ) {
198 return factory->Instantiate();
199 } else {
200 G4VCrossSectionDataSet* ptr = nullptr;
201 return ptr;
202 }
203}
204
207{
208 for (auto xsec : xComponents) {
209 if(xsec && xsec->GetName() == name) { return xsec; }
210 }
211 G4VComponentCrossSection* ptr = nullptr;
212 return ptr;
213}
#define G4_REFERENCE_XS_FACTORY(cross_section)
bool G4bool
Definition: G4Types.hh:86
void DeRegister(G4VCrossSectionDataSet *)
G4VCrossSectionDataSet * GetCrossSectionDataSet(const G4String &name, G4bool warning=true)
G4VComponentCrossSection * GetComponentCrossSection(const G4String &name)
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