musrfit 1.10.0
nxH5::PNeXus Class Reference

NeXus HDF5 file reader with case-insensitive path lookup. More...

#include <PNeXus.h>

Public Member Functions

 PNeXus ()
 
 PNeXus (const std::string fln, const bool printDebug=false)
 
std::string GetFileName () const
 Get the filename of the NeXus file.
 
std::string GetHdf5LibVersion () const
 Get the HDF5 library version string.
 
std::string GetHdf5Version () const
 Get the HDF5 version string from the file.
 
std::string GetNeXusVersion () const
 Get the NeXus version of the file.
 
int GetIdfVersion () const
 Get the Idf version of the file.
 
int ReadNexusFile ()
 Read and parse the NeXus HDF5 file.
 
const std::map< std::string, std::any > & GetDataMap () const
 Get the data map containing all datasets.
 
std::map< std::string, std::any > & GetDataMap ()
 Get mutable reference to the data map.
 
bool HasDataset (const std::string &path) const
 Check if a dataset path exists in the data map.
 
template<typename T>
void SetDataset (const std::string &path, const PNXdata< T > &data)
 Add or update a dataset in the data map.
 
template<typename T>
PNXdata< T > GetDataset (const std::string &path) const
 Get a dataset from the data map.
 
template<typename T>
PNXdata< T > & GetDatasetRef (const std::string &path)
 Get a mutable reference to a dataset in the data map.
 
bool RemoveDataset (const std::string &path)
 Remove a dataset from the data map.
 
void ClearDataMap ()
 Clear all datasets from the data map.
 
size_t GetNumDatasets () const
 Get the number of datasets in the data map.
 
template<typename T>
bool UpdateDatasetData (const std::string &path, const std::vector< T > &newData)
 Update the data of an existing dataset.
 
template<typename T>
bool UpdateDatasetDimensions (const std::string &path, const std::vector< hsize_t > &newDimensions)
 Update the dimensions of an existing dataset.
 
template<typename T>
bool AddDatasetAttribute (const std::string &path, const std::string &attrName, const std::any &attrValue)
 Add or update an attribute for a dataset.
 
template<typename T>
bool RemoveDatasetAttribute (const std::string &path, const std::string &attrName)
 Remove an attribute from a dataset.
 
template<typename T>
bool AddDataset (const std::string &path, const std::vector< T > &data, const std::vector< hsize_t > &dimensions, const H5::DataType &dataType=H5::PredType::NATIVE_INT)
 Create and add a new dataset with data, dimensions, and optional attributes.
 
template<typename T>
bool ModifyDataset (const std::string &path, const std::vector< T > &newData, const std::vector< hsize_t > &newDimensions)
 Modify an existing dataset's data and dimensions.
 
void Dump ()
 
int WriteNexusFile (const std::string &filename, int idfVersion=2)
 
bool AddGroupAttribute (const std::string &groupPath, const std::string &attrName, const std::any &attrValue)
 
bool RemoveGroupAttribute (const std::string &groupPath, const std::string &attrName)
 Remove an attribute from a group.
 
bool HasGroupAttribute (const std::string &groupPath, const std::string &attrName) const
 Check if a group has a specific attribute.
 
std::any GetGroupAttribute (const std::string &groupPath, const std::string &attrName) const
 Get an attribute value from a group.
 
const std::map< std::string, std::any > & GetGroupAttributes (const std::string &groupPath) const
 Get all attributes for a group.
 
bool ClearGroupAttributes (const std::string &groupPath)
 Clear all attributes from a group.
 
bool AddRootAttribute (const std::string &attrName, const std::any &attrValue)
 

Private Member Functions

void HandleIdfV1 (H5::H5File &file)
 Read datasets for IDF version 1 file structure.
 
void HandleIdfV2 (H5::H5File &file)
 Read datasets for IDF version 2 file structure.
 
H5::Group CreateGroupHierarchy (H5::H5File &file, const std::string &path)
 Create nested group hierarchy for a given path.
 
template<typename T>
void WriteDatasetAttributes (H5::DataSet &dataset, const PNXdata< T > &data)
 Write dataset attributes from PNXdata object.
 
void WriteGroupAttributes (H5::Group &group, const std::map< std::string, std::any > &attributes)
 Write attributes to a group.
 
void WriteIntDataset (H5::H5File &file, const std::string &path, const PNXdata< int > &data)
 Write an integer dataset with attributes.
 
void WriteFloatDataset (H5::H5File &file, const std::string &path, const PNXdata< float > &data)
 Write a float dataset with attributes.
 
