BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
getEnv.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include <cstdlib>
19#include <iostream>
20#include "getEnv.h"
21
22std::string getEnv(const char* env)
23{
24 //Check if it is only spaces
25 const char* tmp = std::getenv(env);
26 bool spacesOnly=true;
27 if(tmp){
28 std::string test = tmp;
29 spacesOnly = test.find_first_not_of (' ') == test.npos;
30#ifdef BDSDEBUG
31 std::cout << __FUNCTION__ << "> getEnv - test = " << test << std::endl;
32 std::cout << __FUNCTION__ << "> getEnv - spacesOnly =" << spacesOnly << std::endl;
33#endif
34 }
35 if((tmp==nullptr) || (spacesOnly)){
36#ifdef BDSDEBUG
37 std::cout << __FUNCTION__ << "> getEnv - no environment variable \"" << env << "\" is set" << std::endl;
38#endif
39 return (const char*)"";
40 } else {
41 std::string stmp = (std::string)tmp+ "/";
42#ifdef BDSDEBUG
43 std::cout << __FUNCTION__ << "> getEnv - environment variable \"" << stmp << "\" is set" << std::endl;
44#endif
45 return stmp;
46 }
47}