Geant4  9.6.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$
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"
46 
47 // Neeed for running with 'static' libraries to pull the references of the
48 // declared factories
70 
71 
72 G4CrossSectionDataSetRegistry* G4CrossSectionDataSetRegistry::theInstance = 0;
73 
75 {
76  if(0 == theInstance) {
77  static G4CrossSectionDataSetRegistry manager;
78  theInstance = &manager;
79  }
80  return theInstance;
81 }
82 
83 G4CrossSectionDataSetRegistry::G4CrossSectionDataSetRegistry()
84 {}
85 
87 {
88  Clean();
89 }
90 
92 {
93  size_t n = xSections.size();
94  if(n > 0) {
95  for (size_t i=0; i<n; ++i) {
96  if(xSections[i]) {
97  G4VCrossSectionDataSet* p = xSections[i];
98  xSections[i] = 0;
99  delete p;
100  }
101  }
102  xSections.clear();
103  }
104 }
105 
107 {
108  if(!p) return;
109  size_t n = xSections.size();
110  if(n > 0) {
111  for (size_t i=0; i<n; ++i) {
112  if(xSections[i] == p) { return; }
113  }
114  }
115  xSections.push_back(p);
116 }
117 
119 {
120  if(!p) return;
121  size_t n = xSections.size();
122  if(n > 0) {
123  for (size_t i=0; i<n; ++i) {
124  if(xSections[i] == p) {
125  xSections[i] = 0;
126  return;
127  }
128  }
129  }
130 }
131 
133 {
134  factories[name] = factory;
135 }
136 
138 {
139  size_t n = xSections.size();
140 
141  for (size_t i=0; i<n; ++i)
142  {
143  if(xSections[i])
144  {
145  G4VCrossSectionDataSet* p = xSections[i];
146  if (p->GetName() == name) return p;
147  }
148  }
149  // check if factory exists...
150  //
151  if (factories.find(name)!=factories.end())
152  {
153  return factories[name]->Instantiate();
154  }
155  else
156  {
157  if(warning)
158  {
160  ED << "Factory for ["<< name << "] cross section data set not found." << G4endl;
161  G4Exception("G4CrossSectionDataSetRegistry::GetCrossSectionDataSet", "CrossSection001", FatalException, ED);
162  }
163  return 0;
164  }
165 }