void WriteStringDataset (H5::H5File &file, const std::string &path, const PNXdata< std::string > &data)
 Write a string dataset with attributes.
 
void WriteFileAttributes (H5::H5File &file)
 Write root-level file attributes.
 
std::string FindAttributeName (H5::H5File &obj, const std::string &requestedName)
 
std::string FindGroupPath (H5::H5File &parent, const std::string &requestedPath)
 
std::string FindGroupPath (H5::Group &parent, const std::string &requestedPath)
 Find group path with case-insensitive matching (Group version)
 
std::string FindDatasetPath (H5::H5File &parent, const std::string &requestedPath)
 
std::string FindDatasetPath (H5::Group &parent, const std::string &requestedPath)
 Find dataset path with case-insensitive matching (Group version)
 
void ReadIntDataset (H5::H5File &file, const std::string &path)
 Read an integer dataset and store in data map.
 
void ReadFloatDataset (H5::H5File &file, const std::string &path)
 Read a float dataset and store in data map.
 
void ReadStringDataset (H5::H5File &file, const std::string &path)
 Read a string dataset and store in data map.
 
template<typename T>
void ReadDatasetAttributes (H5::DataSet &dataset, PNXdata< T > &data)
 Read dataset attributes and add to PNXdata object.
 

Static Private Member Functions

static bool CaseInsensitiveEquals (const std::string &a, const std::string &b)
 Compare two strings case-insensitively.
 
static std::vector< std::string > SplitPath (const std::string &path)
 

Private Attributes

bool fPrintDebug {false}
 if true print additional debug information
 
std::string fFileName {""}
 NeXus HDF5 filename.
 
int fIdfVersion {-1}
 IDF version of the NeXus file.
 
std::string fHdf5LibVersion {"n/a"}
 HDF5 library version used when calling PNeXus.
 
std::string fHdf5Version {""}
 HDF5 version of the file.
 
std::string fNeXusVersion {""}
 NeXus version of the file.
 
std::string fFileNameNxs {""}
 
std::string fFileTimeNxs {""}
 
std::string fCreatorNxs {""}
 
std::string fUserV1 {""}
 
std::map< std::string, std::any > fDataMap
 Map of HDF5 paths to PNXdata objects.
 
std::map< std::string, std::map< std::string, std::any > > fGroupAttributes
 Map of group paths to their attributes.
 

Detailed Description

NeXus HDF5 file reader with case-insensitive path lookup.

The PNeXus class provides functionality for reading ISIS muon NeXus HDF5 files using the HDF5 C++ API. It implements case-insensitive path lookup for datasets, groups, and attributes to handle files with varying path casings.

Key features:

  • Automatic file reading upon construction
  • Case-insensitive path resolution for datasets and groups
  • Case-insensitive attribute name matching
  • Comprehensive exception handling with HDF5 C++ exceptions
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1463 of file PNeXus.h.

Constructor & Destructor Documentation

◆ PNeXus() [1/2]

◆ PNeXus() [2/2]

nxH5::PNeXus::PNeXus ( const std::string fln,
const bool printDebug = false )

Definition at line 3490 of file PNeXus.cpp.

References fFileName, fHdf5LibVersion, fPrintDebug, ReadNexusFile(), and status.

Member Function Documentation

◆ AddDataset()

template<typename T>
bool nxH5::PNeXus::AddDataset ( const std::string & path,
const std::vector< T > & data,
const std::vector< hsize_t > & dimensions,
const H5::DataType & dataType = H5::PredType::NATIVE_INT )
inline

Create and add a new dataset with data, dimensions, and optional attributes.

Template Parameters
TData type of the PNXdata object
Parameters
pathHDF5 path for the new dataset
dataData vector
dimensionsDimensions vector
dataTypeHDF5 DataType (optional, uses default if not provided)
Returns
true if dataset was created, false if path already exists
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1723 of file PNeXus.h.

References fDataMap, HasDataset(), nxH5::PNXdata< T >::SetData(), and nxH5::PNXdata< T >::SetDimensions().

◆ AddDatasetAttribute()

template<typename T>
bool nxH5::PNeXus::AddDatasetAttribute ( const std::string & path,
const std::string & attrName,
const std::any & attrValue )
inline

Add or update an attribute for a dataset.

Template Parameters
TData type of the PNXdata object
Parameters
pathHDF5 path of the dataset
attrNameAttribute name
attrValueAttribute value (stored as std::any)
Returns
true if attribute was added, false if dataset doesn't exist
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1677 of file PNeXus.h.

References fDataMap, and HasDataset().

◆ AddGroupAttribute()

bool nxH5::PNeXus::AddGroupAttribute ( const std::string & groupPath,
const std::string & attrName,
const std::any & attrValue )

