30#include "G4FindDataDir.hh"
39#define setenv(name, value, overwrite) _putenv_s(name, value)
44static const char *
const system_paths[] = {
45 GEANT4_INSTALL_FULL_DATADIR,
53 "/cvmfs/geant4.cern.ch"
57static const char *
const data_paths[] = {
59 GEANT4_INSTALL_DATADIR,
60 CMAKE_INSTALL_DATADIR,
67static const char* G4GetDataDir(
const char* name)
69 for (
const auto& d : dataset_definitions)
70 if (strcmp(name, d.env) == 0)
81 for (
const auto data_path : data_paths) {
83 if (strcmp(data_path,
".") == 0)
86 datadir /= path(data_path) / dataset;
87 if (is_directory(absolute(datadir)))
88 return setenv(name, absolute(datadir).
string().c_str(), 0) == 0 ? std::getenv(name) : nullptr;
96#if defined(G4MULTITHREADED)
97 static std::mutex
mutex;
98 std::lock_guard<std::mutex> lock(
mutex);
102 if (
const char *datadir = std::getenv(name))
106 if (
const char *dataset = G4GetDataDir(name)) {
108 if (
const char *basedir = std::getenv(
"GEANT4_DATA_DIR")) {
109 if (is_directory(basedir))
return G4FindDataDir(name, basedir, dataset);
111 G4Exception(
"G4FindDataDir",
"Invalid GEANT4_DATA_DIR",
JustWarning,
"The GEANT4_DATA_DIR environment variable points to an invalid directory.\n"
112 "Will try fallback locations now. Correct the variable to disable this behaviour.");
116 for (
const auto prefix : system_paths)
130#if defined(G4MULTITHREADED)
131 static std::mutex
mutex;
132 std::lock_guard<std::mutex> lock(
mutex);
135 if (
const char *datadir = std::getenv(name))
const char * G4FindDataDir(const char *)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)