Geant4  10.01.p02
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 83697 2014-09-10 07:15:29Z 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
77 
78 
80 
82 {
83  if(0 == theInstance) {
84  static G4ThreadLocal G4CrossSectionDataSetRegistry *manager_G4MT_TLS_ = 0 ; if (!manager_G4MT_TLS_) manager_G4MT_TLS_ = new G4CrossSectionDataSetRegistry ; G4CrossSectionDataSetRegistry &manager = *manager_G4MT_TLS_;
85  theInstance = &manager;
86  }
87  return theInstance;
88 }
89 
91 {}
92 
94 {
95  Clean();
96 }
97 
99 {
100  size_t n = xSections.size();
101  if(n > 0) {
102  for (size_t i=0; i<n; ++i) {
103  if(xSections[i]) {
105  xSections[i] = 0;
106  delete p;
107  }
108  }
109  xSections.clear();
110  }
111 }
112 
114 {
115  if(!p) return;
116  size_t n = xSections.size();
117  if(n > 0) {
118  for (size_t i=0; i<n; ++i) {
119  if(xSections[i] == p) { return; }
120  }
121  }
122  xSections.push_back(p);
123 }
124 
126 {
127  if(!p) return;
128  size_t n = xSections.size();
129  if(n > 0) {
130  for (size_t i=0; i<n; ++i) {
131  if(xSections[i] == p) {
132  xSections[i] = 0;
133  return;
134  }
135  }
136  }
137 }
138 
139 //void G4CrossSectionDataSetRegistry::AddFactory(G4String name, G4VBaseXSFactory* factory)
140 //{
141 // factories[name] = factory;
142 //}
143 
145 {
146  size_t n = xSections.size();
147 
148  for (size_t i=0; i<n; ++i)
149  {
150  if(xSections[i])
151  {
153  if (p->GetName() == name) return p;
154  }
155  }
156  // check if factory exists...
157  //
159  //This thorws if factory is not found, add second parameter to false to avoid this
160  G4VBaseXSFactory* factory = factories->GetFactory(name, warning );
161  if ( factory )
162  return factory->Instantiate();
163  else
164  return static_cast<G4VCrossSectionDataSet*>(0);
165 }
G4VCrossSectionDataSet * GetCrossSectionDataSet(const G4String &name, G4bool warning=true)
static G4ThreadLocal G4CrossSectionDataSetRegistry * theInstance
void DeRegister(G4VCrossSectionDataSet *)
G4String name
Definition: TRTMaterials.hh:40
const G4String & GetName() const
#define G4ThreadLocal
Definition: tls.hh:89
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
std::vector< G4VCrossSectionDataSet * > xSections
static G4CrossSectionFactoryRegistry * Instance()
void Register(G4VCrossSectionDataSet *)