Geant4  10.02.p02
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 #include <iomanip>
43 
45 #include "G4VPhysicsConstructor.hh"
47 
49 
51 {
52  if(0 == theInstance) {
53  static G4ThreadLocal G4PhysicsConstructorRegistry *manager_G4MT_TLS_ = 0 ; if (!manager_G4MT_TLS_) manager_G4MT_TLS_ = new G4PhysicsConstructorRegistry ; G4PhysicsConstructorRegistry &manager = *manager_G4MT_TLS_;
54  theInstance = &manager;
55  }
56  return theInstance;
57 }
58 
60 {}
61 
63 {
64  Clean();
65 }
66 
68 {
69  size_t n = physConstr.size();
70  if(n > 0) {
71  for (size_t i=0; i<n; ++i) {
72  if(physConstr[i]) {
74  physConstr[i] = 0;
75  delete p;
76  }
77  }
78  physConstr.clear();
79  }
80 }
81 
83 {
84  if(!p) return;
85  size_t n = physConstr.size();
86  if(n > 0) {
87  for (size_t i=0; i<n; ++i) {
88  if(physConstr[i] == p) { return; }
89  }
90  }
91  physConstr.push_back(p);
92 }
93 
95 {
96  if ( !p ) return;
97  size_t n = physConstr.size();
98  if ( n > 0 ) {
99  for (size_t i=0; i<n; ++i) {
100  if ( physConstr[i] == p ) {
101  physConstr[i] = 0;
102  return;
103  }
104  }
105  }
106 }
107 
109 {
110  factories[name] = factory;
111 }
112 
114 {
115  // check if factory exists...
116  //
117  if (factories.find(name)!=factories.end())
118  {
119  // we could store the list of called factories in some vector and
120  // before returning we can could first check if this physics constructor was already instantiated
121  // if yes, we can throw an exception saying that this physics can been already registered
122 
123  return factories[name]->Instantiate();
124  }
125  else
126  {
128  ED << "The factory for the physics constructor ["<< name << "] does not exist!" << G4endl;
129  G4Exception("G4PhysicsConstructorRegistry::GetPhysicsConstructor", "PhysicsList001", FatalException, ED);
130  return 0;
131  }
132 }
133 
135 {
136  return ( factories.find(name) != factories.end() );
137 }
138 
139 
141 {
142  std::vector<G4String> avail;
143  std::map<G4String,G4VBasePhysConstrFactory*>::const_iterator itr;
144  for ( itr = factories.begin(); itr != factories.end(); ++itr ) {
145  avail.push_back(itr->first);
146  }
147 
148  return avail;
149 }
150 
152 {
153  std::vector<G4String> avail = AvailablePhysicsConstructors();
154  G4cout << "G4VPhysicsConstructors in G4PhysicsConstructorRegistry are:"
155  << G4endl;
156  if ( avail.empty() ) G4cout << "... no registered processes" << G4endl;
157  else {
158  size_t n = avail.size();
159  for (size_t i=0; i<n; ++i ) {
160  G4cout << " [" << std::setw(3) << i << "] "
161  << " \"" << avail[i] << "\"" << G4endl;
162  }
163  }
164 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
static G4ThreadLocal G4PhysicsConstructorRegistry * theInstance
G4String name
Definition: TRTMaterials.hh:40
G4bool IsKnownPhysicsConstructor(const G4String &name)
std::vector< G4VPhysicsConstructor * > physConstr
#define G4ThreadLocal
Definition: tls.hh:89
G4GLOB_DLL std::ostream G4cout
G4VPhysicsConstructor * GetPhysicsConstructor(const G4String &name)
bool G4bool
Definition: G4Types.hh:79
const G4int n
void AddFactory(G4String, G4VBasePhysConstrFactory *)
std::map< G4String, G4VBasePhysConstrFactory * > factories
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4PhysicsConstructorRegistry * Instance()
#define G4endl
Definition: G4ios.hh:61
std::vector< G4String > AvailablePhysicsConstructors() const
void DeRegister(G4VPhysicsConstructor *)
void Register(G4VPhysicsConstructor *)