Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:42

0001 #include <cassert>
0002 #include <sstream>
0003 #include <cstdlib>
0004 
0005 #include "SSys.hh"
0006 #include "ssys.h"
0007 
0008 #include "SStr.hh"
0009 #include "sstr.h"
0010 #include "spath.h"
0011 
0012 #include "SPath.hh"   // on the way out 
0013 #include "spath.h"
0014 
0015 #include "sproc.h"
0016 #include "SOpticksResource.hh"
0017 #include "SLOG.hh"
0018 
0019 #include "NP.hh"
0020 
0021 
0022 const plog::Severity SOpticksResource::LEVEL = SLOG::EnvLevel("SOpticksResource", "DEBUG"); 
0023 
0024 const char* SOpticksResource::GEOCACHE_PREFIX_KEY = "OPTICKS_GEOCACHE_PREFIX" ; 
0025 const char* SOpticksResource::RNGCACHE_PREFIX_KEY = "OPTICKS_RNGCACHE_PREFIX" ; 
0026 const char* SOpticksResource::USERCACHE_PREFIX_KEY = "OPTICKS_USERCACHE_PREFIX" ; 
0027 const char* SOpticksResource::PRECOOKED_PREFIX_KEY = "OPTICKS_PRECOOKED_PREFIX" ; 
0028 
0029 const char* SOpticksResource::MakeUserDir(const char* sub) 
0030 {
0031     return SPath::Resolve("$HOME", sub, DIRPATH) ; 
0032 }
0033 
0034 
0035 /**
0036 SOpticksResource::ResolveUserPrefix
0037 ----------------------------------------
0038 
0039 1. sensitive to envvars :  OPTICKS_GEOCACHE_PREFIX OPTICKS_RNGCACHE_PREFIX OPTICKS_USERCACHE_PREFIX OPTICKS_PRECOOKED_PREFIX
0040 2. if envvar not defined defaults to $HOME/.opticks 
0041 3. the envvar is subsequently internally set for consistency 
0042 
0043 
0044 **/
0045 
0046 const char* SOpticksResource::ResolveUserPrefix(const char* envkey, bool envset)  // static
0047 {
0048     const char* evalue = ssys::getenvvar(envkey);    
0049     const char* prefix = evalue == nullptr ?  MakeUserDir(".opticks") : evalue ; 
0050     if(envset)
0051     {
0052         bool overwrite = true ; 
0053         int rc = SSys::setenvvar(envkey, prefix, overwrite );
0054         LOG(LEVEL) 
0055              << " envkey " << envkey
0056              << " prefix " << prefix
0057              << " rc " << rc
0058              ;    
0059         assert( rc == 0 );            
0060     } 
0061     return prefix ; 
0062 }
0063 
0064 const char* SOpticksResource::ResolveGeoCachePrefix() { return ResolveUserPrefix(GEOCACHE_PREFIX_KEY, true) ; }
0065 const char* SOpticksResource::ResolveRngCachePrefix() { return ResolveUserPrefix(RNGCACHE_PREFIX_KEY, true) ; }
0066 const char* SOpticksResource::ResolveUserCachePrefix(){ return ResolveUserPrefix(USERCACHE_PREFIX_KEY, true) ; }
0067 const char* SOpticksResource::ResolvePrecookedPrefix(){ return ResolveUserPrefix(PRECOOKED_PREFIX_KEY, true) ; }
0068 
0069 const char* SOpticksResource::GeocacheDir(){        return SPath::Resolve(ResolveGeoCachePrefix(), "geocache", NOOP); }
0070 const char* SOpticksResource::GeocacheScriptPath(){ return SPath::Resolve(GeocacheDir(), "geocache.sh", NOOP); }
0071 
0072 const char* SOpticksResource::RNGCacheDir(){    return SPath::Resolve(ResolveRngCachePrefix(), "rngcache", NOOP); }
0073 const char* SOpticksResource::RNGDir(){         return SPath::Resolve(RNGCacheDir(), "RNG", NOOP); }
0074 const char* SOpticksResource::RuncacheDir(){    return SPath::Resolve(ResolveUserCachePrefix(), "runcache", NOOP); }
0075 const char* SOpticksResource::PrecookedDir(){   return SPath::Resolve(ResolvePrecookedPrefix(), "precooked", NOOP); }
0076 
0077 
0078 /**
0079 SOpticksResource::ExecutableName
0080 ---------------------------------
0081 
0082 In embedded running SProc::ExecutableName returns "python3.8" 
0083 As that is not very informative it is replaced with the value of the 
0084 SCRIPT envvar if it is defined, or otherwise defaulting to "script"
0085 
0086 A good practice would be to define and export SCRIPT in the 
0087 invoking bash function, with the line::
0088 
0089    export SCRIPT=$FUNCNAME 
0090 
0091 Alternatively the returned name can be controlled directly, not just when embedded, 
0092 using envvar SOpticksResource_ExecutableName
0093 
0094 **/
0095 
0096 const char* SOpticksResource::ExecutableName()
0097 {  
0098     /* 
0099     const char* exe0 = sproc::ExecutableName() ; 
0100     bool is_python = sstr::StartsWith(exe0, "python") ;  
0101     const char* script = ssys::getenvvar("SCRIPT"); 
0102     const char* exe = ( is_python && script ) ? script : exe0 ; 
0103     */
0104 
0105     const char* exe = sproc::ExecutableName() ;
0106     const char* result = ssys::getenvvar("SOpticksResource_ExecutableName", exe ) ; 
0107 
0108     // as this is used before logging is setup cannot use normal logging to check 
0109     if(ssys::getenvvar("SOpticksResource")) std::cout 
0110         << "SOpticksResource::ExecutableName" 
0111         << " exe "       << ( exe  ? exe : "-" )
0112         << " result "    << ( result ? result : "-" ) 
0113         << std::endl 
0114         ;
0115 
0116     return result ; 
0117 } 
0118 
0119 const char* SOpticksResource::ExecutableName_GEOM()
0120 {
0121     std::stringstream ss ; 
0122     ss << ExecutableName() << "_GEOM" ;  
0123     std::string s = ss.str(); 
0124     return strdup(s.c_str()); 
0125 }
0126 
0127 /**
0128 SOpticksResource::GEOMFromEnv
0129 --------------------------------
0130 
0131 Precedence order for the GEOM string returned
0132 
0133 1. value of envvar ExecutableName_GEOM 
0134 2. value of envvar GEOM 
0135 3. fallback argumnent, which can be nullptr 
0136 
0137 **/
0138 
0139 const char* SOpticksResource::GEOMFromEnv(const char* fallback)
0140 {
0141     const char* geom_std = ssys::getenvvar("GEOM", fallback) ; 
0142     const char* geom_bin = ExecutableName_GEOM() ; 
0143     const char* geom = ssys::getenvvar(geom_bin, geom_std) ;     
0144     return geom ; 
0145 }
0146 
0147 const char* SOpticksResource::_GEOM = nullptr ; 
0148 
0149 /**
0150 SOpticksResource::GEOM
0151 -------------------------
0152 
0153 If _GEOM is nullptr an attempt to get it from environment is done, 
0154 otherwise the cached _GEOM is returned.   
0155 
0156 **/
0157 
0158 const char* SOpticksResource::GEOM(const char* fallback)
0159 {
0160     if(_GEOM == nullptr) _GEOM = GEOMFromEnv(fallback); 
0161     return _GEOM ; 
0162 }
0163 void SOpticksResource::SetGEOM( const char* geom )
0164 {
0165     _GEOM = strdup(geom); 
0166 }
0167 
0168 
0169 /**
0170 SOpticksResource::DefaultOutputDir
0171 ------------------------------------
0172 
0173 Default dir used by argumentless SEvt::save is $TMP/GEOM/$GEOM/ExecutableName eg::
0174 
0175    /tmp/blyth/opticks/GEOM/RaindropRockAirWater/G4CXSimulateTest
0176 
0177 This allows $TMP/GEOM/$GEOM to be equated with a "temporary CFBASE" for consistent handling in scripts.::
0178 
0179     TMP_CFBASE=/tmp/$USER/opticks/$GEOM
0180 
0181 This layout is consistent with geocache output layout CFBASE/ExecutableName eg: 
0182 
0183    /Users/blyth/.opticks/geocache/DetSim0Svc_pWorld_g4live/g4ok_gltf/41c046fe05b28cb70b1fc65d0e6b7749/1/CSG_GGeo/G4CXSimulateTest
0184 
0185 Previously used the inconsistent flipped layout TMP/ExecutableName/GEOM which complicated scripts. 
0186 
0187 
0188 Hmm how did this arise::
0189 
0190     /tmp/blyth/opticks/GEOM/ntds3/G4CXOpticks
0191 
0192 
0193 **/
0194 
0195 
0196 const char* SOpticksResource::DefaultOutputDir()
0197 { 
0198     return SPath::Resolve("$TMP/GEOM", GEOM(), ExecutableName(), NOOP); 
0199 }
0200 const char* SOpticksResource::DefaultGeometryDir()
0201 { 
0202     //return SPath::Resolve("$HOME/.opticks/GEOM", GEOM(), NOOP); 
0203     //return SPath::Resolve("$TMP/GEOM", GEOM(), NOOP); 
0204     return spath::Resolve("$HOME/.opticks/GEOM/$GEOM") ; 
0205 }
0206 const char* SOpticksResource::DefaultGeometryBase()
0207 { 
0208     return SPath::Resolve("$TMP/GEOM", NOOP); 
0209 }
0210 const char* SOpticksResource::UserGEOMDir()
0211 {
0212     return SPath::Resolve("$HOME/.opticks/GEOM", GEOM(), DIRPATH ); 
0213 
0214 }
0215 
0216 
0217 
0218 std::string SOpticksResource::Desc_DefaultOutputDir()
0219 {
0220     const char* geom = GEOM() ; 
0221     std::stringstream ss ; 
0222     ss << "SOpticksResource::Desc_DefaultOutputDir" << std::endl 
0223        << " SPath::Resolve(\"$TMP/GEOM\",NOOP) " << SPath::Resolve("$TMP/GEOM",NOOP) << std::endl 
0224        << " SOpticksResource::GEOM() " << ( geom ? geom : "-" )  << std::endl 
0225        << " SOpticksResource::ExecutableName() " << SOpticksResource::ExecutableName() << std::endl 
0226        << " SOpticksResource::DefaultOutputDir() " << SOpticksResource::DefaultOutputDir() << std::endl 
0227        ;
0228     std::string s = ss.str(); 
0229     return s ; 
0230 }
0231 
0232 std::string SOpticksResource::Dump()
0233 {
0234 
0235     const char* geocache_prefix = ResolveGeoCachePrefix()  ;
0236     const char* rngcache_prefix = ResolveRngCachePrefix() ; 
0237     const char* usercache_prefix = ResolveUserCachePrefix() ;
0238     const char* precooked_prefix = ResolvePrecookedPrefix() ;
0239     const char* geocache_dir = GeocacheDir() ; 
0240     const char* geocache_scriptpath = GeocacheScriptPath() ; 
0241     const char* rngcache_dir = RNGCacheDir() ; 
0242     const char* rng_dir = RNGDir() ; 
0243     const char* precooked_dir = PrecookedDir() ; 
0244     const char* outputdir = DefaultOutputDir(); 
0245     const char* geometrydir = DefaultGeometryDir(); 
0246     const char* geometrybase = DefaultGeometryBase(); 
0247     const char* runcache_dir = RuncacheDir() ; 
0248     const char* cfbase = CFBase(); 
0249     const char* cfbase_alt = CFBaseAlt(); 
0250     const char* cfbase_fg = CFBaseFromGEOM(); 
0251     const char* gdmlpath = GDMLPathFromGEOM(); 
0252     const char* geom = GEOM(); 
0253     const char* usergeomdir = UserGEOMDir(); 
0254 
0255 
0256     std::stringstream ss ; 
0257     ss 
0258         << std::endl 
0259         << "GEOCACHE_PREFIX_KEY                        " << GEOCACHE_PREFIX_KEY  << std::endl 
0260         << "RNGCACHE_PREFIX_KEY                        " << RNGCACHE_PREFIX_KEY  << std::endl 
0261         << "USERCACHE_PREFIX_KEY                       " << USERCACHE_PREFIX_KEY  << std::endl 
0262         << "SOpticksResource::ResolveGeoCachePrefix()  " << ( geocache_prefix ? geocache_prefix : "-" ) << std::endl 
0263         << "SOpticksResource::ResolveRngCachePrefix()  " << ( rngcache_prefix ? rngcache_prefix : "-" )  << std::endl 
0264         << "SOpticksResource::ResolveUserCachePrefix() " << ( usercache_prefix ? usercache_prefix : "-" )  << std::endl 
0265         << "SOpticksResource::ResolvePrecookedPrefix() " << ( precooked_prefix ? precooked_prefix : "-" )  << std::endl 
0266         << "SOpticksResource::GeocacheDir()            " << ( geocache_dir  ? geocache_dir : "-" ) << std::endl 
0267         << "SOpticksResource::GeocacheScriptPath()     " << ( geocache_scriptpath ? geocache_scriptpath : "-" ) << std::endl 
0268         << "SOpticksResource::RNGCacheDir()            " << ( rngcache_dir  ? rngcache_dir : "-" )  << std::endl 
0269         << "SOpticksResource::RNGDir()                 " << ( rng_dir ? rng_dir : "-" )  << std::endl 
0270         << "SOpticksResource::PrecookedDir()           " << ( precooked_dir ? precooked_dir : "-" )  << std::endl 
0271         << "SOpticksResource::DefaultOutputDir()       " << ( outputdir ? outputdir : "-" ) << std::endl 
0272         << "SOpticksResource::DefaultGeometryBase()    " << ( geometrybase ? geometrybase : "-" ) << std::endl 
0273         << "SOpticksResource::DefaultGeometryDir()     " << ( geometrydir ? geometrydir : "-" ) << std::endl 
0274         << "SOpticksResource::RuncacheDir()            " << ( runcache_dir ? runcache_dir : "-" )  << std::endl 
0275         << "SOpticksResource::CFBase()                 " << ( cfbase ? cfbase : "-" ) << std::endl 
0276         << "SOpticksResource::CFBaseAlt()              " << ( cfbase_alt ? cfbase_alt : "-" ) << std::endl 
0277         << "SOpticksResource::CFBaseFromGEOM()         " << ( cfbase_fg ? cfbase_fg : "-" ) << std::endl 
0278         << "SOpticksResource::GDMLPathFromGEOM()       " << ( gdmlpath ? gdmlpath : "-" ) << std::endl
0279         << "SOpticksResource::GEOM()                   " << ( geom ? geom : "-" ) << std::endl
0280         << "SOpticksResource::UserGEOMDir()            " << ( usergeomdir ? usergeomdir : "-" ) << std::endl
0281         ;
0282 
0283     std::string s = ss.str(); 
0284     return s ; 
0285 }
0286 
0287 
0288 
0289 /**
0290 SOpticksResource::CFBase
0291 --------------------------
0292 
0293 Return the directory path within which the CSGFoundry directory 
0294 will be expected.  The path returned dependes on 
0295 environment variables : CFBASE, OPTICKS_KEY, OPTICKS_GEOCACHE_PREFIX
0296 
0297 Precedence order:
0298 
0299 1. CFBASE envvar values directly providing CFBASE directory 
0300 
0301 2. CFBASE directory derived from OPTICKS_KEY and OPTICKS_GEOCACHE_PREFIX 
0302    giving "$IDBase/CSG_GGeo"
0303 
0304 When the *ekey* envvar (default CFBASE) is defined its 
0305 value is returned otherwise the CFDir obtained from the 
0306 OPTICKS_KEY is returned.  
0307 **/
0308 
0309 
0310 const char* SOpticksResource::CFBASE_ = "CFBASE" ; 
0311 const char* SOpticksResource::CFBase()
0312 {
0313     const char* cfbase = ssys::getenvvar(CFBASE_) ; 
0314     return cfbase ; 
0315 }
0316 
0317 const char* SOpticksResource::CFBaseAlt()
0318 {
0319     const char* cfbase = ssys::getenvvar("CFBASE_ALT") ; 
0320     return cfbase ; 
0321 }
0322 
0323 
0324 /**
0325 SOpticksResource::CFBaseFromGEOM
0326 ----------------------------------
0327 
0328 Indirect config of CFBase folder via two envvars.
0329 
0330 GEOM
0331    short name identifying the geometry, eg J001
0332 
0333 "$GEOM"_CFBaseFromGEOM
0334    ie J001_CFBaseFromGEOM
0335 
0336 The advantage of the indirect approach is that GEOM provides
0337 a simple name, with the detail of the directory hidden in
0338 the other envvar.   
0339 
0340 Bash functions to edit config : geom_, com_. oip
0341 
0342 **/
0343 
0344 const char* SOpticksResource::CFBaseFromGEOM()
0345 {
0346     const char* geom = GEOM(); 
0347     const char* name = spath::Name(geom ? geom : "MISSING_GEOM", "_CFBaseFromGEOM") ; 
0348     const char* path = geom == nullptr ? nullptr : ssys::getenvvar(name) ; 
0349     LOG(LEVEL) 
0350         << " geom " << geom 
0351         << " name " << name 
0352         << " path " << path 
0353         ;
0354     return path  ; 
0355 }
0356 
0357 /**
0358 SOpticksResource::GDMLPathFromGEOM
0359 ------------------------------------
0360 
0361 Used for example from the argumentless G4CXOpticks::setGeometry
0362 
0363 Assumes a GEOM envvar, and looks for 2nd order envvar 
0364 that starts with the GEOM value. 
0365 
0366 As it is better for the C++ code to not make many 
0367 assumptions about a users file layout it is necessary 
0368 to specify where to find the GDML within the invoking 
0369 script. Typically that is done immediately after setting the 
0370 GEOM envvar at the head of a script with::
0371 
0372     source $HOME/.opticks/GEOM/GEOM.sh   # set GEOM envvar 
0373     export ${GEOM}_GDMLPathFromGEOM=$HOME/.opticks/GEOM/$GEOM/origin.gdml  
0374 
0375 Note that the presence of the 2nd order _GDMLPathFromGEOM both indicates
0376 where the GDML is and also indicates to some Geant4-centric executables
0377 to operate starting from GDML. 
0378 
0379 **/
0380 
0381 const char* SOpticksResource::GDMLPathFromGEOM(const char* _geom)
0382 {
0383     const char* geom = _geom == nullptr ? GEOM() : _geom ; 
0384     const char* path =  geom == nullptr ? nullptr : ssys::getenvvar(spath::Name(geom, "_GDMLPathFromGEOM")) ; 
0385     LOG(LEVEL) 
0386         << " _geom " << ( _geom ? _geom : "-" ) 
0387         << " geom " << ( geom ? geom : "-" ) 
0388         << " path " << ( path ? path : "-" ) 
0389         ;
0390     return path ; 
0391 }
0392 
0393 
0394 
0395 
0396 const char* SOpticksResource::WrapLVForName(const char* name)
0397 {
0398     assert(name) ; 
0399     return ssys::getenvvar(spath::Name(name, "_WrapLVForName")) ; 
0400 }
0401 
0402 
0403 
0404 
0405 /**
0406 SOpticksResource::SearchCFBase
0407 -------------------------------
0408 
0409 Traverse up the directory provided looking for a directory containing "CSGFoundry/solid.npy"
0410 The first such directory is returned, or nullptr if not found. 
0411 
0412 **/
0413 
0414 const char* SOpticksResource::SearchCFBase(const char* dir){ return spath::SearchDirUpTreeWithFile(dir, SearchCFBase_RELF) ; }
0415 
0416 
0417 const char* SOpticksResource::OpticksGDMLPath_ = "OpticksGDMLPath" ; 
0418 const char* SOpticksResource::OpticksGDMLPath()
0419 {
0420     return getenv(OpticksGDMLPath_) ;   
0421 }
0422 
0423 const char* SOpticksResource::SomeGDMLPath_ = "SomeGDMLPath" ; 
0424 const char* SOpticksResource::SomeGDMLPath()
0425 {
0426     // TODO: use GDXML instead of the old CGDMLKludge 
0427     const char* path0 = getenv(SomeGDMLPath_) ;   
0428     const char* path1 = spath::Resolve("$HOME/.opticks/GEOM/$GEOM/origin.gdml");  
0429     const char* path2 = nullptr ; 
0430 
0431     const char* path = SPath::PickFirstExisting(path0, path1, path2); 
0432     LOG(LEVEL)  << " path " << ( path ? path : "-" ) ;    
0433     return path ; 
0434 }
0435 
0436 
0437 
0438 /**
0439 SOpticksResource::GDMLPath
0440 ----------------------------
0441 
0442 TODO: consolidate with GDMLPathFromGEOM
0443 
0444 
0445 Converts *geom* name eg "JUNOv101" into a path by reading envvar "JUNOv101_GDMLPath" if it exists, 
0446 returns nullptr when the envvar does not exist or if geom is nullptr. 
0447 
0448 For example exercise this with::
0449 
0450     GEOM=hello hello_GDMLPath='$DefaultOutputDir/some/relative/path' SOpticksResourceTest 
0451 
0452 * Single quotes are needed to prevent shell expansion of the internal token DefaultOutputDir.
0453 * Notice how the key "hello" provides a shortname with which to refer to the long GDML path. 
0454 * the returned path is expected to be resolved by SPath::Resolve 
0455 * there is no check of the existance of the GDML path 
0456 
0457 
0458 
0459 const char* SOpticksResource::GDMLPath(){ return GDMLPath( GEOM()); }
0460 const char* SOpticksResource::GDMLPath(const char* geom)
0461 {
0462     LOG(fatal) << " TODO: ELIMINATE THIS : INSTEAD USE GDMLPathFromGEOM " ; 
0463 
0464     return geom == nullptr ? nullptr : ssys::getenvvar(spath::Name(geom, "_GDMLPath")) ; 
0465 }
0466 
0467 **/
0468 
0469 
0470 
0471 const char* SOpticksResource::GEOMSub( const char* _geom){  return GEOM_Aux( _geom, "_GEOMSub"  ); }
0472 const char* SOpticksResource::GEOMWrap(const char* _geom){  return GEOM_Aux( _geom, "_GEOMWrap" ); }
0473 const char* SOpticksResource::GEOMList(const char* _geom){  return GEOM_Aux( _geom, "_GEOMList" ); }
0474 
0475 const char* SOpticksResource::GEOM_Aux(const char* _geom, const char* aux)
0476 { 
0477     const char* geom = _geom ? _geom : GEOM() ; 
0478     return geom == nullptr ? nullptr : ssys::getenvvar(spath::Name(geom, aux)) ; 
0479 }
0480 
0481 
0482 
0483 const char* SOpticksResource::KEYS = "IDPath CFBase CFBaseAlt GeocacheDir RuncacheDir RNGDir PrecookedDir DefaultOutputDir SomeGDMLPath GDMLPath GEOMSub GEOMWrap CFBaseFromGEOM UserGEOMDir GEOMList" ; 
0484 
0485 /**
0486 SOpticksResource::Get
0487 -----------------------
0488 
0489 The below keys have default values derived from the OPTICKS_KEY envvars, however
0490 envvars with the same keys can be used to override these defaults. 
0491 
0492 +-------------------------+-----------------------------------------------------+
0493 | key                     |  notes                                              |
0494 +=========================+=====================================================+
0495 |   IDPath                |                                                     |
0496 +-------------------------+-----------------------------------------------------+
0497 |   CFBase                |                                                     |
0498 +-------------------------+-----------------------------------------------------+
0499 |   CFBaseAlt             |                                                     |
0500 +-------------------------+-----------------------------------------------------+
0501 |   GeocacheDir           |                                                     |
0502 +-------------------------+-----------------------------------------------------+
0503 |   RuncacheDir           |                                                     |
0504 +-------------------------+-----------------------------------------------------+
0505 |   RNGDir                |                                                     |
0506 +-------------------------+-----------------------------------------------------+
0507 |   PrecookedDir          |                                                     |
0508 +-------------------------+-----------------------------------------------------+
0509 |   DefaultOutputDir      | eg /tmp/blyth/opticks/GEOM/acyl/ExecutableName      |
0510 +-------------------------+-----------------------------------------------------+
0511 |   DefaultGeometryDir    | eg /tmp/blyth/opticks/GEOM/acyl                     |
0512 +-------------------------+-----------------------------------------------------+
0513 |   DefaultGeometryBase   | eg /tmp/blyth/opticks/GEOM                          |
0514 +-------------------------+-----------------------------------------------------+
0515 |   SomeGDMLPath          |                                                     |
0516 +-------------------------+-----------------------------------------------------+
0517 |   GDMLPath              | GEOM gives Name, Name_GDMLPath gives path           |
0518 +-------------------------+-----------------------------------------------------+
0519 |   CFBaseFromGeom        | GEOM gives Name, Name_CFBaseFromGeom gives dirpath  |
0520 +-------------------------+-----------------------------------------------------+
0521 |   UserGEOMDir           |  eg $HOME/.opticks/GEOM/$GEOM                       |
0522 +-------------------------+-----------------------------------------------------+
0523 
0524 
0525 **/
0526 const char* SOpticksResource::Get(const char* key) // static
0527 {
0528     const char* tok = getenv(key) ;   // can override via envvar, but typically below defaults are used
0529     if(tok) return tok ;  
0530 
0531     if( strcmp(key, "CFBase")==0)                tok = SOpticksResource::CFBase(); 
0532     else if( strcmp(key, "CFBaseAlt")==0)        tok = SOpticksResource::CFBaseAlt(); 
0533     else if( strcmp(key, "GeocacheDir")==0)      tok = SOpticksResource::GeocacheDir(); 
0534     else if( strcmp(key, "RuncacheDir")==0)      tok = SOpticksResource::RuncacheDir(); 
0535     else if( strcmp(key, "RNGDir")==0)           tok = SOpticksResource::RNGDir(); 
0536     else if( strcmp(key, "PrecookedDir")==0)     tok = SOpticksResource::PrecookedDir(); 
0537     else if( strcmp(key, "DefaultOutputDir")==0) tok = SOpticksResource::DefaultOutputDir(); 
0538     else if( strcmp(key, "DefaultGeometryBase")==0) tok = SOpticksResource::DefaultGeometryBase(); 
0539     else if( strcmp(key, "DefaultGeometryDir")==0) tok = SOpticksResource::DefaultGeometryDir(); 
0540     else if( strcmp(key, "SomeGDMLPath")==0)     tok = SOpticksResource::SomeGDMLPath(); 
0541     else if( strcmp(key, "GDMLPathFromGEOM")==0) tok = SOpticksResource::GDMLPathFromGEOM(); 
0542     else if( strcmp(key, "CFBaseFromGEOM")==0)   tok = SOpticksResource::CFBaseFromGEOM(); 
0543     else if( strcmp(key, "UserGEOMDir")==0)      tok = SOpticksResource::UserGEOMDir(); 
0544     return tok ;  
0545 }
0546 
0547 
0548 std::string SOpticksResource::Desc() 
0549 {
0550     std::vector<std::string> keys ; 
0551     SStr::Split(KEYS, ' ', keys); 
0552 
0553     std::stringstream ss ; 
0554     ss << "SOpticksResource::Desc" << std::endl ; 
0555     for(unsigned i=0 ; i < keys.size() ; i++ ) 
0556     {
0557         const char* key = keys[i].c_str() ; 
0558         std::string lab = SStr::Format("SOpticksResource::Get(\"%s\") ", key) ; 
0559         const char* val = Get(key); 
0560         ss 
0561             << std::setw(70) << lab.c_str() 
0562             << " : "
0563             << ( val ? val : "-" ) 
0564             << std::endl 
0565             ;
0566     }
0567 
0568 
0569     
0570 
0571     const char* gdml_key = "$IDPath/origin_GDMLKludge.gdml" ; 
0572 
0573     for(int pass=0 ; pass < 5 ; pass++)
0574     {
0575         switch(pass)
0576         {
0577            case 1: SSys::setenvvar("IDPath", "/some/override/IDPath/via/envvar", true );  break ; 
0578            case 2: SSys::unsetenv("IDPath") ; break ; 
0579            case 3: SSys::setenvvar("IDPath", "/another/override/IDPath/via/envvar", true );  break ; 
0580            case 4: SSys::unsetenv("IDPath") ; break ; 
0581         }
0582         const char* gdml_path = SPath::Resolve(gdml_key, NOOP );
0583         ss 
0584             << std::setw(70) << gdml_key 
0585             << " : "
0586             << ( gdml_path ? gdml_path : "-" )
0587             << std::endl 
0588             ;
0589     }
0590 
0591 
0592 
0593     std::string s = ss.str(); 
0594     return s ; 
0595 }
0596 
0597