Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
nutools
old
G4NuPhysicsLists
src
G4PhysicsProcessFactorySingleton.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
// $Id: G4PhysicsProcessFactorySingleton.cc,v 1.2 2012-09-20 21:43:53 greenc Exp $
27
// GEANT4 tag $Name: not supported by cvs2svn $
28
//
29
//---------------------------------------------------------------------------
30
//
31
// ClassName: G4PhysicsProcessFactorySingleton
32
//
33
// Author: 2012-02-02 R. Hatcher
34
//
35
// Modified:
36
//
37
//----------------------------------------------------------------------------
38
//
39
40
#include "
G4NuPhysicsLists/G4PhysicsProcessFactorySingleton.hh
"
41
42
#include <iomanip>
43
44
namespace
g4nu
{
45
46
// Define static variable which holds the one-and-only instance
47
G4PhysicsProcessFactorySingleton
*
G4PhysicsProcessFactorySingleton::fgTheInstance
;
48
49
G4PhysicsProcessFactorySingleton::G4PhysicsProcessFactorySingleton
()
50
{
51
fgTheInstance
=
this
;
// record created self in static pointer
52
}
53
54
G4PhysicsProcessFactorySingleton::~G4PhysicsProcessFactorySingleton
()
55
{
56
fgTheInstance
= 0;
57
}
58
59
G4PhysicsProcessFactorySingleton
&
G4PhysicsProcessFactorySingleton::Instance
()
60
{
61
// Cleaner dtor calls G4PhysicsProcessFactorySingleton dtor at job end
62
static
Cleaner
cleaner;
63
64
if
( !
fgTheInstance
) {
65
// need to create one
66
cleaner.
UseMe
();
// dummy call to quiet compiler warnings
67
fgTheInstance
=
new
G4PhysicsProcessFactorySingleton
();
68
}
69
70
return
*
fgTheInstance
;
71
}
72
73
G4VPhysicsConstructor*
74
G4PhysicsProcessFactorySingleton::GetPhysicsProcess
(
const
G4String&
name
)
75
{
76
G4VPhysicsConstructor*
p
= 0;
77
78
// we don't want map creating an entry if it doesn't exist
79
// so use map::find() not map::operator[]
80
std::map<G4String, PhysProcCtorFuncPtr_t>::iterator
itr
81
=
fFunctionMap
.find(name);
82
if
(
fFunctionMap
.end() != itr ) {
83
// found an appropriate entry in the list
84
PhysProcCtorFuncPtr_t
foo = itr->second;
// this is the function
85
p = (*foo)();
// use function to create the physics process
86
}
87
if
( ! p ) {
88
G4cout <<
"### G4PhysicsProcessFactorySingleton WARNING: "
89
<<
"PhysicsProcess "
<< name <<
" is not known"
90
<< G4endl;
91
}
92
return
p
;
93
}
94
95
G4bool
G4PhysicsProcessFactorySingleton::IsKnownPhysicsProcess
(
const
G4String&
name
)
96
{
97
// check if we know the name
98
G4bool res =
false
;
99
std::map<G4String, PhysProcCtorFuncPtr_t>::iterator
itr
100
=
fFunctionMap
.find(name);
101
if
(
fFunctionMap
.end() != itr ) res =
true
;
102
return
res;
103
}
104
105
const
std::vector<G4String>&
106
G4PhysicsProcessFactorySingleton::AvailablePhysicsProcesses
()
const
107
{
108
// list of names might be out of date due to new registrations
109
// rescan the std::map on each call (which won't be frequent)
110
listnames
.clear();
111
112
// scan map for registered names
113
std::map<G4String, PhysProcCtorFuncPtr_t>::const_iterator
itr;
114
for
( itr =
fFunctionMap
.begin(); itr !=
fFunctionMap
.end(); ++itr )
115
listnames
.push_back(itr->first);
116
117
return
listnames
;
118
}
119
120
void
G4PhysicsProcessFactorySingleton::PrintAvailablePhysicsProcesses
()
const
121
{
122
std::vector<G4String> list =
AvailablePhysicsProcesses
();
123
G4cout <<
"G4VPhysicsConstructors in "
124
<<
"G4PhysicsProcessFactorySingleton are: "
125
<< G4endl;
126
if
( list.empty() ) G4cout <<
" ... no registered processes"
<< G4endl;
127
else
{
128
for
(
size_t
indx=0; indx < list.size(); ++indx ) {
129
G4cout <<
" ["
<<
std::setw
(2) << indx <<
"] "
130
<<
"\""
<< list[indx] <<
"\""
<< G4endl;
131
}
132
}
133
134
}
135
136
G4bool
G4PhysicsProcessFactorySingleton::RegisterCreator
(G4String
name
,
137
PhysProcCtorFuncPtr_t
foo,
138
G4bool* boolptr)
139
{
140
// record new functions for creating processes
141
fFunctionMap
[
name
] = foo;
142
fBoolPtrMap
[
name
] = boolptr;
143
return
true
;
144
}
145
146
}
// end-of-namespace g4nu
147
148
/// !!!!!! register existing classes without disturbing their .cc files (yet)
149
//#include "G4PhysProcRegisterOld.icc"
name
static QCString name
Definition:
declinfo.cpp:673
iterator
intermediate_table::iterator iterator
Definition:
intermediate_table.cc:24
g4nu::G4PhysicsProcessFactorySingleton::PrintAvailablePhysicsProcesses
void PrintAvailablePhysicsProcesses() const
Definition:
G4PhysicsProcessFactorySingleton.cc:120
g4nu::G4PhysicsProcessFactorySingleton::~G4PhysicsProcessFactorySingleton
virtual ~G4PhysicsProcessFactorySingleton()
Definition:
G4PhysicsProcessFactorySingleton.cc:54
g4nu::G4PhysicsProcessFactorySingleton::RegisterCreator
G4bool RegisterCreator(G4String name, PhysProcCtorFuncPtr_t ctorptr, G4bool *ptr)
Definition:
G4PhysicsProcessFactorySingleton.cc:136
const_iterator
intermediate_table::const_iterator const_iterator
Definition:
intermediate_table.cc:25
g4nu::G4PhysicsProcessFactorySingleton::Cleaner
Definition:
G4PhysicsProcessFactorySingleton.hh:108
g4nu::G4PhysicsProcessFactorySingleton::AvailablePhysicsProcesses
const std::vector< G4String > & AvailablePhysicsProcesses() const
Definition:
G4PhysicsProcessFactorySingleton.cc:106
G4PhysicsProcessFactorySingleton
Definition:
G4PhysicsProcessFactorySingleton.hh:57
g4nu::G4PhysicsProcessFactorySingleton::fgTheInstance
static G4PhysicsProcessFactorySingleton * fgTheInstance
Definition:
G4PhysicsProcessFactorySingleton.hh:81
g4nu
Definition:
G4PhysicsProcessFactorySingleton.hh:57
G4PhysicsProcessFactorySingleton.hh
g4nu::G4PhysicsProcessFactorySingleton::G4PhysicsProcessFactorySingleton
G4PhysicsProcessFactorySingleton()
Definition:
G4PhysicsProcessFactorySingleton.cc:49
g4nu::G4PhysicsProcessFactorySingleton::IsKnownPhysicsProcess
G4bool IsKnownPhysicsProcess(const G4String &)
Definition:
G4PhysicsProcessFactorySingleton.cc:95
g4nu::G4PhysicsProcessFactorySingleton
Definition:
G4PhysicsProcessFactorySingleton.hh:59
g4nu::G4PhysicsProcessFactorySingleton::Cleaner::UseMe
void UseMe()
Definition:
G4PhysicsProcessFactorySingleton.hh:109
g4nu::G4PhysicsProcessFactorySingleton::listnames
std::vector< G4String > listnames
Definition:
G4PhysicsProcessFactorySingleton.hh:89
setw
Q_EXPORT QTSManip setw(int w)
Definition:
qtextstream.h:331
test.p
p
Definition:
test.py:223
g4nu::G4PhysicsProcessFactorySingleton::Instance
static G4PhysicsProcessFactorySingleton & Instance()
Definition:
G4PhysicsProcessFactorySingleton.cc:59
g4nu::G4PhysicsProcessFactorySingleton::fBoolPtrMap
std::map< G4String, G4bool * > fBoolPtrMap
Definition:
G4PhysicsProcessFactorySingleton.hh:87
g4nu::G4PhysicsProcessFactorySingleton::fFunctionMap
std::map< G4String, PhysProcCtorFuncPtr_t > fFunctionMap
Definition:
G4PhysicsProcessFactorySingleton.hh:84
PhysProcCtorFuncPtr_t
G4VPhysicsConstructor *(* PhysProcCtorFuncPtr_t)()
Definition:
G4PhysicsProcessFactorySingleton.hh:55
g4nu::G4PhysicsProcessFactorySingleton::GetPhysicsProcess
G4VPhysicsConstructor * GetPhysicsProcess(const G4String &)
Definition:
G4PhysicsProcessFactorySingleton.cc:74
Generated by
1.8.11