musrfit 1.10.0
nxH4::PNeXus Class Reference

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

#include <PNeXus.h>

Public Member Functions

 PNeXus ()
 
 PNeXus (const std::string fln, const bool printDebug=false)
 Constructor - creates PNeXus object and reads the NeXus file.
 
 ~PNeXus ()
 Destructor - closes HDF4 file if open.
 
std::string GetFileName () const
 Get the filename of the NeXus file.
 
std::string GetHdf4LibVersion () const
 Get the hdf4 library version.
 
std::string GetHdf4Version () const
 Get the hdf4 version of the NeXus 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 HDF4 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< uint32_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< uint32_t > &dimensions, const H4DataType &dataType=H4DataType::kINT32)
 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< uint32_t > &newDimensions)
 Modify an existing dataset's data and dimensions.
 
void Dump ()
 Print a human-readable dump of the NeXus file contents.
 
int WriteNexusFile (const std::string &filename, int idfVersion=2)
 Write the data map contents to a NeXus HDF4 file.
 
bool AddGroupAttribute (const std::string &groupPath, const std::string &attrName, const std::any &attrValue)
 Add or update an attribute for a group.
 
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 (int32 sd_id)
 Read datasets for IDF version 1 file structure.
 
void HandleIdfV2 (int32 sd_id)
 Read datasets for IDF version 2 file structure.
 
template<typename T>
void WriteDatasetAttributes (int32 sds_id, const PNXdata< T > &data)
 Write dataset attributes from PNXdata object.
 
void WriteVGroupAttributes (int32 vgroup_id, const std::map< std::string, std::any > &attributes)
 Write attributes to a Vgroup.
 
int32 CreateVGroupHierarchy (int32 file_id, const std::string &path, std::map< std::string, int32 > &vgroupCache)
 Create the Vgroup hierarchy for a given path.
 
int32 WriteIntDataset (int32 sd_id, const std::string &path, const PNXdata< int > &data)
 Write an integer dataset with attributes and return its SDS reference.
 
int32 WriteFloatDataset (int32 sd_id, const std::string &path, const PNXdata< float > &data)
 Write a float dataset with attributes and return its SDS reference.
 
int32 WriteStringDataset (int32 sd_id, const std::string &path, const PNXdata< std::string > &data)
 Write a string dataset with attributes and return its SDS reference.
 
void WriteFileAttributes (int32 sd_id)
 Write root-level file attributes.
 
std::string FindAttributeName (int32 sd_id, const std::string &requestedName)
 
int32 FindDatasetIndex (int32 sd_id, const std::string &requestedName)
 Find dataset index with case-insensitive matching.
 
int32 FindDatasetRefByPath (const std::string &path)
 Find dataset reference by navigating VGroup hierarchy.
 
void ReadIntDataset (int32 sd_id, const std::string &path)
 Read an integer dataset and store in data map.
 
void ReadFloatDataset (int32 sd_id, const std::string &path)
 Read a float dataset and store in data map.
 
void ReadStringDataset (int32 sd_id, const std::string &path)
 Read a string dataset and store in data map.
 
template<typename T>
void ReadDatasetAttributes (int32 sds_id, 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)
 
static H4DataType convertHdf4Type (int32 hdf4_type)
 Convert HDF4 data type to H4DataType enum.
 
static int32 convertToHdf4Type (H4DataType dataType)
 Convert H4DataType enum to HDF4 data type.
 

Private Attributes

bool fPrintDebug {false}
 if true print additional debug information
 
std::string fFileName {""}
 NeXus HDF4 filename.
 
int fIdfVersion {-1}
 IDF version of the NeXus file.
 
std::string fHdf4LibVersion {""}
 HDF4 library version used when calling PNeXus.
 
std::string fHdf4Version {""}
 HDF4 version of the file.
 
std::string fNeXusVersion {""}
 NeXus version of the file.
 
std::string fFileNameNxs {""}
 
std::string fFileTimeNxs {""}
 
std::string fCreatorNxs {""}
 
std::string fUserV1 {""}
 
