Geant4 11.2.2
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// 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
80G4CrossSectionDataSetRegistry::G4CrossSectionDataSetRegistry()
81{}
82
87
89{
90 size_t n = xSections.size();
91 for (size_t i=0; i<n; ++i) {
92 G4VCrossSectionDataSet* p = xSections[i];
93 if(p) {
94 //std::cout << "Clean x-section #" << i << std::endl;
95 //std::cout << " " << p->GetName() << std::endl;
96 delete p;
97 xSections[i] = nullptr;
98 }
99 }
100 n = xComponents.size();
101 for (size_t i=0; i<n; ++i) {
102 G4VComponentCrossSection* p = xComponents[i];
103 if(p) {
104 //std::cout << "Clean component #" << i << std::endl;
105 //std::cout << " " << p->GetName() << std::endl;
106 delete p;
107 xComponents[i] = nullptr;
108 }
109 }
110}
111
113{
114 if(nullptr == p) { return; }
115 for (auto xsec : xSections) {
116 if(xsec == p) { return; }
117 }
118 //G4cout << "Register x-section #" << xSections.size()
119 // << " " << p->GetName() << " " << p << G4endl;
120 xSections.push_back(p);
121}
122
124{
125 if(nullptr == p) { return; }
126 size_t n = xSections.size();
127 for (size_t i=0; i<n; ++i) {
128 if(xSections[i] == p) {
129 //std::cout << "DeRegister x-section #" << i
130 // << " " << p->GetName() << " " << p << std::endl;
131 xSections[i] = nullptr;
132 return;
133 }
134 }
135}
136
138{
139 if(!p) { return; }
140 for (auto xsec : xComponents) {
141 if(xsec == p) { return; }
142 }
143 //G4cout << "Register component #" << xComponents.size()
144 //<< " " << p->GetName() << G4endl;
145 xComponents.push_back(p);
146}
147
149{
150 if(!p) { return; }
151 size_t n = xComponents.size();
152 for (size_t i=0; i<n; ++i) {
153 if(xComponents[i] == p) {
154 //std::cout << "DeRegister component #" << i << std::endl;
155 //std::cout << " " << p->GetName() << std::endl;
156 xComponents[i] = nullptr;
157 return;
158 }
159 }
160}
161
162void
164{
165 if(!p) { return; }
166 size_t n = xComponents.size();
167 for (size_t i=0; i<n; ++i) {
168 if(xComponents[i] == p) {
169 //std::cout << "Delete component #" << i << std::endl;
170 //std::cout << " " << p->GetName() << std::endl;
171 delete p;
172 return;
173 }
174 }
175}
176
179 G4bool warning)
180{
181 for (auto xsec : xSections) {
182 if(xsec && xsec->GetName() == name) { return xsec; }
183 }
184 // check if factory exists...
185 //
188 // This throws if factory is not found, add second parameter
189 // to false to avoid this
190 G4VBaseXSFactory* factory = factories->GetFactory(name, warning );
191 if ( factory ) {
192 return factory->Instantiate();
193 } else {
194 G4VCrossSectionDataSet* ptr = nullptr;
195 return ptr;
196 }
197}
198
201{
202 for (auto xsec : xComponents) {
203 if(xsec && xsec->GetName() == name) { return xsec; }
204 }
205 G4VComponentCrossSection* ptr = nullptr;
206 return ptr;
207}
#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)
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