00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "G4NuclearLevelStore.hh"
00036 #include <sstream>
00037 #include <fstream>
00038
00039 G4NuclearLevelStore* G4NuclearLevelStore::theInstance = 0;
00040
00041 G4NuclearLevelStore* G4NuclearLevelStore::GetInstance()
00042 {
00043 if(!theInstance) {
00044 static G4NuclearLevelStore store;
00045 theInstance = &store;
00046 }
00047 return theInstance;
00048 }
00049
00050 G4NuclearLevelStore::G4NuclearLevelStore()
00051 {
00052 userFiles = false;
00053 char* env = getenv("G4LEVELGAMMADATA");
00054 if (env == 0)
00055 {
00056 G4cout << "G4NuclarLevelStore: please set the G4LEVELGAMMADATA environment variable\n";
00057 dirName = "";
00058 }
00059 else
00060 {
00061 dirName = env;
00062 dirName += '/';
00063 }
00064 }
00065
00066 G4NuclearLevelStore::~G4NuclearLevelStore()
00067 {
00068 ManagersMap::iterator i;
00069 for (i = theManagers.begin(); i != theManagers.end(); ++i)
00070 { delete i->second; }
00071 MapForHEP::iterator j;
00072 for (j = managersForHEP.begin(); j != managersForHEP.end(); ++j)
00073 { delete j->second; }
00074 if(userFiles) {
00075 std::map<G4int, G4String>::iterator k;
00076 for (k = theUserDataFiles.begin(); k != theUserDataFiles.end(); ++k)
00077 { delete k->second; }
00078 }
00079 }
00080
00081 void
00082 G4NuclearLevelStore::AddUserEvaporationDataFile(G4int Z, G4int A,
00083 const G4String& filename)
00084 {
00085 if (Z<1 || A<2) {
00086 G4cout<<"G4NuclearLevelStore::AddUserEvaporationDataFile "
00087 <<" Z= " << Z << " and A= " << A << " not valid!"<<G4endl;
00088 }
00089
00090 std::ifstream DecaySchemeFile(filename);
00091 if (DecaySchemeFile){
00092 G4int ID_ion=Z*1000+A;
00093 theUserDataFiles[ID_ion]=filename;
00094 userFiles = true;
00095 }
00096 else {
00097 G4cout<<"The file "<<filename<<" does not exist!"<<G4endl;
00098 }
00099 }
00100
00101 G4String
00102 G4NuclearLevelStore::GenerateFileName(G4int Z, G4int A) const
00103 {
00104 std::ostringstream streamName;
00105 streamName << 'z' << Z << ".a" << A;
00106 G4String name(streamName.str());
00107 return name;
00108 }
00109
00110 G4NuclearLevelManager*
00111 G4NuclearLevelStore::GetManager(G4int Z, G4int A)
00112 {
00113 G4NuclearLevelManager * result = 0;
00114 if (A < 1 || Z < 1 || A < Z)
00115 {
00116
00117
00118 return result;
00119 }
00120
00121
00122 G4int key = Z*1000+A;
00123
00124
00125 ManagersMap::iterator idx = theManagers.find(key);
00126
00127 if ( idx == theManagers.end() )
00128 {
00129 G4String file = dirName + GenerateFileName(Z,A);
00130
00131
00132 if(userFiles) {
00133 G4String file1 = theUserDataFiles[key];
00134 if (file1 != "") { file = file1; }
00135 }
00136 result = new G4NuclearLevelManager(Z,A,file);
00137 theManagers.insert(std::make_pair(key,result));
00138 }
00139
00140 else
00141 {
00142 result = idx->second;
00143 }
00144
00145 return result;
00146 }
00147
00148 G4LevelManager*
00149 G4NuclearLevelStore::GetLevelManager(G4int Z, G4int A)
00150 {
00151 G4LevelManager * result = 0;
00152
00153 G4int key = Z*1000+A;
00154
00155
00156 MapForHEP::iterator idx = managersForHEP.find(key);
00157
00158 if ( idx == managersForHEP.end() ) {
00159 result = new G4LevelManager(Z,A,reader,
00160 dirName + GenerateFileName(Z,A));
00161 managersForHEP.insert(std::make_pair(key,result));
00162
00163
00164 } else {
00165 result = idx->second;
00166 }
00167
00168 return result;
00169 }