int32 fSdId {-1}
 HDF4 SD interface identifier.
 
int32 fFileId {-1}
 HDF4 file identifier.
 
std::map< std::string, std::any > fDataMap
 Map of HDF4 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 HDF4 file reader with case-insensitive path lookup.

The PNeXus class provides functionality for reading ISIS muon NeXus HDF4 files using the HDF4 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
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 517 of file PNeXus.h.

Constructor & Destructor Documentation

◆ PNeXus() [1/2]

◆ PNeXus() [2/2]

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

Constructor - creates PNeXus object and reads the NeXus file.

Parameters
flnFilename of the NeXus HDF4 file to read
printDebugEnable debug output
Exceptions
std::runtime_errorif file cannot be opened or read

Definition at line 340 of file PNeXus.cpp.

References fFileId, fFileName, fHdf4LibVersion, fPrintDebug, fSdId, and ReadNexusFile().

◆ ~PNeXus()

nxH4::PNeXus::~PNeXus ( )

Destructor - closes HDF4 file if open.

Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 356 of file PNeXus.cpp.

References fFileId, and fSdId.

Member Function Documentation

◆ AddDataset()

template<typename T>
bool nxH4::PNeXus::AddDataset ( const std::string & path,
const std::vector< T > & data,
const std::vector< uint32_t > & dimensions,
const H4DataType & dataType = H4DataType::kINT32 )
inline

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

Template Parameters
TData type of the PNXdata object
Parameters
pathHDF4 path for the new dataset
dataData vector
dimensionsDimensions vector
dataTypeHDF4 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 759 of file PNeXus.h.

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

◆ AddDatasetAttribute()

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

References fDataMap, and HasDataset().

◆ AddGroupAttribute()

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

Add or update an attribute for a group.

Stores an attribute value in the internal group attributes map. These attributes will be written when WriteNexusFile() is called. The root group "/" can be used for file-level attributes.

Parameters
groupPathHDF4 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 2449 of file PNeXus.cpp.

References fGroupAttributes.

Referenced by AddRootAttribute().

◆ AddRootAttribute()

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

◆ CaseInsensitiveEquals()

bool nxH4::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 2516 of file PNeXus.cpp.

Referenced by FindAttributeName(), FindDatasetIndex(), FindDatasetRefByPath(), and ReadNexusFile().

◆ ClearDataMap()

void nxH4::PNeXus::ClearDataMap ( )
inline

Clear all datasets from the data map.

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

Definition at line 658 of file PNeXus.h.

References fDataMap.

◆ ClearGroupAttributes()

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

Clear all attributes from a group.

Parameters
groupPathHDF4 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 2498 of file PNeXus.cpp.

References fGroupAttributes.

◆ convertHdf4Type()

nxH4::H4DataType nxH4::PNeXus::convertHdf4Type ( int32 hdf4_type)
staticprivate

Convert HDF4 data type to H4DataType enum.

Convert HDF4 numeric type constant to H4DataType enum.

Parameters
hdf4_typeHDF4 numeric type constant (DFNT_*)
Returns
H4DataType enum value

Maps HDF4 DFNT_* type constants to the library's H4DataType enum for type-safe handling of dataset types.

Parameters
hdf4_typeHDF4 numeric type constant (e.g., DFNT_INT32)
Returns
Corresponding H4DataType enum value
Note
Unknown types default to H4DataType::INT32
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 2744 of file PNeXus.cpp.

References nxH4::kCHAR8, nxH4::kFLOAT32, nxH4::kFLOAT64, nxH4::kINT16, nxH4::kINT32, nxH4::kINT8, nxH4::kUINT16, nxH4::kUINT32, and nxH4::kUINT8.

◆ convertToHdf4Type()

int32 nxH4::PNeXus::convertToHdf4Type ( H4DataType dataType)
staticprivate

Convert H4DataType enum to HDF4 data type.

Convert H4DataType enum to HDF4 numeric type constant.

Parameters
dataTypeH4DataType enum value
Returns
HDF4 numeric type constant (DFNT_*)

