G4NuclearLevelStore.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 //
00028 // 06-10-2010 M. Kelsey -- Drop static data members.
00029 // 17-11-2010 V. Ivanchenko - make as a classical singleton. 
00030 // 17-10-2011 V. L. Desorgher - allows to define separate datafile for 
00031 //               given isotope
00032 // 06-01-2012 V. Ivanchenko - cleanup the code; new method GetLevelManager  
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;//A*1000+Z;
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       //G4cerr << "G4NuclearLevelStore::GetManager: Wrong values Z = " << Z 
00117       //               << " A = " << A << '\n';
00118       return result;
00119     }
00120 
00121   // Generate the key = filename
00122   G4int key = Z*1000+A; //GenerateKey(Z,A);
00123     
00124   // Check if already exists that key
00125   ManagersMap::iterator idx = theManagers.find(key);
00126   // If doesn't exists then create it
00127   if ( idx == theManagers.end() )
00128     {
00129       G4String file = dirName + GenerateFileName(Z,A);
00130 
00131       //Check if data have been provided by the user
00132       if(userFiles) {
00133         G4String file1 = theUserDataFiles[key];//1000*A+Z];
00134         if (file1 != "") { file = file1; }
00135       }
00136       result = new G4NuclearLevelManager(Z,A,file);
00137       theManagers.insert(std::make_pair(key,result));
00138     }
00139   // But if it exists...
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   // Generate the key = filename
00153   G4int key = Z*1000+A; 
00154     
00155   // Check if already exists that key
00156   MapForHEP::iterator idx = managersForHEP.find(key);
00157   // If doesn't exists then create it
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     // it exists
00164   } else {
00165     result = idx->second;
00166   }
00167     
00168   return result; 
00169 }

Generated on Mon May 27 17:49:06 2013 for Geant4 by  doxygen 1.4.7