Add or update an attribute for a group.

Parameters
groupPathHDF5 path of the group (e.g., "/raw_data_1")
attrNameAttribute name
attrValueAttribute value (stored as std::any)
Returns
true if attribute was added successfully
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 5605 of file PNeXus.cpp.

References fGroupAttributes.

Referenced by AddRootAttribute().

◆ AddRootAttribute()

bool nxH5::PNeXus::AddRootAttribute ( const std::string & attrName,
const std::any & attrValue )

Add or update an attribute at the root level "/". This is a convenience method that calls AddGroupAttribute("/", attrName, attrValue).

Parameters
attrNameAttribute name
attrValueAttribute value (stored as std::any)
Returns
true if attribute was added successfully
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 5712 of file PNeXus.cpp.

References AddGroupAttribute().

◆ CaseInsensitiveEquals()

bool nxH5::PNeXus::CaseInsensitiveEquals ( const std::string & a,
const std::string & b )
staticprivate

Compare two strings case-insensitively.

Parameters
aFirst string to compare
bSecond string to compare
Returns
true if strings are equal (ignoring case), false otherwise
Note
Uses std::tolower for character-by-character comparison
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 3015 of file PNeXus.cpp.

Referenced by FindAttributeName(), FindDatasetPath(), FindDatasetPath(), FindGroupPath(), and FindGroupPath().

◆ ClearDataMap()

void nxH5::PNeXus::ClearDataMap ( )
inline

Clear all datasets from the data map.

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

Definition at line 1622 of file PNeXus.h.

References fDataMap.

◆ ClearGroupAttributes()

bool nxH5::PNeXus::ClearGroupAttributes ( const std::string & groupPath)

Clear all attributes from a group.

Parameters
groupPathHDF5 path of the group
Returns
true if group was found and attributes cleared, false otherwise

Clear all attributes from a group.

Parameters
groupPathHDF5 path of the group
Returns
true if group was found and attributes cleared, false otherwise
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 5693 of file PNeXus.cpp.

References fGroupAttributes.

◆ CreateGroupHierarchy()

H5::Group nxH5::PNeXus::CreateGroupHierarchy ( H5::H5File & file,
const std::string & path )
private

Create nested group hierarchy for a given path.

Parameters
fileHDF5 file object
pathFull path (e.g., "/raw_data_1/detector_1")
Returns
H5::Group handle to the deepest created/opened group
Exceptions
H5::GroupIExceptionif group creation fails

Create nested group hierarchy for a given path. Groups are created recursively if they don't exist. If a group already exists, it is opened and returned.

Parameters
fileHDF5 file object
pathFull path (e.g., "/raw_data_1/detector_1")
Returns
H5::Group handle to the deepest created/opened group
Exceptions
H5::GroupIExceptionif group creation fails
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 5027 of file PNeXus.cpp.

References fGroupAttributes, fPrintDebug, SplitPath(), and WriteGroupAttributes().

Referenced by WriteFloatDataset(), WriteIntDataset(), and WriteStringDataset().

◆ Dump()

◆ FindAttributeName()

std::string nxH5::PNeXus::FindAttributeName ( H5::H5File & obj,
const std::string & requestedName )
private

◆ FindDatasetPath() [1/2]

std::string nxH5::PNeXus::FindDatasetPath ( H5::Group & parent,
const std::string & requestedPath )
private

Find dataset path with case-insensitive matching (Group version)

Parameters
parentHDF5 Group object to start search from
requestedPathRequested dataset path (any case)
Returns
Correctly-cased dataset path as it exists in the file
Exceptions
H5::DataSetIExceptionif dataset not found or path invalid
Note
Validates that final path component is actually a dataset

Definition at line 3372 of file PNeXus.cpp.

References CaseInsensitiveEquals(), and SplitPath().

◆ FindDatasetPath() [2/2]

std::string nxH5::PNeXus::FindDatasetPath ( H5::H5File & parent,
const std::string & requestedPath )
private

◆ FindGroupPath() [1/2]

std::string nxH5::PNeXus::FindGroupPath ( H5::Group & parent,
const std::string & requestedPath )
private

Find group path with case-insensitive matching (Group version)

Parameters
parentHDF5 Group object to start search from
requestedPathRequested group path (any case)
Returns
Correctly-cased group path as it exists in the file
Exceptions
H5::GroupIExceptionif group not found or path invalid

Definition at line 3200 of file PNeXus.cpp.

References CaseInsensitiveEquals(), and SplitPath().

◆ FindGroupPath() [2/2]