Maps the library's H4DataType enum to HDF4 DFNT_* type constants for writing datasets to HDF4 files.

Parameters
dataTypeH4DataType enum value
Returns
Corresponding HDF4 numeric type constant (e.g., DFNT_INT32)
Note
Unknown types default to DFNT_INT32
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 2771 of file PNeXus.cpp.

References nxH4::kCHAR8, nxH4::kFLOAT32, nxH4::kFLOAT64, nxH4::kINT16, nxH4::kINT32, nxH4::kINT8, nxH4::kUINT16, nxH4::kUINT32, and nxH4::kUINT8.

◆ CreateVGroupHierarchy()

int32 nxH4::PNeXus::CreateVGroupHierarchy ( int32 file_id,
const std::string & path,
std::map< std::string, int32 > & vgroupCache )
private

Create the Vgroup hierarchy for a given path.

Given a path like "/run/sample", creates Vgroups "run" and "sample" (nested), writing any associated group attributes from fGroupAttributes. Uses a cache to avoid creating duplicate Vgroups.

Parameters
file_idHDF4 file ID (from Hopen)
pathThe group path to create (e.g., "/run/sample")
vgroupCacheMap of already-created group paths to their Vgroup references
Returns
The Vgroup reference of the deepest group in the path
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 2365 of file PNeXus.cpp.

References fGroupAttributes, SplitPath(), and WriteVGroupAttributes().

Referenced by WriteNexusFile().

◆ Dump()

void nxH4::PNeXus::Dump ( )

Print a human-readable dump of the NeXus file contents.

Outputs the contents of the loaded NeXus file to stdout in a hierarchical format. The output includes:

  • File metadata (HDF4 version, NeXus version, file name, file time)
  • IDF version
  • Run information (run number, title, start/stop time)
  • Sample information (name, temperature, magnetic field)
  • Instrument information
  • Detector counts with dimensions and first few values

The output format differs based on IDF version (1 or 2).

Note
This method is primarily useful for debugging and verification
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 981 of file PNeXus.cpp.

References fDataMap, fFileName, fFileNameNxs, fFileTimeNxs, fHdf4Version, fIdfVersion, and fNeXusVersion.

◆ FindAttributeName()

std::string nxH4::PNeXus::FindAttributeName ( int32 sd_id,
const std::string & requestedName )
private

◆ FindDatasetIndex()

int32 nxH4::PNeXus::FindDatasetIndex ( int32 sd_id,
const std::string & requestedName )
private

Find dataset index with case-insensitive matching.

Parameters
sd_idHDF4 SD interface ID
requestedNameRequested dataset name (any case)
Returns
Dataset index
Exceptions
std::runtime_errorif dataset not found
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 2572 of file PNeXus.cpp.

References CaseInsensitiveEquals().

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

◆ FindDatasetRefByPath()

int32 nxH4::PNeXus::FindDatasetRefByPath ( const std::string & path)
private

Find dataset reference by navigating VGroup hierarchy.

Parameters
pathFull hierarchical path (e.g., "/run/sample/name")
Returns
Dataset reference number, or -1 if not found
Note
Uses VGroup navigation to resolve paths in HDF4 files with duplicate dataset names
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 2604 of file PNeXus.cpp.

References CaseInsensitiveEquals(), fFileId, fSdId, and SplitPath().

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

◆ GetDataMap() [1/2]

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

Get mutable reference to the data map.

Returns
Reference to the data map

Definition at line 595 of file PNeXus.h.

References fDataMap.

◆ GetDataMap() [2/2]

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

References fDataMap.

◆ GetDataset()

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

Get a dataset from the data map.

Template Parameters
TData type of the PNXdata object
Parameters
pathHDF4 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 624 of file PNeXus.h.

References fDataMap.

◆ GetDatasetRef()

template<typename T>
PNXdata< T > & nxH4::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
pathHDF4 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 637 of file PNeXus.h.

References fDataMap.

◆ GetFileName()

std::string nxH4::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 552 of file PNeXus.h.

References fFileName.

◆ GetGroupAttribute()

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

Get an attribute value from a group.

