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

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

#include <PNeXus.h>

Public Member Functions

 PNXdata ()
 Default constructor.
 
 PNXdata (const H4DataType &dataType)
 Constructor with datatype.
 
H4DataType GetDataType () const
 Get the HDF4 DataType.
 
void SetDataType (const H4DataType &dataType)
 Set the HDF4 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< uint32_t > & GetDimensions () const
 Get the dimensions of the dataset.
 
void SetDimensions (const std::vector< uint32_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

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

Detailed Description

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

Template class for storing HDF4 dataset content with attributes.

The PNXdata class stores data read from an HDF4 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 HDF4 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 HDF4 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 370 of file PNeXus.h.

Constructor & Destructor Documentation

◆ PNXdata() [1/2]

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

Default constructor.

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

Definition at line 375 of file PNeXus.h.

References fDataType, and nxH4::kINT32.

◆ PNXdata() [2/2]

template<typename T>
nxH4::PNXdata< T >::PNXdata ( const H4DataType & dataType)
inline

Constructor with datatype.

Parameters
dataTypeHDF4 datatype for this dataset

Definition at line 381 of file PNeXus.h.

References fDataType.

Member Function Documentation

◆ AddAttribute()

template<typename T>
void nxH4::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 449 of file PNeXus.h.

References fAttributes.

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

◆ GetAttribute()

template<typename T>
std::any nxH4::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 459 of file PNeXus.h.

References fAttributes.

◆ GetAttributes() [1/2]

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

Get mutable reference to all attributes.

Returns
Mutable map of attribute names to values

Definition at line 484 of file PNeXus.h.

References fAttributes.

◆ GetAttributes() [2/2]

template<typename T>
const std::map< std::string, std::any > & nxH4::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 476 of file PNeXus.h.

References fAttributes.

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

◆ GetData() [1/2]

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

Get mutable reference to the data vector.

Returns
Reference to the data vector

Definition at line 405 of file PNeXus.h.

References fData.

◆ GetData() [2/2]

template<typename T>
const std::vector< T > & nxH4::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 399 of file PNeXus.h.

References fData.

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

◆ GetDataType()

template<typename T>
H4DataType nxH4::PNXdata< T >::GetDataType ( ) const
inline

Get the HDF4 DataType.

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

Definition at line 387 of file PNeXus.h.

References fDataType.

◆ GetDimensions()

template<typename T>
const std::vector< uint32_t > & nxH4::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 417 of file PNeXus.h.

References fDimensions.

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

◆ GetNumElements()

template<typename T>
size_t nxH4::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 435 of file PNeXus.h.

References fDimensions.

◆ GetRank()

template<typename T>
size_t nxH4::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 429 of file PNeXus.h.

References fDimensions.

◆ HasAttribute()

template<typename T>
bool nxH4::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 468 of file PNeXus.h.

References fAttributes.

◆ SetData()

template<typename T>
void nxH4::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 411 of file PNeXus.h.

References fData.

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

◆ SetDataType()

template<typename T>
void nxH4::PNXdata< T >::SetDataType ( const H4DataType & dataType)
inline

Set the HDF4 DataType.

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

Definition at line 393 of file PNeXus.h.

References fDataType.

◆ SetDimensions()

template<typename T>
void nxH4::PNXdata< T >::SetDimensions ( const std::vector< uint32_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 423 of file PNeXus.h.

References fDimensions.

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

Member Data Documentation

◆ fAttributes

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

Attributes associated with this dataset.

Definition at line 492 of file PNeXus.h.

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

◆ fData

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

Data storage (flattened multi-dimensional array)

Definition at line 490 of file PNeXus.h.

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

◆ fDataType

template<typename T>
H4DataType nxH4::PNXdata< T >::fDataType
private

HDF4 datatype of the dataset.

Definition at line 489 of file PNeXus.h.

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

◆ fDimensions

template<typename T>
std::vector<uint32_t> nxH4::PNXdata< T >::fDimensions
private

Dimensions of the dataset.

Definition at line 491 of file PNeXus.h.

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


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