std::string nxH5::PNeXus::FindGroupPath ( H5::H5File & parent,
const std::string & requestedPath )
private

◆ GetDataMap() [1/2]

std::map< std::string, std::any > & nxH5::PNeXus::GetDataMap ( )
inline

Get mutable reference to the data map.

Returns
Reference to the data map

Definition at line 1559 of file PNeXus.h.

References fDataMap.

◆ GetDataMap() [2/2]

const std::map< std::string, std::any > & nxH5::PNeXus::GetDataMap ( ) const
inline

Get the data map containing all datasets.

Returns
Reference to the data map (path -> PNXdata stored in std::any)
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1553 of file PNeXus.h.

References fDataMap.

◆ GetDataset()

template<typename T>
PNXdata< T > nxH5::PNeXus::GetDataset ( const std::string & path) const
inline

Get a dataset from the data map.

Template Parameters
TData type of the PNXdata object
Parameters
pathHDF5 path of the dataset
Returns
PNXdata object
Exceptions
std::out_of_rangeif path doesn't exist
std::bad_any_castif type T doesn't match stored type
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1588 of file PNeXus.h.

References fDataMap.

◆ GetDatasetRef()

template<typename T>
PNXdata< T > & nxH5::PNeXus::GetDatasetRef ( const std::string & path)
inline

Get a mutable reference to a dataset in the data map.

Template Parameters
TData type of the PNXdata object
Parameters
pathHDF5 path of the dataset
Returns
Reference to PNXdata object
Exceptions
std::out_of_rangeif path doesn't exist
std::bad_any_castif type T doesn't match stored type
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1601 of file PNeXus.h.

References fDataMap.

◆ GetFileName()

std::string nxH5::PNeXus::GetFileName ( ) const
inline

Get the filename of the NeXus file.

Returns
The filename as a string
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1514 of file PNeXus.h.

References fFileName.

◆ GetGroupAttribute()

std::any nxH5::PNeXus::GetGroupAttribute ( const std::string & groupPath,
const std::string & attrName ) const

Get an attribute value from a group.

Parameters
groupPathHDF5 path of the group
attrNameAttribute name
Returns
The attribute value as std::any
Exceptions
std::out_of_rangeif group or attribute doesn't exist

Get an attribute value from a group.

Parameters
groupPathHDF5 path of the group
attrNameAttribute name
Returns
The attribute value as std::any
Exceptions
std::out_of_rangeif group or attribute doesn't exist
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 5666 of file PNeXus.cpp.

References fGroupAttributes.

◆ GetGroupAttributes()

const std::map< std::string, std::any > & nxH5::PNeXus::GetGroupAttributes ( const std::string & groupPath) const

Get all attributes for a group.

Parameters
groupPathHDF5 path of the group
Returns
Map of attribute names to values

Get all attributes for a group.

Parameters
groupPathHDF5 path of the group
Returns
Map of attribute names to values
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 5677 of file PNeXus.cpp.

References fGroupAttributes.

◆ GetHdf5LibVersion()

std::string nxH5::PNeXus::GetHdf5LibVersion ( ) const
inline

Get the HDF5 library version string.

Returns
The HDF5 version as a string (e.g., "1.10.4")
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1520 of file PNeXus.h.

References fHdf5LibVersion.

◆ GetHdf5Version()

std::string nxH5::PNeXus::GetHdf5Version ( ) const
inline

Get the HDF5 version string from the file.

Returns
The HDF5 version as a string (e.g., "1.10.4")
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1526 of file PNeXus.h.

References fHdf5Version.

◆ GetIdfVersion()

int nxH5::PNeXus::GetIdfVersion ( ) const
inline

Get the Idf version of the file.

Returns
The Idf version tag
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1538 of file PNeXus.h.

References fIdfVersion.

◆ GetNeXusVersion()

std::string nxH5::PNeXus::GetNeXusVersion ( ) const
inline

Get the NeXus version of the file.

Returns
The NeXus version as a string
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1532 of file PNeXus.h.

References fNeXusVersion.

◆ GetNumDatasets()

size_t nxH5::PNeXus::GetNumDatasets ( ) const
inline

Get the number of datasets in the data map.

Returns
Number of datasets stored
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1628 of file PNeXus.h.

References fDataMap.

◆ HandleIdfV1()

void nxH5::PNeXus::HandleIdfV1 ( H5::H5File & file)
private

Read datasets for IDF version 1 file structure.

Reads datasets specific to the IDF version 1 NeXus format, which uses a "/run/" group hierarchy. Datasets are organized under paths like:

  • /run/IDF_version, /run/number, /run/title
  • /run/sample/temperature, /run/sample/magnetic_field
  • /run/histogram_data_1/counts, /run/histogram_data_1/raw_time
