Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #pragma once
0002 /**
0003 smeta.h
0004 ==========
0005 
0006 BASH_SOURCE fails to export
0007 
0008 **/
0009 
0010 #include "sproc.h"
0011 #include "ssys.h"
0012 #include "sstamp.h"
0013 
0014 #include "NP.hh"
0015 
0016 struct smeta
0017 {
0018     static constexpr const char* PREFIX = "OPTICKS_" ;
0019     static constexpr const char* VARS = R"(
0020 CVD
0021 CUDA_VISIBLE_DEVICES
0022 HOME
0023 USER
0024 SCRIPT
0025 PWD
0026 CMDLINE
0027 CHECK
0028 LAYOUT
0029 TEST
0030 VERSION
0031 GEOM
0032 EXECUTABLE
0033 COMMANDLINE
0034 DIRECTORY
0035 ${GEOM}_GEOMList
0036 )" ;
0037 // HIGHER ORDER KEYS WITH TOKENS ARE HANDLED IN ssys::_getenv
0038     static void Collect(std::string& meta, const char* source=nullptr, bool stamp=false) ;
0039     static void CollectEnv(std::string& meta ) ;
0040 };
0041 
0042 /**
0043 smeta::Collect
0044 ----------------
0045 
0046 This is used for example to populate (SEvt)sevt.meta by:
0047 
0048 1. G4CXOpticks::init_SEvt for SEvt::EGPU meta
0049 2. U4Recorder::init_SEvt for SEvt::ECPU meta
0050 3. CSGFoundry::init for the CSGFoundry::meta
0051 
0052 **/
0053 
0054 inline void smeta::Collect(std::string& meta, const char* source, bool stamp )
0055 {
0056     if(stamp)
0057     {
0058         uint64_t t = sstamp::Now();
0059         std::string tf = sstamp::Format(t) ;
0060         NP::SetMeta<uint64_t>(meta, "_init_stamp", t);
0061         NP::SetMeta<std::string>(meta, "_init_stamp_Fmt", tf);
0062     }
0063 
0064     if(source) NP::SetMeta<std::string>(meta, "source", source );
0065     NP::SetMeta<std::string>(meta, "creator", sproc::ExecutableName() );
0066     NP::SetMeta<std::string>(meta, "uname", ssys::uname("-a"));
0067     CollectEnv(meta);
0068 }
0069 
0070 /**
0071 smeta::CollectEnv
0072 -------------------
0073 
0074 TODO: collect all envvars starting with prefix OPTICKS_
0075 
0076 **/
0077 
0078 inline void smeta::CollectEnv(std::string& meta )
0079 {
0080     typedef std::pair<std::string, std::string> KV ;
0081     std::vector<KV> kvs0 ;
0082     ssys::getenv_(kvs0, VARS);
0083     NP::SetMetaKV(meta, kvs0);
0084 
0085     std::vector<KV> kvs1 ;
0086     ssys::getenv_with_prefix(kvs1, PREFIX);
0087     NP::SetMetaKV(meta, kvs1);
0088 }
0089 
0090 
0091