Geant4
9.6.p02
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
geant4_9_6_p02
source
physics_lists
builders
src
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
// $Id:
28
//
29
// -------------------------------------------------------------------
30
//
31
// GEANT4 Class file
32
//
33
//
34
// File name: G4PhysicsConstructorRegistry
35
//
36
// Author W. Pokorski 21.09.2012
37
//
38
// Modifications:
39
//
40
41
#include "
G4ios.hh
"
42
43
#include "
G4PhysicsConstructorRegistry.hh
"
44
#include "
G4VPhysicsConstructor.hh
"
45
#include "
G4PhysicsConstructorFactory.hh
"
46
47
G4PhysicsConstructorRegistry
* G4PhysicsConstructorRegistry::theInstance = 0;
48
49
G4PhysicsConstructorRegistry
*
G4PhysicsConstructorRegistry::Instance
()
50
{
51
if
(0 == theInstance) {
52
static
G4PhysicsConstructorRegistry
manager;
53
theInstance = &manager;
54
}
55
return
theInstance;
56
}
57
58
G4PhysicsConstructorRegistry::G4PhysicsConstructorRegistry()
59
{}
60
61
G4PhysicsConstructorRegistry::~G4PhysicsConstructorRegistry
()
62
{
63
Clean
();
64
}
65
66
void
G4PhysicsConstructorRegistry::Clean
()
67
{
68
size_t
n
= physConstr.size();
69
if
(n > 0) {
70
for
(
size_t
i=0; i<
n
; ++i) {
71
if
(physConstr[i]) {
72
G4VPhysicsConstructor
*
p
= physConstr[i];
73
physConstr[i] = 0;
74
delete
p
;
75
}
76
}
77
physConstr.clear();
78
}
79
}
80
81
void
G4PhysicsConstructorRegistry::Register
(
G4VPhysicsConstructor
*
p
)
82
{
83
if
(!p)
return
;
84
size_t
n
= physConstr.size();
85
if
(n > 0) {
86
for
(
size_t
i=0; i<
n
; ++i) {
87
if
(physConstr[i] == p) {
return
; }
88
}
89
}
90
physConstr.push_back(p);
91
}
92
93
void
G4PhysicsConstructorRegistry::DeRegister
(
G4VPhysicsConstructor
*
p
)
94
{
95
if
(!p)
return
;
96
size_t
n
= physConstr.size();
97
if
(n > 0) {
98
for
(
size_t
i=0; i<
n
; ++i) {
99
if
(physConstr[i] == p) {
100
physConstr[i] = 0;
101
return
;
102
}
103
}
104
}
105
}
106
107
void
G4PhysicsConstructorRegistry::AddFactory
(
G4String
name
,
G4VBasePhysConstrFactory
* factory)
108
{
109
factories[
name
] = factory;
110
}
111
112
G4VPhysicsConstructor
*
G4PhysicsConstructorRegistry::GetPhysicsConstructor
(
const
G4String
&
name
)
113
{
114
// check if factory exists...
115
//
116
if
(factories.find(name)!=factories.end())
117
{
118
// we could store the list of called factories in some vector and
119
// before returning we can could first check if this physics constructor was already instantiated
120
// if yes, we can throw an exception saying that this physics can been already registered
121
122
return
factories[
name
]->Instantiate();
123
}
124
else
125
{
126
G4ExceptionDescription
ED;
127
ED <<
"The factory for the physics constructor ["
<< name <<
"] does not exist!"
<<
G4endl
;
128
G4Exception
(
"G4PhysicsConstructorRegistry::GetPhysicsConstructor"
,
"PhysicsList001"
,
FatalException
, ED);
129
return
0;
130
}
131
}
Generated on Sat May 25 2013 14:33:27 for Geant4 by
1.8.4