Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
44 #include "G4VPhysicsConstructor.hh"
46 
47 G4ThreadLocal G4PhysicsConstructorRegistry* G4PhysicsConstructorRegistry::theInstance = 0;
48 
50 {
51  if(0 == theInstance) {
52  static G4ThreadLocal G4PhysicsConstructorRegistry *manager_G4MT_TLS_ = 0 ; if (!manager_G4MT_TLS_) manager_G4MT_TLS_ = new G4PhysicsConstructorRegistry ; G4PhysicsConstructorRegistry &manager = *manager_G4MT_TLS_;
53  theInstance = &manager;
54  }
55  return theInstance;
56 }
57 
58 G4PhysicsConstructorRegistry::G4PhysicsConstructorRegistry()
59 {}
60 
62 {
63  Clean();
64 }
65 
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 
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 
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 
108 {
109  factories[name] = factory;
110 }
111 
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  {
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 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
const char * p
Definition: xmltok.h:285
const XML_Char * name
#define G4ThreadLocal
Definition: tls.hh:52
G4VPhysicsConstructor * GetPhysicsConstructor(const G4String &name)
const G4int n
void AddFactory(G4String, G4VBasePhysConstrFactory *)
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
void DeRegister(G4VPhysicsConstructor *)
void Register(G4VPhysicsConstructor *)