Parameters
groupPathHDF4 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 2481 of file PNeXus.cpp.

References fGroupAttributes.

◆ GetGroupAttributes()

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

Get all attributes for a group.

Parameters
groupPathHDF4 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 2487 of file PNeXus.cpp.

References fGroupAttributes.

◆ GetHdf4LibVersion()

std::string nxH4::PNeXus::GetHdf4LibVersion ( ) const
inline

Get the hdf4 library version.

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

Definition at line 558 of file PNeXus.h.

References fHdf4LibVersion.

◆ GetHdf4Version()

std::string nxH4::PNeXus::GetHdf4Version ( ) const
inline

Get the hdf4 version of the NeXus file.

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

Definition at line 564 of file PNeXus.h.

References fHdf4Version.

◆ GetIdfVersion()

int nxH4::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 576 of file PNeXus.h.

References fIdfVersion.

◆ GetNeXusVersion()

std::string nxH4::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 570 of file PNeXus.h.

References fNeXusVersion.

◆ GetNumDatasets()

size_t nxH4::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 664 of file PNeXus.h.

References fDataMap.

◆ HandleIdfV1()

void nxH4::PNeXus::HandleIdfV1 ( int32 sd_id)
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
sd_idHDF4 SD interface ID
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 544 of file PNeXus.cpp.

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

Referenced by ReadNexusFile().

◆ HandleIdfV2()

void nxH4::PNeXus::HandleIdfV2 ( int32 sd_id)
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
sd_idHDF4 SD interface ID
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 628 of file PNeXus.cpp.

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

Referenced by ReadNexusFile().

◆ HasDataset()

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

Check if a dataset path exists in the data map.

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

Definition at line 602 of file PNeXus.h.

References fDataMap.

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

◆ HasGroupAttribute()

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

Check if a group has a specific attribute.

Parameters
groupPathHDF4 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 2471 of file PNeXus.cpp.

References fGroupAttributes.

◆ ModifyDataset()

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

Modify an existing dataset's data and dimensions.

Template Parameters
TData type of the PNXdata object
Parameters
pathHDF4 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 779 of file PNeXus.h.

References fDataMap, and HasDataset().

◆ ReadDatasetAttributes()

template<typename T>
void nxH4::PNeXus::ReadDatasetAttributes ( int32 sds_id,
PNXdata< T > & data )
private

Read dataset attributes and add to PNXdata object.

Template Parameters
TThe data type of the PNXdata object
Parameters
sds_idHDF4 dataset ID
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 920 of file PNeXus.cpp.

References nxH4::PNXdata< T >::AddAttribute().

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

◆ ReadFloatDataset()

void nxH4::PNeXus::ReadFloatDataset ( int32 sd_id,
const std::string & path )
private

Read a float dataset and store in data map.

Parameters
sd_idHDF4 SD interface ID
pathPath to the dataset
Exceptions
std::runtime_errorif reading fails
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 766 of file PNeXus.cpp.

References fDataMap, FindDatasetIndex(), FindDatasetRefByPath(), nxH4::kFLOAT32, ReadDatasetAttributes(), nxH4::PNXdata< T >::SetData(), nxH4::PNXdata< T >::SetDimensions(), and SplitPath().

Referenced by HandleIdfV1(), and HandleIdfV2().

◆ ReadIntDataset()

void nxH4::PNeXus::ReadIntDataset ( int32 sd_id,
const std::string & path )
private

Read an integer dataset and store in data map.

Parameters
sd_idHDF4 SD interface ID
pathPath to the dataset
Exceptions
std::runtime_errorif reading fails
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 690 of file PNeXus.cpp.

References fDataMap, FindDatasetIndex(), FindDatasetRefByPath(), nxH4::kINT32, ReadDatasetAttributes(), nxH4::PNXdata< T >::SetData(), nxH4::PNXdata< T >::SetDimensions(), and SplitPath().

Referenced by HandleIdfV1(), and HandleIdfV2().

◆ ReadNexusFile()

int nxH4::PNeXus::ReadNexusFile ( )

Read and parse the NeXus HDF4 file.

Returns
0 on success, 1 on error
Exceptions
std::runtime_errorif file cannot be opened or read
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 369 of file PNeXus.cpp.

References CaseInsensitiveEquals(), fFileId, fFileName, fFileNameNxs, fFileTimeNxs, fHdf4Version, fIdfVersion, FindDatasetRefByPath(), fNeXusVersion, fPrintDebug, fSdId, HandleIdfV1(), and HandleIdfV2().

Referenced by PNeXus().

◆ ReadStringDataset()

void nxH4::PNeXus::ReadStringDataset ( int32 sd_id,
const std::string & path )
private

Read a string dataset and store in data map.

Parameters
sd_idHDF4 SD interface ID
pathPath to the dataset
Exceptions
std::runtime_errorif reading fails
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 842 of file PNeXus.cpp.

References fDataMap, FindDatasetIndex(), FindDatasetRefByPath(), nxH4::kCHAR8, ReadDatasetAttributes(), nxH4::PNXdata< T >::SetData(), nxH4::PNXdata< T >::SetDimensions(), and SplitPath().

Referenced by HandleIdfV1(), and HandleIdfV2().

◆ RemoveDataset()

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

Remove a dataset from the data map.

Parameters
pathHDF4 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 646 of file PNeXus.h.

References fDataMap.

◆ RemoveDatasetAttribute()

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

References fDataMap, and HasDataset().

◆ RemoveGroupAttribute()

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

Remove an attribute from a group.

Parameters
groupPathHDF4 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 2457 of file PNeXus.cpp.

References fGroupAttributes.

◆ SetDataset()

template<typename T>
void nxH4::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
pathHDF4 path for the dataset
dataPNXdata object to store
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 611 of file PNeXus.h.

References fDataMap.

◆ SplitPath()

◆ UpdateDatasetData()

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

References fDataMap, and HasDataset().

◆ UpdateDatasetDimensions()

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

Update the dimensions of an existing dataset.

Template Parameters
TData type of the PNXdata object
Parameters
pathHDF4 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 693 of file PNeXus.h.

References fDataMap, and HasDataset().

◆ WriteDatasetAttributes()

template<typename T>
void nxH4::PNeXus::WriteDatasetAttributes ( int32 sds_id,
const PNXdata< T > & data )
private

Write dataset attributes from PNXdata object.

Template Parameters
TThe data type of the PNXdata object
Parameters
sds_idHDF4 dataset ID 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 2267 of file PNeXus.cpp.

References nxH4::PNXdata< T >::GetAttributes().

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

◆ WriteFileAttributes()

void nxH4::PNeXus::WriteFileAttributes ( int32 sd_id)
private

Write root-level file attributes.

Parameters
sd_idHDF4 SD interface ID
Exceptions
std::runtime_errorif writing fails
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 2079 of file PNeXus.cpp.

References fFileNameNxs, fFileTimeNxs, fGroupAttributes, fHdf4Version, and fNeXusVersion.

Referenced by WriteNexusFile().

◆ WriteFloatDataset()

int32 nxH4::PNeXus::WriteFloatDataset ( int32 sd_id,
const std::string & path,
const PNXdata< float > & data )
private

Write a float dataset with attributes and return its SDS reference.

Parameters
sd_idHDF4 SD interface ID
pathDataset path (leaf name used for SDS name)
dataPNXdata object containing data, dimensions, and attributes
Returns
SDS reference number for linking into Vgroups
Exceptions
std::runtime_errorif writing fails
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 2172 of file PNeXus.cpp.

References nxH4::PNXdata< T >::GetData(), nxH4::PNXdata< T >::GetDimensions(), SplitPath(), and WriteDatasetAttributes().

Referenced by WriteNexusFile().

◆ WriteIntDataset()

int32 nxH4::PNeXus::WriteIntDataset ( int32 sd_id,
const std::string & path,
const PNXdata< int > & data )
private

Write an integer dataset with attributes and return its SDS reference.

