musrfit 1.10.0
nxH5::PNXdata< T > Class Template Reference

Template class for storing HDF5 dataset content with attributes. More...

#include <PNeXus.h>

Public Member Functions

 PNXdata ()
 Default constructor.
 
 PNXdata (const H5::DataType &dataType)
 Constructor with datatype.
 
H5::DataType GetDataType () const
 Get the HDF5 DataType.
 
void SetDataType (const H5::DataType &dataType)
 Set the HDF5 DataType.
 
const std::vector< T > & GetData () const
 Get the data as a vector.
 
std::vector< T > & GetData ()
 Get mutable reference to the data vector.
 
void SetData (const std::vector< T > &data)
 Set the data vector.
 
const std::vector< hsize_t > & GetDimensions () const
 Get the dimensions of the dataset.
 
void SetDimensions (const std::vector< hsize_t > &dims)
 Set the dimensions of the dataset.
 
size_t GetRank () const
 Get the number of dimensions.
 
size_t GetNumElements () const
 Get total number of elements.
 
void AddAttribute (const std::string &name, const std::any &value)
 Add an attribute to this dataset.
 
std::any GetAttribute (const std::string &name) const
 Get an attribute by name.
 
bool HasAttribute (const std::string &name) const
 Check if an attribute exists.
 
const std::map< std::string, std::any > & GetAttributes () const
 Get all attributes.
 
std::map< std::string, std::any > & GetAttributes ()
 Get mutable reference to all attributes.
 

Private Attributes

H5::DataType fDataType
 HDF5 datatype of the dataset.
 
std::vector< T > fData
 Data storage (flattened multi-dimensional array)
 
std::vector< hsize_t > fDimensions
 Dimensions of the dataset.
 
std::map< std::string, std::any > fAttributes
 Attributes associated with this dataset.
 

Detailed Description

template<typename T>
class nxH5::PNXdata< T >

Template class for storing HDF5 dataset content with attributes.

The PNXdata class stores data read from an HDF5 dataset along with metadata such as dimensions, datatype, and attributes. It is designed to be stored in std::map<std::string, std::any> where the key is the HDF5 path.

Template Parameters
TThe element type of the dataset (int, float, std::string, etc.)

Key features:

  • Stores multi-dimensional data as flattened std::vector<T>
  • Preserves dimension information (shape)
  • Stores HDF5 DataType for type safety
  • Supports attributes as nested PNXdata objects
  • Compatible with std::any for type-erased storage
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1316 of file PNeXus.h.

Constructor & Destructor Documentation

◆ PNXdata() [1/2]

template<typename T>
nxH5::PNXdata< T >::PNXdata ( )
inline

Default constructor.

Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1321 of file PNeXus.h.

References fDataType.

◆ PNXdata() [2/2]

template<typename T>
nxH5::PNXdata< T >::PNXdata ( const H5::DataType & dataType)
inline

Constructor with datatype.

Parameters
dataTypeHDF5 datatype for this dataset

Definition at line 1327 of file PNeXus.h.

References fDataType.

Member Function Documentation

◆ AddAttribute()

template<typename T>
void nxH5::PNXdata< T >::AddAttribute ( const std::string & name,
const std::any & value )
inline

Add an attribute to this dataset.

Parameters
nameAttribute name
valueAttribute value (stored as std::any to support different types)
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1395 of file PNeXus.h.

References fAttributes.

Referenced by nxH5::PNeXus::ReadDatasetAttributes().

◆ GetAttribute()

template<typename T>
std::any nxH5::PNXdata< T >::GetAttribute ( const std::string & name) const
inline

Get an attribute by name.

Parameters
nameAttribute name
Returns
The attribute value as std::any
Exceptions
std::out_of_rangeif attribute doesn't exist
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1405 of file PNeXus.h.

References fAttributes.

◆ GetAttributes() [1/2]

template<typename T>
std::map< std::string, std::any > & nxH5::PNXdata< T >::GetAttributes ( )
inline

Get mutable reference to all attributes.

Returns
Mutable map of attribute names to values

Definition at line 1430 of file PNeXus.h.

References fAttributes.

◆ GetAttributes() [2/2]

template<typename T>
const std::map< std::string, std::any > & nxH5::PNXdata< T >::GetAttributes ( ) const
inline

Get all attributes.

Returns
Map of attribute names to values
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1422 of file PNeXus.h.

References fAttributes.

Referenced by nxH5::PNeXus::WriteDatasetAttributes().

◆ GetData() [1/2]

template<typename T>
std::vector< T > & nxH5::PNXdata< T >::GetData ( )
inline

