source: trunk/source/processes/hadronic/models/de_excitation/photon_evaporation/src/G4NuclearLevelStore.cc @ 1348

Last change on this file since 1348 was 1347, checked in by garnier, 14 years ago

geant4 tag 9.4

File size: 3.5 KB
Line 
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,v 1.5 2010/11/17 16:50:53 vnivanch Exp $
27// GEANT4 tag $Name: geant4-09-04-ref-00 $
28//
29// 06-10-2010 M. Kelsey -- Drop static data members.
30// 17-11-2010 V. Ivanchenko - make as a classical singleton.
31
32#include "G4NuclearLevelStore.hh"
33#include <sstream>
34
35G4NuclearLevelStore* G4NuclearLevelStore::theInstance = 0;
36
37G4NuclearLevelStore* G4NuclearLevelStore::GetInstance()
38{
39  if(!theInstance) {
40    static G4NuclearLevelStore store;
41    theInstance = &store;
42  }
43  return theInstance;
44}
45
46G4NuclearLevelStore::G4NuclearLevelStore()
47{
48  char* env = getenv("G4LEVELGAMMADATA");
49  if (env == 0) 
50    {
51      G4cout << "G4NuclarLevelStore: please set the G4LEVELGAMMADATA environment variable\n";
52      dirName = "";
53    }
54  else
55    {
56      dirName = env;
57      dirName += '/';
58    }
59}
60
61G4NuclearLevelStore::~G4NuclearLevelStore()
62{
63  ManagersMap::iterator i;
64  for (i = theManagers.begin(); i != theManagers.end(); ++i)
65    delete i->second;
66}
67
68G4String
69G4NuclearLevelStore::GenerateFilename(G4int Z, G4int A) const 
70{
71  std::ostringstream streamName; 
72  streamName << 'z' << Z << ".a" << A;
73  G4String name(streamName.str());
74  return name;
75}
76
77G4NuclearLevelManager* 
78G4NuclearLevelStore::GetManager(G4int Z, G4int A) 
79{
80  G4NuclearLevelManager * result = 0; 
81  if (A < 1 || Z < 1 || A < Z)
82    {
83        G4cerr << "G4NuclearLevelStore::GetManager: Wrong values Z = " << Z
84               << " A = " << A << '\n';
85        return result;
86    }
87
88  // Generate the key = filename
89  G4int key = GenerateKey(Z,A);
90   
91  // Check if already exists that key
92  ManagersMap::iterator idx = theManagers.find(key);
93  // If doesn't exists then create it
94  if ( idx == theManagers.end() )
95    {
96      G4String file = GenerateFilename(Z,A);
97      result = new G4NuclearLevelManager(Z,A,dirName + file);
98      theManagers.insert(std::make_pair(key,result));
99    }
100  // But if it exists...
101  else
102    {
103      result = idx->second;
104    }
105   
106  return result; 
107}
Note: See TracBrowser for help on using the repository browser.