Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4PhysicsConstructorRegistry.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//
30// GEANT4 Class file
31//
32//
33// File name: G4PhysicsConstructorRegistry
34//
35// Author W. Pokorski 21.09.2012
36//
37// Modifications:
38//
39
40#include "G4ios.hh"
41#include <iomanip>
42
43// force REFERENCE macros _not_ to be expanded here
44// but wherever the class is used (w/ that .hh use)
45#define G4PhysicsConstructorRegistry_cc 1
47
50
51G4ThreadLocal G4PhysicsConstructorRegistry* G4PhysicsConstructorRegistry::theInstance = 0;
52
54{
55 if(0 == theInstance) {
56 static G4ThreadLocal G4PhysicsConstructorRegistry *manager_G4MT_TLS_ = 0 ; if (!manager_G4MT_TLS_) manager_G4MT_TLS_ = new G4PhysicsConstructorRegistry ; G4PhysicsConstructorRegistry &manager = *manager_G4MT_TLS_;
57 theInstance = &manager;
58 }
59 return theInstance;
60}
61
62G4PhysicsConstructorRegistry::G4PhysicsConstructorRegistry()
63{}
64
66{
67 Clean();
68}
69
71{
72 size_t n = physConstr.size();
73 if(n > 0) {
74 for (size_t i=0; i<n; ++i) {
75 if(physConstr[i]) {
76 G4VPhysicsConstructor* p = physConstr[i];
77 physConstr[i] = 0;
78 delete p;
79 }
80 }
81 physConstr.clear();
82 }
83}
84
86{
87 if(!p) return;
88 size_t n = physConstr.size();
89 if(n > 0) {
90 for (size_t i=0; i<n; ++i) {
91 if(physConstr[i] == p) { return; }
92 }
93 }
94 physConstr.push_back(p);
95}
96
98{
99 if ( !p ) return;
100 size_t n = physConstr.size();
101 if ( n > 0 ) {
102 for (size_t i=0; i<n; ++i) {
103 if ( physConstr[i] == p ) {
104 physConstr[i] = 0;
105 return;
106 }
107 }
108 }
109}
110
112{
113 factories[name] = factory;
114}
115
117{
118 // check if factory exists...
119 //
120 if (factories.find(name)!=factories.end())
121 {
122 // we could store the list of called factories in some vector and
123 // before returning we can could first check if this physics constructor was already instantiated
124 // if yes, we can throw an exception saying that this physics can been already registered
125
126 return factories[name]->Instantiate();
127 }
128 else
129 {
131 ED << "The factory for the physics constructor ["<< name << "] does not exist!" << G4endl;
132 G4Exception("G4PhysicsConstructorRegistry::GetPhysicsConstructor", "PhysicsList001", FatalException, ED);
133 return 0;
134 }
135}
136
138{
139 return ( factories.find(name) != factories.end() );
140}
141
142
144{
145 std::vector<G4String> avail;
146 std::map<G4String,G4VBasePhysConstrFactory*>::const_iterator itr;
147 for ( itr = factories.begin(); itr != factories.end(); ++itr ) {
148 avail.push_back(itr->first);
149 }
150
151 return avail;
152}
153
155{
156 std::vector<G4String> avail = AvailablePhysicsConstructors();
157 G4cout << "G4VPhysicsConstructors in G4PhysicsConstructorRegistry are:"
158 << G4endl;
159 if ( avail.empty() ) G4cout << "... no registered processes" << G4endl;
160 else {
161 size_t n = avail.size();
162 for (size_t i=0; i<n; ++i ) {
163 G4cout << " [" << std::setw(3) << i << "] "
164 << " \"" << avail[i] << "\"" << G4endl;
165 }
166 }
167}
168
169//
170// External reference to phy ctor factories for running with 'static'
171// libraries to pull the references of the declared factories into the
172// same compilation unit as the registry itself.
173// No harm having them in the non-static case.
174//
175
176// Ideally we'd do the G4_REFERENCE_PHYSCONSTR_FACTORY() macros
177// here, but this introduces a circular dependence between the
178// ctor_phys_factory library and the other ctor_phys_* libraries
179// when creating granular libraries.
180// Instead we'll make the references in the location(s) where the
181// G4PhysicsConstructorRegistry is _used_ :
182// G4
183/*
184#include "G4RegisterPhysicsConstructors.icc"
185*/
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
bool G4bool
Definition: G4Types.hh:86
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
void DeRegister(G4VPhysicsConstructor *)
void AddFactory(G4String, G4VBasePhysConstrFactory *)
G4VPhysicsConstructor * GetPhysicsConstructor(const G4String &name)
void Register(G4VPhysicsConstructor *)
static G4PhysicsConstructorRegistry * Instance()
std::vector< G4String > AvailablePhysicsConstructors() const
G4bool IsKnownPhysicsConstructor(const G4String &name)
#define G4ThreadLocal
Definition: tls.hh:77