Geant4 10.7.0
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)
 
void G4PrintEnv (std::ostream &os=G4cout)
 

Function Documentation

◆ 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)
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:35
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)
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 226 of file G4EnvironmentUtils.hh.

227{
229}