musrfit 1.10.0
PNeXus.h File Reference

NeXus HDF4/HDF5 file reader and writer for muon spin rotation data. More...

#include <string>
#include <vector>
#include <map>
#include <cctype>
#include <algorithm>
#include <any>
#include <cstdint>
#include "Minuit2/FCNBase.h"
#include <mfhdf.h>
#include <hdf.h>
#include <H5Cpp.h>
Include dependency graph for PNeXus.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  nxH4::PNeXusDeadTime
 Dead time correction calculator for muon detector data. More...
 
class  nxH4::PNXdata< T >
 Template class for storing HDF4 dataset content with attributes. More...
 
class  nxH4::PNeXus
 NeXus HDF4 file reader with case-insensitive path lookup. More...
 
class  nxH5::PNeXusDeadTime
 Dead time correction calculator for muon detector data. More...
 
class  nxH5::PNXdata< T >
 Template class for storing HDF5 dataset content with attributes. More...
 
class  nxH5::PNeXus
 NeXus HDF5 file reader with case-insensitive path lookup. More...
 

Namespaces

namespace  nxs
 Common utilities for NeXus file handling.
 
namespace  nxH4
 HDF4 implementation of the NeXus file reader/writer.
 
namespace  nxH5
 HDF5 implementation of the NeXus file reader/writer.
 

Enumerations

enum class  nxs::HDFType { nxs::HDF4 , nxs::HDF5 , nxs::Unknown }
 Enumeration of supported HDF file types. More...
 
enum class  nxH4::H4DataType {
  nxH4::kINT32 , nxH4::kFLOAT32 , nxH4::kFLOAT64 , nxH4::kCHAR8 ,
  nxH4::kUINT32 , nxH4::kINT16 , nxH4::kUINT16 , nxH4::kINT8 ,
  nxH4::kUINT8
}
 HDF4 data type enumeration. More...
 

Functions

HDFType nxs::checkHDFType (const std::string &filename)
 Determine the HDF format type of a file by reading its header.
 
std::string nxs::getIso8601TimestampLocal ()
 get the current time and return it as na IOS8601 time stamp.
 

Detailed Description

NeXus HDF4/HDF5 file reader and writer for muon spin rotation data.

This header file defines the PNeXus library for reading and writing NeXus files in both HDF4 and HDF5 formats. The library is specifically designed for ISIS muon NeXus files but can be adapted for other NeXus data.

The library provides:

  • Dual format support: Both HDF4 (nxH4 namespace) and HDF5 (nxH5 namespace)
  • Case-insensitive path lookup: Handles varying path casings in NeXus files
  • Type-safe data handling: Template-based PNXdata class with type preservation
  • IDF version support: Handles both IDF version 1 and version 2 file structures
  • Dead time correction: Built-in muon spectrometry dead time analysis

Architecture

The library is organized into three namespaces:

  • nxs: Common utilities (HDFType enum, checkHDFType function)
  • nxH4: HDF4-specific implementation (conditional, requires HAVE_HDF4)
  • nxH5: HDF5-specific implementation (always available)

Data Organization

NeXus files follow the ISIS muon format with structure:

* /raw_data_1/                          (NXentry)
* ├── IDF_version
* ├── beamline, definition, run_number, title
* ├── start_time, end_time, good_frames
* ├── detector_1/                       (NXdata)
* │   ├── counts (multi-dimensional)
* │   ├── raw_time
* │   └── attributes (signal, axes, units, etc.)
* └── instrument/                       (NXinstrument)
*     ├── name, source/
*     └── detector_1/                   (NXdetector)
*         ├── counts, raw_time
*         ├── resolution, spectrum_index
*         └── dead_time
* 

Usage Example

#include "PNeXus.h"
// Check file type
nxs::HDFType type = nxs::checkHDFType("file.nxs");
if (type == nxs::HDFType::HDF5) {
// Read HDF5 NeXus file
nxH5::PNeXus nexus("file.nxs");
nexus.Dump();
// Access data
auto counts = nexus.GetDataset<int>("/raw_data_1/detector_1/counts");
auto dims = counts.GetDimensions();
}
NeXus HDF4/HDF5 file reader and writer for muon spin rotation data.
NeXus HDF5 file reader with case-insensitive path lookup.
Definition PNeXus.h:1463
HDFType
Enumeration of supported HDF file types.
Definition PNeXus.h:141
@ HDF5
HDF5 format (magic: 0x89 'H' 'D' 'F' 0x0d 0x0a 0x1a 0x0a)
Definition PNeXus.h:143
HDFType checkHDFType(const std::string &filename)
Determine the HDF format type of a file by reading its header.
Definition PNeXus.cpp:100
Author
Andreas Suter
Date
2007-2026
Version
1.0
See also
nxs::checkHDFType()
nxH4::PNeXus
nxH5::PNeXus

Definition in file PNeXus.h.