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