CYCLUS
Loading...
Searching...
No Matches
env.h
Go to the documentation of this file.
1#ifndef CYCLUS_SRC_ENV_H_
2#define CYCLUS_SRC_ENV_H_
3
4#include <cstdlib>
5#include <string>
6#include <vector>
7#include "boost/filesystem.hpp"
8
9#include "error.h"
10#include "pyne.h"
11
12// Undefines isnan from pyne
13#ifdef isnan
14 #undef isnan
15#endif
16
17namespace cyclus {
18
19/// @class Env
20/// An environment utility to help locate files and find environment
21/// settings. The environment for a given simulation can be accessed via the
22/// simulation's Context.
23class Env {
24 public:
25 /// splits a string of paths by a delimeter
26 ///
27 /// @param s string of paths
28 /// @param delim the delimeter character
29 /// @param elems the vector of split strings
30 static void SplitPath(const std::string &s, char delim,
31 std::vector<std::string> &elems) {
32 std::stringstream ss(s);
33 std::string item;
34 while (std::getline(ss, item, delim)) {
35 elems.push_back(item);
36 }
37 }
38
39 /// splits a string of paths by a delimeter
40 ///
41 /// @param s string of paths
42 /// @param delim the delimeter character
43 ///
44 /// @return the vector of split strings
45 static std::vector<std::string> SplitPath(const std::string &s, char delim) {
46 std::vector<std::string> elems;
48 return elems;
49 }
50
51 /// the path basis
52 /// @return path with the last item removed
53 static std::string PathBase(std::string path);
54
55 /// The relative path to the root install directory (containing bin, lib, etc.)
56 /// This first checks the path of the cyclus executable itself and then tries
57 /// the install directory given at run time.
58 /// @return the absolute path to the install directory
59 static const std::string GetInstallPath();
60
61 /// The relative path to the root build directory (containing bin, lib, etc.)
62 /// @return the absolute path to the build directory
63 static const std::string GetBuildPath();
64
65 /// Method to check the existence of and return an environment variable
66 /// @param var is the variable to check and return
67 static std::string GetEnv(std::string var);
68
69 /// @return the current value of the data environment variable
70 /// CYCLUS_NUC_DATA
71 static const std::string nuc_data();
72
73 /// Returns the current rng schema. Uses CYCLUS_RNG_SCHEMA env var if
74 /// set; otherwise uses the default install location. If using the default
75 /// location, set flat=true for the default flat schema.
76 static const std::string rng_schema(bool flat = false);
77
78 /// @return the current value of the module environment variable
79 /// CYCLUS_PATH
80 static const std::vector<std::string> cyclus_path();
81
82 /// @return whether or not Cyclus should allow Mixed-Integer Linear Programs
83 /// The default depends on a compile time option DEFAULT_ALLOW_MILPS, but
84 /// may be specified at run time with the ALLOW_MILPS environment variable
85 static const bool allow_milps();
86
87 /// @return the correct environment variable delimiter based on the file system
88 static const std::string EnvDelimiter();
89
90 /// @return the correct path delimiter based on the file system
91 static const std::string PathDelimiter();
92
93 /// Initializes the path to the cyclus_nuc_data.h5 file
94 ///
95 /// By default, it is assumed to be located in the path given by
96 /// GetInstallPath()/share; however, paths in environment variable
97 /// CYCLUS_NUC_DATA are checked first.
98 inline static const void SetNucDataPath() {
100 }
101
102 /// Initializes the path to the nuclear data library to p
103 inline static const void SetNucDataPath(std::string p) {
105 if (!boost::filesystem::exists(p))
106 throw IOError("cyclus_nuc_data.h5 not found at " + p);
107 }
108
109 /// Returns the full path to a module by searching through default install
110 /// and CYCLUS_PATH directories. You may optionally pass in the lib name itself
111 /// without any frills. In this case, Python modules will also be searched.
112 static std::string FindModule(std::string path);
113 static std::string FindModule(std::string path, std::string lib);
114
115 private:
116 /// the cwd path
117 static boost::filesystem::path cwd_;
118
119 /// the install path, cache of results from GetInstallPath()
120 static std::string instdir_;
121};
122
123} // namespace cyclus
124
125#endif // CYCLUS_SRC_ENV_H_
An environment utility to help locate files and find environment settings.
Definition env.h:23
static const std::string rng_schema(bool flat=false)
Returns the current rng schema.
Definition env.cc:120
static const void SetNucDataPath()
Initializes the path to the cyclus_nuc_data.h5 file.
Definition env.h:98
static const std::string GetInstallPath()
The relative path to the root install directory (containing bin, lib, etc.) This first checks the pat...
Definition env.cc:34
static const std::string PathDelimiter()
Definition env.cc:90
static const bool allow_milps()
Definition env.cc:164
static std::string FindModule(std::string path)
Returns the full path to a module by searching through default install and CYCLUS_PATH directories.
Definition env.cc:179
static std::string GetEnv(std::string var)
Method to check the existence of and return an environment variable.
Definition env.cc:74
static std::vector< std::string > SplitPath(const std::string &s, char delim)
splits a string of paths by a delimeter
Definition env.h:45
static std::string PathBase(std::string path)
the path basis
Definition env.cc:25
static const void SetNucDataPath(std::string p)
Initializes the path to the nuclear data library to p.
Definition env.h:103
static const std::string EnvDelimiter()
Definition env.cc:82
static const std::string GetBuildPath()
The relative path to the root build directory (containing bin, lib, etc.)
Definition env.cc:62
static const std::string nuc_data()
Definition env.cc:98
static const std::vector< std::string > cyclus_path()
Definition env.cc:155
static void SplitPath(const std::string &s, char delim, std::vector< std::string > &elems)
splits a string of paths by a delimeter
Definition env.h:30
for failed reading/writing to files, network connections, etc..
Definition error.h:59
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters
std::string NUC_DATA_PATH
Path to the nuc_data.h5 file.
Definition pyne.h:1848