Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
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 // $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 #include <iomanip>
43 
44 // force REFERENCE macros _not_ to be expanded here
45 // but wherever the class is used (w/ that .hh use)
46 #define G4PhysicsConstructorRegistry_cc 1
48 
49 #include "G4VPhysicsConstructor.hh"
51 
53 
55 {
56  if(0 == theInstance) {
57  static G4ThreadLocal G4PhysicsConstructorRegistry *manager_G4MT_TLS_ = 0 ; if (!manager_G4MT_TLS_) manager_G4MT_TLS_ = new G4PhysicsConstructorRegistry ; G4PhysicsConstructorRegistry &manager = *manager_G4MT_TLS_;
58  theInstance = &manager;
59  }
60  return theInstance;
61 }
62 
64 {}
65 
67 {
68  Clean();
69 }
70 
72 {
73  size_t n = physConstr.size();
74  if(n > 0) {
75  for (size_t i=0; i<n; ++i) {
76  if(physConstr[i]) {
78  physConstr[i] = 0;
79  delete p;
80  }
81  }
82  physConstr.clear();
83  }
84 }
85 
87 {
88  if(!p) return;
89  size_t n = physConstr.size();
90  if(n > 0) {
91  for (size_t i=0; i<n; ++i) {
92  if(physConstr[i] == p) { return; }
93  }
94  }
95  physConstr.push_back(p);
96 }
97 
99 {
100  if ( !p ) return;
101  size_t n = physConstr.size();
102  if ( n > 0 ) {
103  for (size_t i=0; i<n; ++i) {
104  if ( physConstr[i] == p ) {
105  physConstr[i] = 0;
106  return;
107  }
108  }
109  }
110 }
111 
113 {
114  factories[name] = factory;
115 }
116 
118 {
119  // check if factory exists...
120  //
121  if (factories.find(name)!=factories.end())
122  {
123  // we could store the list of called factories in some vector and
124  // before returning we can could first check if this physics constructor was already instantiated
125  // if yes, we can throw an exception saying that this physics can been already registered
126 
127  return factories[name]->Instantiate();
128  }
129  else
130  {
132  ED << "The factory for the physics constructor ["<< name << "] does not exist!" << G4endl;
133  G4Exception("G4PhysicsConstructorRegistry::GetPhysicsConstructor", "PhysicsList001", FatalException, ED);
134  return 0;
135  }
136 }
137 
139 {
140  return ( factories.find(name) != factories.end() );
141 }
142 
143 
145 {
146  std::vector<G4String> avail;
147  std::map<G4String,G4VBasePhysConstrFactory*>::const_iterator itr;
148  for ( itr = factories.begin(); itr != factories.end(); ++itr ) {
149  avail.push_back(itr->first);
150  }
151 
152  return avail;
153 }
154 
156 {
157  std::vector<G4String> avail = AvailablePhysicsConstructors();
158  G4cout << "G4VPhysicsConstructors in G4PhysicsConstructorRegistry are:"
159  << G4endl;
160  if ( avail.empty() ) G4cout << "... no registered processes" << G4endl;
161  else {
162  size_t n = avail.size();
163  for (size_t i=0; i<n; ++i ) {
164  G4cout << " [" << std::setw(3) << i << "] "
165  << " \"" << avail[i] << "\"" << G4endl;
166  }
167  }
168 }
169 
170 //
171 // External reference to phy ctor factories for running with 'static'
172 // libraries to pull the references of the declared factories into the
173 // same compilation unit as the registry itself.
174 // No harm having them in the non-static case.
175 //
176 
177 // Ideally we'd do the G4_REFERENCE_PHYSCONSTR_FACTORY() macros
178 // here, but this introduces a circular dependence between the
179 // ctor_phys_factory library and the other ctor_phys_* libraries
180 // when creating granular libraries.
181 // Instead we'll make the references in the location(s) where the
182 // G4PhysicsConstructorRegistry is _used_ :
183 // G4
184 /*
185 #include "G4RegisterPhysicsConstructors.icc"
186 */
const XML_Char * name
Definition: expat.h:151
std::vector< G4VPhysicsConstructor * > physConstr
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
void Register(G4VPhysicsConstructor *)
#define G4endl
Definition: G4ios.hh:61
void AddFactory(G4String, G4VBasePhysConstrFactory *)
const char * p
Definition: xmltok.h:285
G4VPhysicsConstructor * GetPhysicsConstructor(const G4String &name)
std::map< G4String, G4VBasePhysConstrFactory * > factories
static G4PhysicsConstructorRegistry * Instance()
#define G4ThreadLocal
Definition: tls.hh:69
std::vector< G4String > AvailablePhysicsConstructors() const
static G4ThreadLocal G4PhysicsConstructorRegistry * theInstance
bool G4bool
Definition: G4Types.hh:79
void DeRegister(G4VPhysicsConstructor *)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
G4GLOB_DLL std::ostream G4cout
Char_t n[5]
G4bool IsKnownPhysicsConstructor(const G4String &name)