Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4NuclearLevelStore.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 // $Id: G4NuclearLevelStore.cc 67983 2013-03-13 10:42:03Z gcosmo $
27 //
28 // 06-10-2010 M. Kelsey -- Drop static data members.
29 // 17-11-2010 V. Ivanchenko - make as a classical singleton.
30 // 17-10-2011 V. L. Desorgher - allows to define separate datafile for
31 // given isotope
32 // 06-01-2012 V. Ivanchenko - cleanup the code; new method GetLevelManager
33 //
34 
35 #include "G4NuclearLevelStore.hh"
36 #include <sstream>
37 #include <fstream>
38 
39 G4ThreadLocal G4NuclearLevelStore* G4NuclearLevelStore::theInstance = 0;
40 
42 {
43  if(!theInstance) {
44  static G4ThreadLocal G4NuclearLevelStore *store_G4MT_TLS_ = 0 ; if (!store_G4MT_TLS_) store_G4MT_TLS_ = new G4NuclearLevelStore ; G4NuclearLevelStore &store = *store_G4MT_TLS_;
45  theInstance = &store;
46  }
47  return theInstance;
48 }
49 
50 G4NuclearLevelStore::G4NuclearLevelStore()
51 {
52  userFiles = false;
53  char* env = getenv("G4LEVELGAMMADATA");
54  if (env == 0)
55  {
56  G4cout << "G4NuclarLevelStore: please set the G4LEVELGAMMADATA environment variable\n";
57  dirName = "";
58  }
59  else
60  {
61  dirName = env;
62  dirName += '/';
63  }
64 }
65 
67 {
68  ManagersMap::iterator i;
69  for (i = theManagers.begin(); i != theManagers.end(); ++i)
70  { delete i->second; }
71  MapForHEP::iterator j;
72  for (j = managersForHEP.begin(); j != managersForHEP.end(); ++j)
73  { delete j->second; }
74  if(userFiles) {
75  std::map<G4int, G4String>::iterator k;
76  for (k = theUserDataFiles.begin(); k != theUserDataFiles.end(); ++k)
77  { delete k->second; }
78  }
79 }
80 
81 void
83  const G4String& filename)
84 {
85  if (Z<1 || A<2) {
86  G4cout<<"G4NuclearLevelStore::AddUserEvaporationDataFile "
87  <<" Z= " << Z << " and A= " << A << " not valid!"<<G4endl;
88  }
89 
90  std::ifstream DecaySchemeFile(filename);
91  if (DecaySchemeFile){
92  G4int ID_ion=Z*1000+A;//A*1000+Z;
93  theUserDataFiles[ID_ion]=filename;
94  userFiles = true;
95  }
96  else {
97  G4cout<<"The file "<<filename<<" does not exist!"<<G4endl;
98  }
99 }
100 
101 G4String
102 G4NuclearLevelStore::GenerateFileName(G4int Z, G4int A) const
103 {
104  std::ostringstream streamName;
105  streamName << 'z' << Z << ".a" << A;
106  G4String name(streamName.str());
107  return name;
108 }
109 
112 {
113  G4NuclearLevelManager * result = 0;
114  if (A < 1 || Z < 1 || A < Z)
115  {
116  //G4cerr << "G4NuclearLevelStore::GetManager: Wrong values Z = " << Z
117  // << " A = " << A << '\n';
118  return result;
119  }
120 
121  // Generate the key = filename
122  G4int key = Z*1000+A; //GenerateKey(Z,A);
123 
124  // Check if already exists that key
125  ManagersMap::iterator idx = theManagers.find(key);
126  // If doesn't exists then create it
127  if ( idx == theManagers.end() )
128  {
129  G4String file = dirName + GenerateFileName(Z,A);
130 
131  //Check if data have been provided by the user
132  if(userFiles) {
133  G4String file1 = theUserDataFiles[key];//1000*A+Z];
134  if (file1 != "") { file = file1; }
135  }
136  result = new G4NuclearLevelManager(Z,A,file);
137  theManagers.insert(std::make_pair(key,result));
138  }
139  // But if it exists...
140  else
141  {
142  result = idx->second;
143  }
144 
145  return result;
146 }
147 
150 {
151  G4LevelManager * result = 0;
152  // Generate the key = filename
153  G4int key = Z*1000+A;
154 
155  // Check if already exists that key
156  MapForHEP::iterator idx = managersForHEP.find(key);
157  // If doesn't exists then create it
158  if ( idx == managersForHEP.end() ) {
159  result = new G4LevelManager(Z,A,reader,
160  dirName + GenerateFileName(Z,A));
161  managersForHEP.insert(std::make_pair(key,result));
162 
163  // it exists
164  } else {
165  result = idx->second;
166  }
167 
168  return result;
169 }
const XML_Char * name
static G4NuclearLevelStore * GetInstance()
#define G4ThreadLocal
Definition: tls.hh:52
int G4int
Definition: G4Types.hh:78
void AddUserEvaporationDataFile(G4int Z, G4int A, const G4String &filename)
G4GLOB_DLL std::ostream G4cout
G4LevelManager * GetLevelManager(G4int Z, G4int A)
G4NuclearLevelManager * GetManager(G4int Z, G4int A)
#define G4endl
Definition: G4ios.hh:61