Geant4  10.03.p02
 All Classes 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 96096 2016-03-14 21:50:15Z 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
75 
76 
77 G4ThreadLocal G4CrossSectionDataSetRegistry* G4CrossSectionDataSetRegistry::instance = 0;
78 
80 {
81  if(0 == instance) {
83  instance = inst.Instance();
84  }
85  return instance;
86 }
87 
88 G4CrossSectionDataSetRegistry::G4CrossSectionDataSetRegistry()
89 {}
90 
92 {
93  Clean();
94 }
95 
97 {
98  size_t n = xSections.size();
99  for (size_t i=0; i<n; ++i) {
100  if(xSections[i]) {
101  //const char* xxx = (xSections[i]->GetName()).c_str();
102  //G4int len = (xSections[i]->GetName()).length();
103  //len = std::min(len, 9);
104  //const G4String xname = G4String(xxx, len);
107  //if( (xname != "NeutronHP") && (xname != "ParticleH") ) {
108  delete xSections[i];
109  //}
110  //std::cout << " done" << " " << this << std::endl;
111  }
112  }
113  xSections.clear();
114 }
115 
117 {
118  if(!p) return;
119  size_t n = xSections.size();
120  for (size_t i=0; i<n; ++i) {
121  if(xSections[i] == p) { return; }
122  }
123  //G4cout << "Register x-section: " << p->GetName() << " " << p
124  // << " " << this << G4endl;
125  xSections.push_back(p);
126 }
127 
129 {
130  if(!p) return;
131  size_t n = xSections.size();
132  for (size_t i=0; i<n; ++i) {
133  if(xSections[i] == p) {
134  xSections[i] = 0;
135  return;
136  }
137  }
138 }
139 
140 //void G4CrossSectionDataSetRegistry::AddFactory(G4String name, G4VBaseXSFactory* factory)
141 //{
142 // factories[name] = factory;
143 //}
144 
146 {
147  size_t n = xSections.size();
148 
149  for (size_t i=0; i<n; ++i)
150  {
151  if(xSections[i])
152  {
153  G4VCrossSectionDataSet* p = xSections[i];
154  if (p->GetName() == name) return p;
155  }
156  }
157  // check if factory exists...
158  //
160  //This thorws if factory is not found, add second parameter to false to avoid this
161  G4VBaseXSFactory* factory = factories->GetFactory(name, warning );
162  if ( factory )
163  return factory->Instantiate();
164  else
165  return static_cast<G4VCrossSectionDataSet*>(0);
166 }
#define G4_REFERENCE_XS_FACTORY(cross_section)
G4VCrossSectionDataSet * GetCrossSectionDataSet(const G4String &name, G4bool warning=true)
const XML_Char * name
Definition: expat.h:151
void DeRegister(G4VCrossSectionDataSet *)
const char * p
Definition: xmltok.h:285
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
static G4CrossSectionDataSetRegistry * Instance()
const G4int n
static G4CrossSectionFactoryRegistry * Instance()
void Register(G4VCrossSectionDataSet *)