Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4CrossSectionDataSetRegistry.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: G4CrossSectionDataSetRegistry.cc 73791 2013-09-12 07:55:48Z gcosmo $
28 //
29 // -------------------------------------------------------------------
30 //
31 // GEANT4 Class file
32 //
33 //
34 // File name: G4CrossSectionDataSetRegistry
35 //
36 // Author V.Ivanchenko 24.01.2009
37 //
38 // Modifications:
39 //
40 
41 #include "G4ios.hh"
42 
45 #include "G4CrossSectionFactory.hh"
47 
48 // Neeed for running with 'static' libraries to pull the references of the
49 // declared factories
73 
74 
75 G4ThreadLocal G4CrossSectionDataSetRegistry* G4CrossSectionDataSetRegistry::theInstance = 0;
76 
78 {
79  if(0 == theInstance) {
80  static G4ThreadLocal G4CrossSectionDataSetRegistry *manager_G4MT_TLS_ = 0 ; if (!manager_G4MT_TLS_) manager_G4MT_TLS_ = new G4CrossSectionDataSetRegistry ; G4CrossSectionDataSetRegistry &manager = *manager_G4MT_TLS_;
81  theInstance = &manager;
82  }
83  return theInstance;
84 }
85 
86 G4CrossSectionDataSetRegistry::G4CrossSectionDataSetRegistry()
87 {}
88 
90 {
91  Clean();
92 }
93 
95 {
96  size_t n = xSections.size();
97  if(n > 0) {
98  for (size_t i=0; i<n; ++i) {
99  if(xSections[i]) {
100  G4VCrossSectionDataSet* p = xSections[i];
101  xSections[i] = 0;
102  delete p;
103  }
104  }
105  xSections.clear();
106  }
107 }
108 
110 {
111  if(!p) return;
112  size_t n = xSections.size();
113  if(n > 0) {
114  for (size_t i=0; i<n; ++i) {
115  if(xSections[i] == p) { return; }
116  }
117  }
118  xSections.push_back(p);
119 }
120 
122 {
123  if(!p) return;
124  size_t n = xSections.size();
125  if(n > 0) {
126  for (size_t i=0; i<n; ++i) {
127  if(xSections[i] == p) {
128  xSections[i] = 0;
129  return;
130  }
131  }
132  }
133 }
134 
135 //void G4CrossSectionDataSetRegistry::AddFactory(G4String name, G4VBaseXSFactory* factory)
136 //{
137 // factories[name] = factory;
138 //}
139 
141 {
142  size_t n = xSections.size();
143 
144  for (size_t i=0; i<n; ++i)
145  {
146  if(xSections[i])
147  {
148  G4VCrossSectionDataSet* p = xSections[i];
149  if (p->GetName() == name) return p;
150  }
151  }
152  // check if factory exists...
153  //
155  //This thorws if factory is not found, add second parameter to false to avoid this
156  G4VBaseXSFactory* factory = factories->GetFactory(name, warning );
157  if ( factory )
158  return factory->Instantiate();
159  else
160  return static_cast<G4VCrossSectionDataSet*>(0);
161 }
G4VCrossSectionDataSet * GetCrossSectionDataSet(const G4String &name, G4bool warning=true)
void DeRegister(G4VCrossSectionDataSet *)
const char * p
Definition: xmltok.h:285
const XML_Char * name
const G4String & GetName() const
#define G4ThreadLocal
Definition: tls.hh:52
virtual G4VCrossSectionDataSet * Instantiate()=0
G4VBaseXSFactory * GetFactory(const G4String &name, G4bool abortIfNotFound=true) const
bool G4bool
Definition: G4Types.hh:79
G4_REFERENCE_XS_FACTORY(G4ChipsKaonMinusInelasticXS)
static G4CrossSectionDataSetRegistry * Instance()
const G4int n
static G4CrossSectionFactoryRegistry * Instance()
void Register(G4VCrossSectionDataSet *)