Context
Context
Section titled “Context”#include <sbio/core/context.hh>template<IOTraits IO, class EPolicy>class ContextDefined in src/lib/sbio/core/context.hh:92
The Context constructs DataSources from IO and Execution policies within an environment.
The Context provides a mechanism to check both the compatiblity of the various policies that are being composed (in large part at compile), as well as a central place to handle interactions with the environment.
The Context can record and interface directly with environment variables, which may be needed for locating streams e.g. (not yet implemented with Locator support), as well as various configuration of execution policies.
Compile time checks look for:
- IOCapability
- ParallelSupport
At construction runtime checks include:
- IO::validate_environment for the IO policy (if provided).
- Execution::validate_environment for the execution policy
- E.g. to check MPI thread support level.
Context will only configure the EPolicy once. From the Context DataSources can be created (using a separate constructor that avoids reconfiguration).
sbio::Context<sbio::SyncPOSIXIO, sbio::ThreadedExecution> ctx(ecfg);if (!ctx.ok()) { std::cerr << ctx.error() << std::endl;}auto ds = ctx.data_source<sbio::XTC2Traits>();Template Parameters
Section titled “Template Parameters”-
IOThe IO policy. -
EPolicyThe Execution policy.
Public Methods
Section titled “Public Methods”| Return | Name | Description |
|---|---|---|
Context inline explicit |
Validate the proposed policies within the environment and then configure. | |
~Context inline |
||
Context |
Deleted constructor. | |
Context & |
operator= |
Deleted assignment operator. |
Context |
Deleted constructor. | |
Context & |
operator= |
Deleted assignment operator. |
bool |
ok const inline |
|
const std::string & |
error const inline |
|
DataSource< IO, EPolicy, FTraits > |
data_source const inline requires FormatTraits<FTraits, IO, EPolicy> |
Construct a DataSource from the Context. |
std::string |
env const inline |
Retrieve an environment variable, with optional fallback. |
bool |
has_env const inline |
|
void |
set_env inline |
Provide a specific override for an environment variable that only the Context uses. |
Context
Section titled “Context”inline explicit
inline explicit Context(const EPolicyConfig & config = {})Defined in src/lib/sbio/core/context.hh:108
Validate the proposed policies within the environment and then configure.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
config |
const EPolicyConfig & |
The Execution policy configuration. |
~Context
Section titled “~Context”inline
inline ~Context()Defined in src/lib/sbio/core/context.hh:136
Context
Section titled “Context”Context(const Context &) = deleteDefined in src/lib/sbio/core/context.hh:148
Deleted constructor.
operator=
Section titled “operator=”Context & operator=(const Context &) = deleteDefined in src/lib/sbio/core/context.hh:149
Deleted assignment operator.
Context
Section titled “Context”Context(Context &&) = deleteDefined in src/lib/sbio/core/context.hh:150
Deleted constructor.
operator=
Section titled “operator=”Context & operator=(Context &&) = deleteDefined in src/lib/sbio/core/context.hh:151
Deleted assignment operator.
const inline
inline bool ok() constDefined in src/lib/sbio/core/context.hh:156
Returns
Section titled “Returns”Whether the Context is valid (EPolicy has been configured.)
const inline
inline const std::string & error() constDefined in src/lib/sbio/core/context.hh:161
Returns
Section titled “Returns”Why the Context is not valid or empty string.
data_source
Section titled “data_source”const inline requires FormatTraits<FTraits, IO, EPolicy>
template<class FTraits> inline DataSource< IO, EPolicy, FTraits > data_source() const requires FormatTraits<FTraits, IO, EPolicy>Defined in src/lib/sbio/core/context.hh:242
Construct a DataSource from the Context.
Preconditions
Section titled “Preconditions”[ok()](#ok).
Returns
Section titled “Returns”The DataSource, ready for stream locating.
const inline
inline std::string env(std::string_view key, std::string_view fallback = {}) constDefined in src/lib/sbio/core/context.hh:258
Retrieve an environment variable, with optional fallback.
Returns
Section titled “Returns”The value.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
key |
std::string_view |
The environment variable name. |
fallback |
std::string_view |
The value if the variable is not set. |
has_env
Section titled “has_env”const inline
inline bool has_env(std::string_view key) constDefined in src/lib/sbio/core/context.hh:273
Returns
Section titled “Returns”Whether key is set in the Context overrides or process environment.
set_env
Section titled “set_env”inline
inline void set_env(std::string_view key, std::string_view value)Defined in src/lib/sbio/core/context.hh:288
Provide a specific override for an environment variable that only the Context uses.
Public Static Methods
Section titled “Public Static Methods”| Return | Name | Description |
|---|---|---|
constexpr bool |
supports static inline constexpr |
Check if a particular parallelization method is supported (threads, MPI, etc.) |
bool |
validate_policy static inline |
Check an EPolicy can be used with config, and IOPolicy, in the current env. |
supports
Section titled “supports”static inline constexpr
constexpr static inline constexpr bool supports(ParallelizationMethods method)Defined in src/lib/sbio/core/context.hh:169
Check if a particular parallelization method is supported (threads, MPI, etc.)
Returns
Section titled “Returns”true if supported else false
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
method |
ParallelizationMethods |
The parallelization method |
validate_policy
Section titled “validate_policy”static inline
static inline bool validate_policy(const EPolicyConfig & config, std::string & error)Defined in src/lib/sbio/core/context.hh:201
Check an EPolicy can be used with config, and IOPolicy, in the current env.
Returns
Section titled “Returns”true if the policy can be configured else false.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
config |
const EPolicyConfig & |
The EPolicy configuration parameters |
error |
std::string & |
A description of the problem if not a usable compostion. |
Public Types
Section titled “Public Types”| Name | Description |
|---|---|
IOPolicy |
|
ExecutionPolicy |
|
EPolicyConfig |
IOPolicy
Section titled “IOPolicy”using IOPolicy = IODefined in src/lib/sbio/core/context.hh:94
ExecutionPolicy
Section titled “ExecutionPolicy”using ExecutionPolicy = EPolicyDefined in src/lib/sbio/core/context.hh:95
EPolicyConfig
Section titled “EPolicyConfig”using EPolicyConfig = typename EPolicy::ConfigDefined in src/lib/sbio/core/context.hh:96
Private Attributes
Section titled “Private Attributes”| Return | Name | Description |
|---|---|---|
bool |
m_ok |
|
bool |
m_registered |
|
bool |
m_io_environment |
Whether this Context holds the IO environment. |
std::string |
m_error |
|
std::map< std::string, std::string > |
m_env |
bool m_ok { false }Defined in src/lib/sbio/core/context.hh:304
m_registered
Section titled “m_registered”bool m_registered { false }Defined in src/lib/sbio/core/context.hh:305
m_io_environment
Section titled “m_io_environment”bool m_io_environment { false }Defined in src/lib/sbio/core/context.hh:306
Whether this Context holds the IO environment.
m_error
Section titled “m_error”std::string m_error {}Defined in src/lib/sbio/core/context.hh:307
std::map< std::string, std::string > m_env {}Defined in src/lib/sbio/core/context.hh:308
Private Static Methods
Section titled “Private Static Methods”| Return | Name | Description |
|---|---|---|
constexpr const char * |
method_name static inline constexpr |
method_name
Section titled “method_name”static inline constexpr
constexpr static inline constexpr const char * method_name(ParallelizationMethods method)Defined in src/lib/sbio/core/context.hh:293