Skip to content

Context

#include <sbio/core/context.hh>
template<IOTraits IO, class EPolicy>
class Context

Defined 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>();
  • IO The IO policy.

  • EPolicy The Execution policy.

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.

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.

Parameter Type Description
config const EPolicyConfig & The Execution policy configuration.

inline

inline ~Context()

Defined in src/lib/sbio/core/context.hh:136


Context(const Context &) = delete

Defined in src/lib/sbio/core/context.hh:148

Deleted constructor.


Context & operator=(const Context &) = delete

Defined in src/lib/sbio/core/context.hh:149

Deleted assignment operator.


Context(Context &&) = delete

Defined in src/lib/sbio/core/context.hh:150

Deleted constructor.


Context & operator=(Context &&) = delete

Defined in src/lib/sbio/core/context.hh:151

Deleted assignment operator.


const inline

inline bool ok() const

Defined in src/lib/sbio/core/context.hh:156

Whether the Context is valid (EPolicy has been configured.)


const inline

inline const std::string & error() const

Defined in src/lib/sbio/core/context.hh:161

Why the Context is not valid or empty string.


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.

[ok()](#ok).

The DataSource, ready for stream locating.


const inline

inline std::string env(std::string_view key, std::string_view fallback = {}) const

Defined in src/lib/sbio/core/context.hh:258

Retrieve an environment variable, with optional fallback.

The value.

Parameter Type Description
key std::string_view The environment variable name.
fallback std::string_view The value if the variable is not set.

const inline

inline bool has_env(std::string_view key) const

Defined in src/lib/sbio/core/context.hh:273

Whether key is set in the Context overrides or process environment.


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.

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.

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.)

true if supported else false

Parameter Type Description
method ParallelizationMethods The parallelization method

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.

true if the policy can be configured else false.

Parameter Type Description
config const EPolicyConfig & The EPolicy configuration parameters
error std::string & A description of the problem if not a usable compostion.
Name Description
IOPolicy
ExecutionPolicy
EPolicyConfig

using IOPolicy = IO

Defined in src/lib/sbio/core/context.hh:94


using ExecutionPolicy = EPolicy

Defined in src/lib/sbio/core/context.hh:95


using EPolicyConfig = typename EPolicy::Config

Defined in src/lib/sbio/core/context.hh:96

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


bool m_registered { false }

Defined in src/lib/sbio/core/context.hh:305


bool m_io_environment { false }

Defined in src/lib/sbio/core/context.hh:306

Whether this Context holds the IO environment.


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

Return Name Description
constexpr const char * method_name static inline constexpr

static inline constexpr

constexpr static inline constexpr const char * method_name(ParallelizationMethods method)

Defined in src/lib/sbio/core/context.hh:293