Parameters
fileHDF5 file object to read from
Note
IDF v1 is an older format primarily used by ISIS facilities
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 3631 of file PNeXus.cpp.

References FindAttributeName(), fPrintDebug, fUserV1, ReadFloatDataset(), ReadIntDataset(), and ReadStringDataset().

Referenced by ReadNexusFile().

◆ HandleIdfV2()

void nxH5::PNeXus::HandleIdfV2 ( H5::H5File & file)
private

Read datasets for IDF version 2 file structure.

Reads datasets specific to the IDF version 2 NeXus format, which uses a "/raw_data_1/" group hierarchy. Datasets are organized under paths like:

  • /raw_data_1/IDF_version, /raw_data_1/run_number, /raw_data_1/title
  • /raw_data_1/instrument/detector_1/counts
  • /raw_data_1/instrument/detector_1/resolution
Parameters
fileHDF5 file object to read from
Note
IDF v2 is the current standard format for ISIS muon NeXus files
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 3693 of file PNeXus.cpp.

References fFileNameNxs, fFileTimeNxs, FindAttributeName(), fPrintDebug, ReadFloatDataset(), ReadIntDataset(), and ReadStringDataset().

Referenced by ReadNexusFile().

◆ HasDataset()

bool nxH5::PNeXus::HasDataset ( const std::string & path) const
inline

Check if a dataset path exists in the data map.

Parameters
pathHDF5 path to check
Returns
true if path exists, false otherwise
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1566 of file PNeXus.h.

References fDataMap.

Referenced by AddDataset(), AddDatasetAttribute(), ModifyDataset(), RemoveDatasetAttribute(), UpdateDatasetData(), and UpdateDatasetDimensions().

◆ HasGroupAttribute()

bool nxH5::PNeXus::HasGroupAttribute ( const std::string & groupPath,
const std::string & attrName ) const

Check if a group has a specific attribute.

Parameters
groupPathHDF5 path of the group
attrNameAttribute name to check
Returns
true if attribute exists, false otherwise

Check if a group has a specific attribute.

Parameters
groupPathHDF5 path of the group
attrNameAttribute name to check
Returns
true if attribute exists, false otherwise
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 5648 of file PNeXus.cpp.

References fGroupAttributes.

◆ ModifyDataset()

template<typename T>
bool nxH5::PNeXus::ModifyDataset ( const std::string & path,
const std::vector< T > & newData,
const std::vector< hsize_t > & newDimensions )
inline

Modify an existing dataset's data and dimensions.

Template Parameters
TData type of the PNXdata object
Parameters
pathHDF5 path of the dataset
newDataNew data vector
newDimensionsNew dimensions vector
Returns
true if modification succeeded, false if path doesn't exist
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1743 of file PNeXus.h.

References fDataMap, and HasDataset().

◆ ReadDatasetAttributes()

template<typename T>
void nxH5::PNeXus::ReadDatasetAttributes ( H5::DataSet & dataset,
PNXdata< T > & data )
private

Read dataset attributes and add to PNXdata object.

Template Parameters
TThe data type of the PNXdata object
Parameters
datasetHDF5 dataset object
dataPNXdata object to add attributes to

Reads all attributes from an HDF5 dataset and adds them to a PNXdata object. Attributes can be integers, floats, or strings.

Template Parameters
TThe data type of the PNXdata object
Parameters
datasetHDF5 dataset object
dataPNXdata object to add attributes to
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 4971 of file PNeXus.cpp.

References nxH5::PNXdata< T >::AddAttribute(), and fPrintDebug.

Referenced by ReadFloatDataset(), ReadIntDataset(), and ReadStringDataset().

◆ ReadFloatDataset()

void nxH5::PNeXus::ReadFloatDataset ( H5::H5File & file,
const std::string & path )
private

Read a float dataset and store in data map.

Parameters
fileHDF5 file object
pathPath to the dataset
Exceptions
H5::Exceptionif reading fails

Reads a float dataset from the HDF5 file and stores it in the data map. Handles multi-dimensional datasets by flattening them into a vector.

Parameters
fileHDF5 file object
pathPath to the dataset
Exceptions
H5::Exceptionif reading fails
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 4835 of file PNeXus.cpp.

References fDataMap, FindDatasetPath(), fPrintDebug, ReadDatasetAttributes(), nxH5::PNXdata< T >::SetData(), and nxH5::PNXdata< T >::SetDimensions().

Referenced by HandleIdfV1(), and HandleIdfV2().

◆ ReadIntDataset()

