Gromacs  2026.0-dev-20251119-5f0a571d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions
gmx::H5mdTimeDataBlock< ValueType > Class Template Reference

#include <gromacs/fileio/h5md/h5md_timedatablock.h>

Description

template<typename ValueType>
class gmx::H5mdTimeDataBlock< ValueType >

Class which manages time-dependent data sets of the templated ValueType.

Time-dependent data in H5md require the coexistance of multiple data sets:

1) A data set for the primary value type that is to be stored, 2) A data set with the simulation step number for each stored value, and 3) (Optionally) A data set with the simulation time for each stored value.

This class manages this set of data sets as one, providing routines for writing new frame data as well as reading existing values, steps or times. New data is written to all data sets as one to keep them synchronized.

Use the H5mdTimeDataBlockBuilder class to construct new objects with certain features. When opening already existing blocks for reading or appending data (i.e. when resuming simulations from checkpoints), use the H5mdTimeDataBlock constructor.

Public Member Functions

 H5mdTimeDataBlock (hid_t container, const char *name)
 
bool hasTime () const
 Return whether or not this block manages a time data set.
 
const DataSetDimsframeDims () const
 Return the frame dimensions of the value data set.
 
int64_t numFrames () const
 Return the number of frames written to the managed data sets.
 
std::optional< int64_t > readStepAtIndex (int64_t frameIndex)
 Return the step value of the given frameIndex. More...
 
std::optional< double > readTimeAtIndex (int64_t frameIndex)
 Return the time value of the given frameIndex. More...
 
bool readValueAtIndex (int64_t frameIndex, ArrayRef< ValueType > values)
 Read the primary value of the given frameIndex into the given buffer if the index exists. More...
 
bool readFrame (int64_t frameIndex, ArrayRef< ValueType > values, int64_t *step, double *time)
 Read the frame at frameIndex into the given buffers if the index exists. More...
 
void writeNextFrame (ArrayRef< const ValueType > values, int64_t step)
 Write given values and step to their data sets as the next frame. More...
 
void writeNextFrame (ArrayRef< const ValueType > values, int64_t step, double time)
 Write given values to all managed data sets as the next frame. More...
 

Member Function Documentation

template<typename ValueType >
bool gmx::H5mdTimeDataBlock< ValueType >::readFrame ( int64_t  frameIndex,
ArrayRef< ValueType >  values,
int64_t *  step,
double *  time 
)

Read the frame at frameIndex into the given buffers if the index exists.

If step or time are nullptr their values are not read. If a time data set is not managed time is never read.

Parameters
[in]frameIndexIndex of frame to read.
[out]valuesBuffer to read values into.
[out]stepBuffer to read step into, or nullptr if not to read.
[out]timeBuffer to read time into, or nullptr if not to read.
Returns
Whether the index is within [0, numFrames) and thus if the frame was read.
Exceptions
FileIOErrorif there was an error reading any value.
template<typename ValueType >
std::optional< int64_t > gmx::H5mdTimeDataBlock< ValueType >::readStepAtIndex ( int64_t  frameIndex)

Return the step value of the given frameIndex.

Parameters
[in]frameIndexIndex of frame to get the value for.
Returns
The step or std::nullopt if frameIndex is not within [0, numFrames).
Exceptions
FileIOErrorif there was an error reading the value.
template<typename ValueType >
std::optional< double > gmx::H5mdTimeDataBlock< ValueType >::readTimeAtIndex ( int64_t  frameIndex)

Return the time value of the given frameIndex.

If the time data set is not managed this always returns std::nullopt.

Parameters
[in]frameIndexIndex of frame to get the value for.
Returns
The time if available, or std::nullopt if frameIndex is not within [0, numFrames).
Exceptions
FileIOErrorif there was an error reading the value.
template<typename ValueType >
bool gmx::H5mdTimeDataBlock< ValueType >::readValueAtIndex ( int64_t  frameIndex,
ArrayRef< ValueType >  values 
)

Read the primary value of the given frameIndex into the given buffer if the index exists.

Parameters
[in]frameIndexIndex of frame to get the value for.
[out]valuesBuffer to read the value into.
Returns
Whether the index is within [0, numframes) and thus if the value was read into the buffer.
Exceptions
FileIOErrorif there was an error reading the value.
template<typename ValueType >
void gmx::H5mdTimeDataBlock< ValueType >::writeNextFrame ( ArrayRef< const ValueType >  values,
int64_t  step 
)

Write given values and step to their data sets as the next frame.

Note
This overload throws if a time data set is managed, and is designed to be used by callers who know that they are not writing times.
Parameters
[in]valuesValues to write.
[in]stepStep to write.
Exceptions
FileIOErrorif there was an error writing the values or if a time data set is managed.
template<typename ValueType >
void gmx::H5mdTimeDataBlock< ValueType >::writeNextFrame ( ArrayRef< const ValueType >  values,
int64_t  step,
double  time 
)

Write given values to all managed data sets as the next frame.

This function works both when a time data set is managed and when it is not. If a time data set is managed the time is written to it. If a time data set is not managed the time is never written, but other values are.

Parameters
[in]valuesValues to write.
[in]stepStep to write.
[in]timeTime to write, if managed.
Exceptions
FileIOErrorif there was an error writing the values.

The documentation for this class was generated from the following files: