Algorithms¶
libpninexus’s provides an extensive set algorithms related to NeXus. In particulare related to searching for particular base classes.
Containers¶
-
class 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.
- Throws:
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.
-
GroupList(const NodeList &nodes)¶
-
class 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.
- Throws:
std::runtime_error – in case of a failure
- Parameters:
nodes – reference to the original node list
-
DatasetList() = default¶
-
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 NodePredicate¶
abstract predicate interface for nodes
This is the base class for all predicates related to HDF5 Node instances.
Subclassed by pni::nexus::IsBaseClass
Public Functions
-
virtual ~NodePredicate()¶
virtual destructor
Required for inheritances
-
virtual bool operator()(const hdf5::node::Node &node) const = 0¶
predicate operator
Every specialization of this class has to implement this function.
- Parameters:
node – reference to the node of interest
- Returns:
true of the node matches the predicate, false otherwise
-
virtual ~NodePredicate()¶
-
class IsBaseClass : public pni::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::nexus::IsData, pni::nexus::IsDetector, pni::nexus::IsEntry, pni::nexus::IsInstrument, pni::nexus::IsSample, pni::nexus::IsSubentry, pni::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.
-
explicit 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.
-
virtual ~IsBaseClass()¶
virtual destructor
Required for inheritance.
-
virtual 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::nexus::IsBaseClass¶
matches NXdata
Child class of IsBaseClass that matches NXdata
-
class IsDetector : public pni::nexus::IsBaseClass¶
matches NXdetector
Child class of IsBaseClass that matches NXdetector
-
class IsEntry : public pni::nexus::IsBaseClass¶
matches NXentry
Child class of IsBaseClass that matches an NXentry
-
class IsInstrument : public pni::nexus::IsBaseClass¶
matches NXinstrument
Child class of IsBaseClass that matches NXinstrument
-
class IsSample : public pni::nexus::IsBaseClass¶
matches NXsample
Child class of IsBaseClass that matches NXsample
-
class IsSubentry : public pni::nexus::IsBaseClass¶
matches NXsubentry
Child class of IsBaseClass that matches NXsubentry
-
class IsTransformation : public pni::nexus::IsBaseClass¶
matches an NXtransformations
Child class of IsBaseClass that matches an NXtransformation.
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.
-
PNINEXUS_EXPORT NodeList pni::nexus::search(const hdf5::node::Group &base, const NodePredicate &predicate, bool recursive = false)¶
search for nodes satisfying a 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
- Returns:
an instance of NodeList with all nodes satisfying the predicate
Utilities¶
-
PNINEXUS_EXPORT pni::type_id_t pni::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.
- Throws:
std::runtime_error – in case of a failure
- Parameters:
attribute – reference to the attribute
- Returns:
type_id_t enumeration
-
PNINEXUS_EXPORT pni::type_id_t pni::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.
- Throws:
std::runtime_error – in case of a failure
- Parameters:
dataset – reference to the dataset
- Returns:
type_id_t enumeration
-
PNINEXUS_EXPORT hdf5::Dimensions pni::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.
- Throws:
std::runtime_error – in case of a failure
- Parameters:
attribute – reference to the attribute
- Returns:
instance of hdf5::Dimensions with the current dimensions
-
PNINEXUS_EXPORT hdf5::Dimensions pni::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.
- Throws:
std::runtime_error – in case of a failure
- Parameters:
dataset – reference to the dataset
- Returns:
instance of hdf5::Dimensions with the current dimensions