void nxH5::PNeXus::ReadIntDataset ( H5::H5File & file,
const std::string & path )
private

Read an integer dataset and store in data map.

Parameters
fileHDF5 file object
pathPath to the dataset
Exceptions
H5::Exceptionif reading fails

Reads an integer dataset from the HDF5 file and stores it in the data map. Handles multi-dimensional datasets by flattening them into a vector.

Parameters
fileHDF5 file object
pathPath to the dataset
Exceptions
H5::Exceptionif reading fails
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 4769 of file PNeXus.cpp.

References fDataMap, FindDatasetPath(), fPrintDebug, ReadDatasetAttributes(), nxH5::PNXdata< T >::SetData(), and nxH5::PNXdata< T >::SetDimensions().

Referenced by HandleIdfV1(), and HandleIdfV2().

◆ ReadNexusFile()

int nxH5::PNeXus::ReadNexusFile ( )

Read and parse the NeXus HDF5 file.

Returns
0 on success, 1 on error
Exceptions
H5::FileIExceptionif file cannot be opened
H5::AttributeIExceptionif required attributes are missing
H5::DataSetIExceptionif required datasets are missing

Reads and parses the NeXus HDF5 file. Opens the file in read-only mode, loads the NeXus version attribute, and reads the IDF version dataset. Uses case-insensitive path lookup to handle varying path casings.

Returns
0 on success, 1 on error
Exceptions
H5::FileIExceptionif file cannot be opened
H5::AttributeIExceptionif NeXus_version attribute is missing
H5::DataSetIExceptionif IDF_version dataset is missing
Note
This method is called automatically by the constructor. It performs case-insensitive lookups for both attributes and datasets to handle NeXus files with varying naming conventions.
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 3531 of file PNeXus.cpp.

References fFileName, fHdf5Version, fIdfVersion, FindAttributeName(), FindDatasetPath(), fNeXusVersion, fPrintDebug, HandleIdfV1(), and HandleIdfV2().

Referenced by PNeXus().

◆ ReadStringDataset()

void nxH5::PNeXus::ReadStringDataset ( H5::H5File & file,
const std::string & path )
private

Read a string dataset and store in data map.

Parameters
fileHDF5 file object
pathPath to the dataset
Exceptions
H5::Exceptionif reading fails

Reads a string dataset from the HDF5 file and stores it in the data map.

Parameters
fileHDF5 file object
pathPath to the dataset
Exceptions
H5::Exceptionif reading fails
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 4900 of file PNeXus.cpp.

References fDataMap, FindDatasetPath(), fPrintDebug, ReadDatasetAttributes(), nxH5::PNXdata< T >::SetData(), and nxH5::PNXdata< T >::SetDimensions().

Referenced by HandleIdfV1(), and HandleIdfV2().

◆ RemoveDataset()

bool nxH5::PNeXus::RemoveDataset ( const std::string & path)
inline

Remove a dataset from the data map.

Parameters
pathHDF5 path of the dataset to remove
Returns
true if dataset was removed, false if path didn't exist
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1610 of file PNeXus.h.

References fDataMap.

◆ RemoveDatasetAttribute()

template<typename T>
bool nxH5::PNeXus::RemoveDatasetAttribute ( const std::string & path,
const std::string & attrName )
inline

Remove an attribute from a dataset.

Template Parameters
TData type of the PNXdata object
Parameters
pathHDF5 path of the dataset
attrNameAttribute name to remove
Returns
true if attribute was removed, false if dataset doesn't exist or attribute not found
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1697 of file PNeXus.h.

References fDataMap, and HasDataset().

◆ RemoveGroupAttribute()

bool nxH5::PNeXus::RemoveGroupAttribute ( const std::string & groupPath,
const std::string & attrName )

Remove an attribute from a group.

Parameters
groupPathHDF5 path of the group
attrNameAttribute name to remove
Returns
true if attribute was removed, false if group or attribute not found

Remove an attribute from a group.

Parameters
groupPathHDF5 path of the group
attrNameAttribute name to remove
Returns
true if attribute was removed, false if group or attribute not found
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 5619 of file PNeXus.cpp.

References fGroupAttributes.

◆ SetDataset()

template<typename T>
void nxH5::PNeXus::SetDataset ( const std::string & path,
const PNXdata< T > & data )
inline

Add or update a dataset in the data map.

Template Parameters
TData type of the PNXdata object
Parameters
pathHDF5 path for the dataset
dataPNXdata object to store
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1575 of file PNeXus.h.

References fDataMap.

◆ SplitPath()

std::vector< std::string > nxH5::PNeXus::SplitPath ( const std::string & path)
staticprivate

