Algorithms

libpniio’s provides an extensive set algorithms related to NeXus. In particulare related to searching for particular base classes.

Containers

class pni::io::nexus::GroupList : public std::vector<hdf5::node::Group>

list of HDF5 groups

A specialization of std::list storing instances of hdf5::node::Group.

Public Functions

GroupList(const NodeList &nodes)

conversion constructor

This constructor is deliberately not marked as explicit. It is used to convert a list of nodes to a list of groups. This will only work if all nodes are indeed groups. Otherwise an exception is thrown.

Exceptions
  • std::runtime_error: in case of a failure

Parameters
  • nodes: reference to the original node list

GroupList() = default

default constructor

Use the compiler provided default implementation.

class pni::io::nexus::DatasetList : public std::vector<hdf5::node::Dataset>

list of datasets

A specialization of std::vector storing instances of hdf5::node::Dataset;

Public Functions

DatasetList() = default

default constructor

Use the compiler provided default implementation here

DatasetList(const NodeList &nodes)

implicit conversion constructor

This constructor is deliberately not marked as explicit. It is used to convert a list of nodes to a list of groups. This will only work if all nodes are indeed groups. Otherwise an exception is thrown.

Exceptions
  • std::runtime_error: in case of a failure

Parameters
  • nodes: reference to the original node list

class NodeList : public std::vector<hdf5::node::Node>

list of HDF5 nodes

A specialization of std::list storing instances of hdf5::node::Node;

class AttributeList : public std::vector<hdf5::attribute::Attribute>

Predicates

class pni::io::nexus::NodePredicate

abstract predicate interface for nodes

This is the base class for all predicates related to HDF5 Node instances.

Subclassed by pni::io::nexus::IsBaseClass

Public Functions

~NodePredicate()

virtual destructor

Required for inheritances

bool operator()(const hdf5::node::Node &node) const = 0

predicate operator

Every specialization of this class has to implement this function.

Return

true of the node matches the predicate, false otherwise

Parameters
  • node: reference to the node of interest

class pni::io::nexus::IsBaseClass : public pni::io::nexus::NodePredicate

predicate to search for base classes

This predicate can be used in two particular ways

  • to search for any base class (when default constructed)

  • to search for a specific base class when constructed with a class name

//!

using GroupList = std::list<hdf5::node::Group>;

GroupList detectors;
hdf5::node::Group entry = ...;

std::copy_if(node::RecursiveNodeIterator::begin(entry),
             node::RecursiveNodeIterator::end(entry),
             std::back_inserter(detectors),
             IsBaseClass("NXdetector"));

Subclassed by pni::io::nexus::IsData, pni::io::nexus::IsDetector, pni::io::nexus::IsEntry, pni::io::nexus::IsInstrument, pni::io::nexus::IsSample, pni::io::nexus::IsSubentry, pni::io::nexus::IsTransformation

Public Functions

IsBaseClass() = default

default constructor

We use the compiler provided default implementation. When instantiated with the default constructor this predicate will match every base class.

IsBaseClass(const std::string &name)

constructor

A predicate instantiated with this constructor searches for a particular type of base class. The type is determined by the name argument of the constructor.

Parameters
  • name: the name of the base class to match

IsBaseClass(const IsBaseClass&) = default

copy constructor

We use the compiler provided default implementation here.

~IsBaseClass()

virtual destructor

Required for inheritance.

bool operator()(const hdf5::node::Node &node) const

function call operator

Returns true if the node matches the predicate, false otherwise.

Parameters
  • node: reference to the node to check

class IsData : public pni::io::nexus::IsBaseClass

matches NXdata

Child class of IsBaseClass that matches NXdata

class IsDetector : public pni::io::nexus::IsBaseClass

matches NXdetector

Child class of IsBaseClass that matches NXdetector

class IsEntry : public pni::io::nexus::IsBaseClass

matches NXentry

Child class of IsBaseClass that matches an NXentry

class IsInstrument : public pni::io::nexus::IsBaseClass

matches NXinstrument

Child class of IsBaseClass that matches NXinstrument

class IsSample : public pni::io::nexus::IsBaseClass

matches NXsample

Child class of IsBaseClass that matches NXsample

class IsSubentry : public pni::io::nexus::IsBaseClass

matches NXsubentry

Child class of IsBaseClass that matches NXsubentry

class IsTransformation : public pni::io::nexus::IsBaseClass

matches an NXtransformations

Child class of IsBaseClass that matches an NXtransformation.

class IsValidNeXusName

predicate checking a NeXus name

This predicate is checking a string if it is a valid NeXus name. The regular expression used for this check is given here.

Searching

There is a single search function which, in connection with the above predicates can be used to retrieve any node from a NeXus tree.

PNIIO_EXPORT NodeList pni::io::nexus::search(const hdf5::node::Group &base, const NodePredicate &predicate, bool recursive = false)

search for nodes satisfying a predicate

Return

an instance of NodeList with all nodes satisfying the predicate

Parameters
  • base: reference to the group where to start the search

  • predicate: the predicate to select a node

  • recursive: if true perform a recursive search

Utilities

PNIIO_EXPORT pni::core::type_id_t pni::io::nexus::get_type_id(const hdf5::attribute::Attribute &attribute)

return the type_id of an attribute

If the underlying data type is unkonwn NONE is returned.

Return

type_id_t enumeration

Exceptions
  • std::runtime_error: in case of a failure

Parameters
  • attribute: reference to the attribute

PNIIO_EXPORT pni::core::type_id_t pni::io::nexus::get_type_id(const hdf5::node::Dataset &dataset)

return the type_id of a dataset

If the underlying data type is unkonwn NONE is returned.

Return

type_id_t enumeration

Exceptions
  • std::runtime_error: in case of a failure

Parameters
  • dataset: reference to the dataset

PNIIO_EXPORT hdf5::Dimensions pni::io::nexus::get_dimensions(const hdf5::attribute::Attribute &attribute)

get the current dimensions of an attribute

If the attribute is scalar {1} is returned. Otherwise the current dimensions of the attribute are returned.

Return

instance of hdf5::Dimensions with the current dimensions

Exceptions
  • std::runtime_error: in case of a failure

Parameters
  • attribute: reference to the attribute

PNIIO_EXPORT hdf5::Dimensions pni::io::nexus::get_dimensions(const hdf5::node::Dataset &dataset)

get the current dimensions of a dataset

If the dataset is scalar {1} is returned. Otherwise the current dimensions of the dataset are returned.

Return

instance of hdf5::Dimensions with the current dimensions

Exceptions
  • std::runtime_error: in case of a failure

Parameters
  • dataset: reference to the dataset