ECCE @ EIC Software
Reference for
ECCE @ EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
G4PhysicsConstructorRegistry.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file G4PhysicsConstructorRegistry.cc
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
46
#include "
G4PhysicsConstructorRegistry.hh
"
47
48
#include "
G4VPhysicsConstructor.hh
"
49
#include "
G4PhysicsConstructorFactory.hh
"
50
51
G4ThreadLocal
G4PhysicsConstructorRegistry
*
G4PhysicsConstructorRegistry::theInstance
= 0;
52
53
G4PhysicsConstructorRegistry
*
G4PhysicsConstructorRegistry::Instance
()
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
62
G4PhysicsConstructorRegistry::G4PhysicsConstructorRegistry
()
63
{}
64
65
G4PhysicsConstructorRegistry::~G4PhysicsConstructorRegistry
()
66
{
67
Clean
();
68
}
69
70
void
G4PhysicsConstructorRegistry::Clean
()
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
85
void
G4PhysicsConstructorRegistry::Register
(
G4VPhysicsConstructor
*
p
)
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
97
void
G4PhysicsConstructorRegistry::DeRegister
(
G4VPhysicsConstructor
*
p
)
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
111
void
G4PhysicsConstructorRegistry::AddFactory
(
G4String
name
,
G4VBasePhysConstrFactory
* factory)
112
{
113
factories
[
name
] = factory;
114
}
115
116
G4VPhysicsConstructor
*
G4PhysicsConstructorRegistry::GetPhysicsConstructor
(
const
G4String
&
name
)
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
{
130
G4ExceptionDescription
ED;
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
137
G4bool
G4PhysicsConstructorRegistry::IsKnownPhysicsConstructor
(
const
G4String
&
name
)
138
{
139
return
(
factories
.find(name) !=
factories
.end() );
140
}
141
142
143
std::vector<G4String>
G4PhysicsConstructorRegistry::AvailablePhysicsConstructors
()
const
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
154
void
G4PhysicsConstructorRegistry::PrintAvailablePhysicsConstructors
()
const
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
*/
geant4
tree
geant4-10.6-release
source
physics_lists
constructors
factory
src
G4PhysicsConstructorRegistry.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:25:27
using
1.8.2 with
ECCE GitHub integration