◆ UpdateDatasetData()

template<typename T>
bool nxH5::PNeXus::UpdateDatasetData ( const std::string & path,
const std::vector< T > & newData )
inline

Update the data of an existing dataset.

Template Parameters
TData type of the PNXdata object
Parameters
pathHDF5 path of the dataset
newDataNew data vector to set
Returns
true if update succeeded, false if path doesn't exist
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1638 of file PNeXus.h.

References fDataMap, and HasDataset().

◆ UpdateDatasetDimensions()

template<typename T>
bool nxH5::PNeXus::UpdateDatasetDimensions ( const std::string & path,
const std::vector< hsize_t > & newDimensions )
inline

Update the dimensions of an existing dataset.

Template Parameters
TData type of the PNXdata object
Parameters
pathHDF5 path of the dataset
newDimensionsNew dimensions vector to set
Returns
true if update succeeded, false if path doesn't exist
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1657 of file PNeXus.h.

References fDataMap, and HasDataset().

◆ WriteDatasetAttributes()

template<typename T>
void nxH5::PNeXus::WriteDatasetAttributes ( H5::DataSet & dataset,
const PNXdata< T > & data )
private

Write dataset attributes from PNXdata object.

Template Parameters
TThe data type of the PNXdata object
Parameters
datasetHDF5 dataset object to write attributes to
dataPNXdata object containing attributes

Writes all attributes from a PNXdata object to an HDF5 dataset. Supports int, float, and string attribute types.

Template Parameters
TThe data type of the PNXdata object
Parameters
datasetHDF5 dataset object to write attributes to
dataPNXdata object containing attributes
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 5089 of file PNeXus.cpp.

References fPrintDebug, and nxH5::PNXdata< T >::GetAttributes().

Referenced by WriteFloatDataset(), WriteIntDataset(), and WriteStringDataset().

◆ WriteFileAttributes()

void nxH5::PNeXus::WriteFileAttributes ( H5::H5File & file)
private

Write root-level file attributes.

Parameters
fileHDF5 file object
Exceptions
H5::Exceptionif writing fails

Writes root-level file attributes such as NeXus_version, HDF5_version, file_name, and file_time to the HDF5 file.

Parameters
fileHDF5 file object
Exceptions
H5::Exceptionif writing fails
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 5479 of file PNeXus.cpp.

References fFileNameNxs, fFileTimeNxs, fGroupAttributes, fHdf5Version, fNeXusVersion, and fPrintDebug.

Referenced by WriteNexusFile().

◆ WriteFloatDataset()

void nxH5::PNeXus::WriteFloatDataset ( H5::H5File & file,
const std::string & path,
const PNXdata< float > & data )
private

Write a float dataset with attributes.

Parameters
fileHDF5 file object
pathDataset path (groups created automatically)
dataPNXdata object containing data, dimensions, and attributes
Exceptions
H5::Exceptionif writing fails

Writes a float dataset to the HDF5 file with all its attributes. The parent group hierarchy is created automatically if it doesn't exist.

Parameters
fileHDF5 file object
pathDataset path (groups created automatically)
dataPNXdata object containing data, dimensions, and attributes
Exceptions
H5::Exceptionif writing fails
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 5248 of file PNeXus.cpp.

References CreateGroupHierarchy(), fPrintDebug, nxH5::PNXdata< T >::GetData(), nxH5::PNXdata< T >::GetDimensions(), nxH5::PNXdata< T >::GetNumElements(), and WriteDatasetAttributes().

Referenced by WriteNexusFile().

◆ WriteGroupAttributes()

void nxH5::PNeXus::WriteGroupAttributes ( H5::Group & group,
const std::map< std::string, std::any > & attributes )
private

Write attributes to a group.

Parameters
groupHDF5 group object to write attributes to
attributesMap of attribute names to values

Writes attributes to an HDF5 group object. Supports int, float, and string attribute types.

Parameters
groupHDF5 group object to write attributes to
attributesMap of attribute names to values (stored as std::any)
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 5396 of file PNeXus.cpp.

References fPrintDebug.

Referenced by CreateGroupHierarchy().

◆ WriteIntDataset()

void nxH5::PNeXus::WriteIntDataset ( H5::H5File & file,
const std::string & path,
const PNXdata< int > & data )
private

Write an integer dataset with attributes.

Parameters
fileHDF5 file object
pathDataset path (groups created automatically)
dataPNXdata object containing data, dimensions, and attributes
Exceptions
H5::Exceptionif writing fails

Writes an integer dataset to the HDF5 file with all its attributes. The parent group hierarchy is created automatically if it doesn't exist.

