Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4EnvironmentUtils.hh File Reference
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <mutex>
#include <sstream>
#include <string>
#include "G4Exception.hh"
#include "G4ExceptionSeverity.hh"
#include "G4String.hh"
#include "G4ios.hh"

Go to the source code of this file.

Classes

class  G4EnvSettings
 

Functions

template<typename _Tp >
_Tp G4GetEnv (const std::string &env_id, _Tp _default=_Tp())
 
template<>
G4bool G4GetEnv (const std::string &env_id, bool _default)
 
template<typename _Tp >
_Tp G4GetEnv (const std::string &env_id, _Tp _default, const std::string &msg)
 
G4String G4GetDataEnv (const std::string &env_id, const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
 
const char * G4FindDataDir (const char *)
 
void G4PrintEnv (std::ostream &os=G4cout)
 

Function Documentation

◆ G4FindDataDir()

const char * G4FindDataDir ( const char *  name)

Definition at line 93 of file G4FindDataDir.cc.

94{
95#if defined(G4MULTITHREADED)
96 static std::mutex mutex;
97 std::lock_guard<std::mutex> lock(mutex);
98#endif
99
100 /* If environment variable is set for this dataset, use it */
101 if (const char *datadir = std::getenv(name))
102 return datadir;
103
104 /* If we know which directory/version to search for, try to find it */
105 if (const char *dataset = G4GetDataDir(name)) {
106 /* If GEANT4_DATA_DIR environment variable is set, use it and don't search further */
107 if (const char *basedir = std::getenv("GEANT4_DATA_DIR"))
108 return G4FindDataDir(name, basedir, dataset);
109
110 /* If GEANT4_DATA_DIR environment variable is not set, search in default system paths */
111 for (const auto prefix : system_paths)
112 if (const auto datadir = G4FindDataDir(name, prefix, dataset))
113 return datadir;
114 }
115
116 return nullptr;
117}
const char * G4FindDataDir(const char *)

Referenced by G4LENDBertiniGammaElectroNuclearBuilder::Build(), G4ParticleHPCapture::BuildPhysicsTable(), G4ParticleHPElastic::BuildPhysicsTable(), G4ParticleHPFission::BuildPhysicsTable(), G4ParticleHPJENDLHEData::BuildPhysicsTable(), G4ParticleHPThermalScatteringData::BuildPhysicsTable(), G4VLEPTSModel::BuildPhysicsTable(), G4IonStoppingData::BuildPhysicsVector(), G4ecpssrBaseKxsModel::G4ecpssrBaseKxsModel(), G4ecpssrBaseLixsModel::G4ecpssrBaseLixsModel(), G4FindDataDir(), G4FissLib::G4FissLib(), G4LevelReader::G4LevelReader(), G4ParticleHPInelastic::G4ParticleHPInelastic(), G4ParticleHPInelasticData::G4ParticleHPInelasticData(), G4PhotoElectricAngularGeneratorPolarized::G4PhotoElectricAngularGeneratorPolarized(), G4RadioactiveDecay::G4RadioactiveDecay(), G4NuclideTable::GenerateNuclide(), G4ParticleHPNames::GetName(), G4ParticleHPInelasticCompFS::Init(), G4ParticleHPInelasticBaseFS::Init(), G4ParticleHPIsoData::Init(), G4IonICRU73Data::Initialise(), G4DNAChampionElasticModel::Initialise(), G4DNACPA100ElasticModel::Initialise(), G4DNASancheExcitationModel::Initialise(), G4BoldyshevTripletModel::Initialise(), G4JAEAElasticScatteringModel::Initialise(), G4JAEAPolarizedElasticScatteringModel::Initialise(), G4LivermoreBremsstrahlungModel::Initialise(), G4LivermoreComptonModel::Initialise(), G4LivermoreGammaConversion5DModel::Initialise(), G4LivermoreGammaConversionModel::Initialise(), G4LivermoreNuclearGammaConversionModel::Initialise(), G4LivermorePolarizedComptonModel::Initialise(), G4LivermorePolarizedGammaConversionModel::Initialise(), G4LivermorePolarizedRayleighModel::Initialise(), G4LivermoreRayleighModel::Initialise(), G4LowEPComptonModel::Initialise(), G4LowEPPolarizedComptonModel::Initialise(), G4MicroElecElasticModel::Initialise(), G4MicroElecElasticModel_new::Initialise(), G4MicroElecInelasticModel::Initialise(), G4MicroElecInelasticModel_new::Initialise(), G4DNABornExcitationModel2::Initialise(), G4DNABornIonisationModel1::Initialise(), G4DNABornIonisationModel2::Initialise(), G4DNACPA100IonisationModel::Initialise(), G4DNAEmfietzoglouIonisationModel::Initialise(), G4DNARelativisticIonisationModel::Initialise(), G4DNAELSEPAElasticModel::Initialise(), G4DNAIonElasticModel::Initialise(), G4ANuElNucleusCcModel::InitialiseModel(), G4ANuElNucleusNcModel::InitialiseModel(), G4ANuMuNucleusCcModel::InitialiseModel(), G4ANuMuNucleusNcModel::InitialiseModel(), G4ANuTauNucleusCcModel::InitialiseModel(), G4ANuTauNucleusNcModel::InitialiseModel(), G4NuElNucleusCcModel::InitialiseModel(), G4NuElNucleusNcModel::InitialiseModel(), G4NuMuNucleusCcModel::InitialiseModel(), G4NuMuNucleusNcModel::InitialiseModel(), G4NuTauNucleusCcModel::InitialiseModel(), G4NuTauNucleusNcModel::InitialiseModel(), G4INCL::HFB::initialize(), G4DNARelativisticIonisationModel::LoadAtomicStates(), G4VCrossSectionHandler::LoadData(), G4ShellData::LoadData(), G4AugerData::LoadData(), G4FluoData::LoadData(), G4GoudsmitSaundersonTable::LoadMSCData(), G4VCrossSectionHandler::LoadNonLogData(), G4FissionProductYieldDist::MakeDirectoryName(), G4OpticalSurface::ReadCompressedFile(), G4AblaDataFile::readData(), G4OpticalSurface::ReadDichroicFile(), G4MicroElecMaterialStructure::ReadMaterialFile(), and G4MuPairProductionModel::RetrieveTables().

◆ G4GetDataEnv()

G4String G4GetDataEnv ( const std::string &  env_id,
const char *  originOfException,
const char *  exceptionCode,
G4ExceptionSeverity  severity,
const char *  description 
)
inline

Definition at line 198 of file G4EnvironmentUtils.hh.

203{
204 char* env_var = std::getenv(env_id.c_str());
205 if(env_var != nullptr)
206 {
207 std::string str_var = std::string(env_var);
208 std::istringstream iss(str_var);
209 G4String var = "";
210 iss >> var;
211 // record value defined by environment
213 return var;
214 }
215
216 // issue an exception
217 G4Exception(originOfException, exceptionCode, severity, description);
218
219 // return default initialized
220 return "";
221}
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
void insert(const std::string &env_id, _Tp val)
static G4EnvSettings * GetInstance()

◆ G4GetEnv() [1/3]

template<typename _Tp >
_Tp G4GetEnv ( const std::string &  env_id,
_Tp  _default,
const std::string &  msg 
)

Definition at line 167 of file G4EnvironmentUtils.hh.

168{
169 char* env_var = std::getenv(env_id.c_str());
170 if(env_var)
171 {
172 std::string str_var = std::string(env_var);
173 std::istringstream iss(str_var);
174 _Tp var = _Tp();
175 iss >> var;
176 G4cout << "Environment variable \"" << env_id << "\" enabled with "
177 << "value == " << var << ". " << msg << G4endl;
178 // record value defined by environment
179 G4EnvSettings::GetInstance()->insert<_Tp>(env_id, var);
180 return var;
181 }
182 // record default value
183 G4EnvSettings::GetInstance()->insert<_Tp>(env_id, _default);
184
185 // return default if not specified in environment
186 return _default;
187}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout

◆ G4GetEnv() [2/3]

template<typename _Tp >
_Tp G4GetEnv ( const std::string &  env_id,
_Tp  _default = _Tp() 
)

Definition at line 116 of file G4EnvironmentUtils.hh.

117{
118 char* env_var = std::getenv(env_id.c_str());
119 if(env_var)
120 {
121 std::string str_var = std::string(env_var);
122 std::istringstream iss(str_var);
123 _Tp var = _Tp();
124 iss >> var;
125 // record value defined by environment
126 G4EnvSettings::GetInstance()->insert<_Tp>(env_id, var);
127 return var;
128 }
129 // record default value
130 G4EnvSettings::GetInstance()->insert<_Tp>(env_id, _default);
131
132 // return default if not specified in environment
133 return _default;
134}

◆ G4GetEnv() [3/3]

template<>
G4bool G4GetEnv ( const std::string &  env_id,
bool  _default 
)
inline

Definition at line 143 of file G4EnvironmentUtils.hh.

144{
145 char* env_var = std::getenv(env_id.c_str());
146 if(env_var != nullptr)
147 {
148 // record value defined by environment
149 G4EnvSettings::GetInstance()->insert<bool>(env_id, true);
150 return true;
151 }
152 // record default value
153 G4EnvSettings::GetInstance()->insert<bool>(env_id, false);
154
155 // return default if not specified in environment
156 return _default;
157}

◆ G4PrintEnv()

void G4PrintEnv ( std::ostream &  os = G4cout)
inline

Definition at line 228 of file G4EnvironmentUtils.hh.

229{
231}