File indexing completed on 2026-04-09 07:49:46
0001 #include <cstdio>
0002 #include <cstdlib>
0003 #include <cassert>
0004 #include <cstring>
0005 #include <string>
0006 #include <sstream>
0007
0008 #include "SPath.hh"
0009 #include "SRngSpec.hh"
0010 #include "SLOG.hh"
0011
0012 const plog::Severity SRngSpec::LEVEL = SLOG::EnvLevel("SRngSpec", "DEBUG");
0013
0014 const char* SRngSpec::DefaultRngDir()
0015 {
0016 return SPath::GetHomePath(".opticks/rngcache/RNG") ;
0017 }
0018
0019 const char* SRngSpec::CURANDStatePath(const char* rngdir, unsigned rngmax, unsigned long long seed, unsigned long long offset)
0020 {
0021 char buf[256];
0022
0023 snprintf(buf, 256, "%s/%s_%u_%llu_%llu.bin",
0024 rngdir ? rngdir : DefaultRngDir(),
0025 PREFIX,
0026 rngmax,
0027 seed,
0028 offset);
0029
0030 return strdup(buf) ;
0031 }
0032
0033 SRngSpec::SRngSpec(unsigned rngmax, unsigned long long seed, unsigned long long offset)
0034 :
0035 m_rngmax(rngmax),
0036 m_seed(seed),
0037 m_offset(offset)
0038 {
0039 }
0040
0041 const char* SRngSpec::getCURANDStatePath(const char* rngdir) const
0042 {
0043 return CURANDStatePath(rngdir, m_rngmax, m_seed, m_offset );
0044 }
0045
0046 bool SRngSpec::isValid(const char* rngdir) const
0047 {
0048 const char* path = getCURANDStatePath(rngdir);
0049 bool readable = SPath::IsReadable(path);
0050 LOG_IF(error, !readable)
0051 << " NOT READABLE CURANDStatePath "
0052 << " path " << ( path ? path : "-" )
0053 << " readable " << readable
0054 ;
0055 return readable ;
0056 }
0057
0058 std::string SRngSpec::desc() const
0059 {
0060 std::stringstream ss ;
0061 ss << "SRngSpec"
0062 << " rngmax " << m_rngmax
0063 << " seed " << m_seed
0064 << " offset " << m_offset
0065 ;
0066 return ss.str();
0067 }
0068
0069