Parameters
fileHDF5 file object
pathDataset path (groups created automatically)
dataPNXdata object containing data, dimensions, and attributes
Exceptions
H5::Exceptionif writing fails
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 5176 of file PNeXus.cpp.

References CreateGroupHierarchy(), fPrintDebug, nxH5::PNXdata< T >::GetData(), nxH5::PNXdata< T >::GetDimensions(), nxH5::PNXdata< T >::GetNumElements(), and WriteDatasetAttributes().

Referenced by WriteNexusFile().

◆ WriteNexusFile()

int nxH5::PNeXus::WriteNexusFile ( const std::string & filename,
int idfVersion = 2 )

Writes the data map contents to a new NeXus HDF5 file. This is the main public API for writing NeXus files.

Parameters
filenamePath to the output NeXus HDF5 file
idfVersionIDF version to write (default: 2)
Returns
0 on success, 1 on error
Exceptions
H5::FileIExceptionif file cannot be created
H5::GroupIExceptionif group creation fails
H5::DataSetIExceptionif dataset writing fails
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 5731 of file PNeXus.cpp.

References fDataMap, fPrintDebug, WriteFileAttributes(), WriteFloatDataset(), WriteIntDataset(), and WriteStringDataset().

◆ WriteStringDataset()

void nxH5::PNeXus::WriteStringDataset ( H5::H5File & file,
const std::string & path,
const PNXdata< std::string > & data )
private

Write a string dataset with attributes.

Parameters
fileHDF5 file object
pathDataset path (groups created automatically)
dataPNXdata object containing data, dimensions, and attributes
Exceptions
H5::Exceptionif writing fails

Writes a string dataset to the HDF5 file with all its attributes. The parent group hierarchy is created automatically if it doesn't exist. Handles both scalar strings and arrays of strings.

Parameters
fileHDF5 file object
pathDataset path (groups created automatically)
dataPNXdata object containing data, dimensions, and attributes
Exceptions
H5::Exceptionif writing fails
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 5321 of file PNeXus.cpp.

References CreateGroupHierarchy(), fPrintDebug, nxH5::PNXdata< T >::GetData(), nxH5::PNXdata< T >::GetDimensions(), and WriteDatasetAttributes().

Referenced by WriteNexusFile().

Member Data Documentation

◆ fCreatorNxs

std::string nxH5::PNeXus::fCreatorNxs {""}
private

Definition at line 1882 of file PNeXus.h.

◆ fDataMap

◆ fFileName

std::string nxH5::PNeXus::fFileName {""}
private

NeXus HDF5 filename.

Definition at line 1875 of file PNeXus.h.

Referenced by Dump(), GetFileName(), PNeXus(), and ReadNexusFile().

◆ fFileNameNxs

std::string nxH5::PNeXus::fFileNameNxs {""}
private

Definition at line 1880 of file PNeXus.h.

Referenced by Dump(), HandleIdfV2(), and WriteFileAttributes().

◆ fFileTimeNxs

std::string nxH5::PNeXus::fFileTimeNxs {""}
private

Definition at line 1881 of file PNeXus.h.

Referenced by Dump(), HandleIdfV2(), and WriteFileAttributes().

◆ fGroupAttributes

std::map<std::string, std::map<std::string, std::any> > nxH5::PNeXus::fGroupAttributes
private

◆ fHdf5LibVersion

std::string nxH5::PNeXus::fHdf5LibVersion {"n/a"}
private

HDF5 library version used when calling PNeXus.

Definition at line 1877 of file PNeXus.h.

Referenced by GetHdf5LibVersion(), PNeXus(), and PNeXus().

◆ fHdf5Version

std::string nxH5::PNeXus::fHdf5Version {""}
private

HDF5 version of the file.

Definition at line 1878 of file PNeXus.h.

Referenced by Dump(), GetHdf5Version(), ReadNexusFile(), and WriteFileAttributes().

◆ fIdfVersion

int nxH5::PNeXus::fIdfVersion {-1}
private

IDF version of the NeXus file.

Definition at line 1876 of file PNeXus.h.

Referenced by Dump(), GetIdfVersion(), and ReadNexusFile().

◆ fNeXusVersion

std::string nxH5::PNeXus::fNeXusVersion {""}
private

NeXus version of the file.

Definition at line 1879 of file PNeXus.h.

Referenced by Dump(), GetNeXusVersion(), ReadNexusFile(), and WriteFileAttributes().

◆ fPrintDebug

◆ fUserV1

std::string nxH5::PNeXus::fUserV1 {""}
private

Definition at line 1883 of file PNeXus.h.

Referenced by Dump(), and HandleIdfV1().


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