Get mutable reference to the data vector.

Returns
Reference to the data vector

Definition at line 1351 of file PNeXus.h.

References fData.

◆ GetData() [2/2]

template<typename T>
const std::vector< T > & nxH5::PNXdata< T >::GetData ( ) const
inline

Get the data as a vector.

Returns
Reference to the data vector
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1345 of file PNeXus.h.

References fData.

Referenced by nxH5::PNeXus::WriteFloatDataset(), nxH5::PNeXus::WriteIntDataset(), and nxH5::PNeXus::WriteStringDataset().

◆ GetDataType()

template<typename T>
H5::DataType nxH5::PNXdata< T >::GetDataType ( ) const
inline

Get the HDF5 DataType.

Returns
The HDF5 DataType for this dataset
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1333 of file PNeXus.h.

References fDataType.

◆ GetDimensions()

template<typename T>
const std::vector< hsize_t > & nxH5::PNXdata< T >::GetDimensions ( ) const
inline

Get the dimensions of the dataset.

Returns
Vector of dimension sizes
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1363 of file PNeXus.h.

References fDimensions.

Referenced by nxH5::PNeXus::WriteFloatDataset(), nxH5::PNeXus::WriteIntDataset(), and nxH5::PNeXus::WriteStringDataset().

◆ GetNumElements()

template<typename T>
size_t nxH5::PNXdata< T >::GetNumElements ( ) const
inline

Get total number of elements.

Returns
Product of all dimensions
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1381 of file PNeXus.h.

References fDimensions.

Referenced by nxH5::PNeXus::WriteFloatDataset(), and nxH5::PNeXus::WriteIntDataset().

◆ GetRank()

template<typename T>
size_t nxH5::PNXdata< T >::GetRank ( ) const
inline

Get the number of dimensions.

Returns
Number of dimensions (rank)
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1375 of file PNeXus.h.

References fDimensions.

◆ HasAttribute()

template<typename T>
bool nxH5::PNXdata< T >::HasAttribute ( const std::string & name) const
inline

Check if an attribute exists.

Parameters
nameAttribute name
Returns
true if attribute exists, false otherwise
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1414 of file PNeXus.h.

References fAttributes.

◆ SetData()

template<typename T>
void nxH5::PNXdata< T >::SetData ( const std::vector< T > & data)
inline

Set the data vector.

Parameters
dataVector of data to store
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1357 of file PNeXus.h.

References fData.

Referenced by nxH5::PNeXus::AddDataset(), nxH5::PNeXus::ReadFloatDataset(), nxH5::PNeXus::ReadIntDataset(), and nxH5::PNeXus::ReadStringDataset().

◆ SetDataType()

template<typename T>
void nxH5::PNXdata< T >::SetDataType ( const H5::DataType & dataType)
inline

Set the HDF5 DataType.

Parameters
dataTypeThe HDF5 DataType to set
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1339 of file PNeXus.h.

References fDataType.

◆ SetDimensions()

template<typename T>
void nxH5::PNXdata< T >::SetDimensions ( const std::vector< hsize_t > & dims)
inline

Set the dimensions of the dataset.

Parameters
dimsVector of dimension sizes
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1369 of file PNeXus.h.

References fDimensions.

Referenced by nxH5::PNeXus::AddDataset(), nxH5::PNeXus::ReadFloatDataset(), nxH5::PNeXus::ReadIntDataset(), and nxH5::PNeXus::ReadStringDataset().

Member Data Documentation

◆ fAttributes

template<typename T>
std::map<std::string, std::any> nxH5::PNXdata< T >::fAttributes
private

Attributes associated with this dataset.

Definition at line 1438 of file PNeXus.h.

Referenced by AddAttribute(), GetAttribute(), GetAttributes(), GetAttributes(), and HasAttribute().

◆ fData

template<typename T>
std::vector<T> nxH5::PNXdata< T >::fData
private

Data storage (flattened multi-dimensional array)

Definition at line 1436 of file PNeXus.h.

Referenced by GetData(), GetData(), and SetData().

◆ fDataType

template<typename T>
H5::DataType nxH5::PNXdata< T >::fDataType
private

HDF5 datatype of the dataset.

Definition at line 1435 of file PNeXus.h.

Referenced by GetDataType(), PNXdata(), PNXdata(), and SetDataType().

◆ fDimensions

template<typename T>
std::vector<hsize_t> nxH5::PNXdata< T >::fDimensions
private

Dimensions of the dataset.

Definition at line 1437 of file PNeXus.h.

Referenced by GetDimensions(), GetNumElements(), GetRank(), and SetDimensions().


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