Parameters
sd_idHDF4 SD interface ID
pathDataset path (leaf name used for SDS name)
dataPNXdata object containing data, dimensions, and attributes
Returns
SDS reference number for linking into Vgroups
Exceptions
std::runtime_errorif writing fails
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 2124 of file PNeXus.cpp.

References nxH4::PNXdata< T >::GetData(), nxH4::PNXdata< T >::GetDimensions(), SplitPath(), and WriteDatasetAttributes().

Referenced by WriteNexusFile().

◆ WriteNexusFile()

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

Write the data map contents to a NeXus HDF4 file.

Parameters
filenamePath to the output NeXus HDF4 file
idfVersionIDF version to write (default: 2)
Returns
0 on success, 1 on error
Exceptions
std::runtime_errorif file cannot be created or written
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 1972 of file PNeXus.cpp.

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

◆ WriteStringDataset()

int32 nxH4::PNeXus::WriteStringDataset ( int32 sd_id,
const std::string & path,
const PNXdata< std::string > & data )
private

Write a string dataset with attributes and return its SDS reference.

Parameters
sd_idHDF4 SD interface ID
pathDataset path (leaf name used for SDS name)
dataPNXdata object containing data, dimensions, and attributes
Returns
SDS reference number for linking into Vgroups, or -1 for empty strings
Exceptions
std::runtime_errorif writing fails
Examples
/workspace/LMU/musrfit/src/external/nexus/PNeXus.cpp, and /workspace/LMU/musrfit/src/external/nexus/PNeXus.h.

Definition at line 2220 of file PNeXus.cpp.

References nxH4::PNXdata< T >::GetData(), SplitPath(), and WriteDatasetAttributes().

Referenced by WriteNexusFile().

◆ WriteVGroupAttributes()

void nxH4::PNeXus::WriteVGroupAttributes ( int32 vgroup_id,
const std::map< std::string, std::any > & attributes )
private

Write attributes to a Vgroup.

Parameters
vgroup_idHDF4 Vgroup ID to write attributes to
attributesMap 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 2316 of file PNeXus.cpp.

Referenced by CreateVGroupHierarchy().

Member Data Documentation

◆ fCreatorNxs

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

Definition at line 896 of file PNeXus.h.

◆ fDataMap

◆ fFileId

int32 nxH4::PNeXus::fFileId {-1}
private

HDF4 file identifier.

Definition at line 899 of file PNeXus.h.

Referenced by FindDatasetRefByPath(), PNeXus(), PNeXus(), ReadNexusFile(), and ~PNeXus().

◆ fFileName

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

NeXus HDF4 filename.

Definition at line 889 of file PNeXus.h.

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

◆ fFileNameNxs

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

Definition at line 894 of file PNeXus.h.

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

◆ fFileTimeNxs

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

Definition at line 895 of file PNeXus.h.

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

◆ fGroupAttributes

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

◆ fHdf4LibVersion

std::string nxH4::PNeXus::fHdf4LibVersion {""}
private

HDF4 library version used when calling PNeXus.

Definition at line 891 of file PNeXus.h.

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

◆ fHdf4Version

std::string nxH4::PNeXus::fHdf4Version {""}
private

HDF4 version of the file.

Definition at line 892 of file PNeXus.h.

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

◆ fIdfVersion

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

IDF version of the NeXus file.

Definition at line 890 of file PNeXus.h.

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

◆ fNeXusVersion

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

NeXus version of the file.

Definition at line 893 of file PNeXus.h.

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

◆ fPrintDebug

bool nxH4::PNeXus::fPrintDebug {false}
private

if true print additional debug information

Definition at line 888 of file PNeXus.h.

Referenced by HandleIdfV1(), HandleIdfV2(), PNeXus(), and ReadNexusFile().

◆ fSdId

int32 nxH4::PNeXus::fSdId {-1}
private

HDF4 SD interface identifier.

Definition at line 898 of file PNeXus.h.

Referenced by FindDatasetRefByPath(), PNeXus(), PNeXus(), ReadNexusFile(), and ~PNeXus().

◆ fUserV1

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

Definition at line 897 of file PNeXus.h.


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