libpniio
Public Types | Public Member Functions | Data Fields | Private Types | Private Member Functions | Private Attributes
pni::io::nx::nxgroup< IMPID > Class Template Reference

NXgroup object. More...

#include <nxgroup.hpp>

Collaboration diagram for pni::io::nx::nxgroup< IMPID >:
Collaboration graph
[legend]

Public Types

using imp_type = typename nximp_map< IMPID >::group_imp
 group implementation type More...
 
using type_type = typename nximp_map< IMPID >::type_imp
 type implementation More...
 
using group_type = nxgroup< IMPID >
 the group type More...
 
using value_type = typename nxobject_trait< IMPID >::object_type
 nxobject as container value_type More...
 
using iterator = pni::core::container_iterator< const group_type >
 iterator type More...
 
using field_type = typename nxobject_trait< IMPID >::field_type
 field type More...
 
using attribute_type = typename nxobject_trait< IMPID >::attribute_type
 attribute type More...
 
using link_type = typename nxobject_trait< IMPID >::link_type
 link type More...
 

Public Member Functions

 nxgroup ()
 default constructor More...
 
 nxgroup (const group_type &o)
 copy constructor More...
 
 nxgroup (group_type &&o)
 move constructor More...
 
 nxgroup (imp_type &&imp)
 move construct from implementation object More...
 
 nxgroup (const typename nxobject_trait< IMPID >::object_type &o)
 conversion constructor More...
 
group_typeoperator= (const group_type &g)
 copy assignment More...
 
group_typeoperator= (group_type &&g)
 move assignment More...
 
group_typeoperator= (const typename nxobject_trait< IMPID >::object_type &o)
 conversion assignment More...
 
group_type create_group (const pni::core::string &n, const pni::core::string &type=pni::core::string()) const
 create a group as nexus class More...
 
template<typename T , typename CTYPE = pni::core::shape_t>
field_type create_field (const pni::core::string &n, const CTYPE &shape={1}) const
 create a field More...
 
template<typename T , typename CTYPE = pni::core::shape_t>
field_type create_field (const pni::core::string &n, const CTYPE &shape, const CTYPE &chunk) const
 create a field More...
 
template<typename T , typename CTYPES , typename FIMP >
field_type create_field (const pni::core::string &n, const CTYPES &shape, const nxfilter< FIMP > &filter) const
 Creates a multidimensional field with a filter. More...
 
template<typename T , typename CTYPES , typename CTYPEC , typename FIMP >
field_type create_field (const pni::core::string &n, const CTYPES &s, const CTYPEC &cs, const nxfilter< FIMP > &filter) const
 create a multidimensional field (explicit chunk) with filter More...
 
nxobject_trait< IMPID >
::object_type 
at (const pni::core::string &n) const
 open an arbitrary object More...
 
nxobject_trait< IMPID >
::object_type 
operator[] (const pni::core::string &n) const
 open an object More...
 
size_t size () const
 return number of children More...
 
nxobject_trait< IMPID >
::object_type 
parent () const
 return parent object More...
 
nxobject_trait< IMPID >
::object_type 
at (size_t i) const
 open object by index More...
 
nxobject_trait< IMPID >
::object_type 
operator[] (size_t i) const
 open object by index More...
 
bool has_child (const pni::core::string &n) const
 check if a particular object exists More...
 
void remove (const pni::core::string &n) const
 remove an object from the file More...
 
iterator begin () const noexcept
 iterator on first child More...
 
iterator end () const
 iterator on last child More...
 
pni::core::string name () const
 name of the group More...
 
pni::core::string filename () const
 return filename More...
 
void close ()
 close the group More...
 
bool is_valid () const
 check group validity More...
 
const imp_typeimp () const noexcept
 get constant reference to the implementation More...
 

Data Fields

nxattribute_manager< group_typeattributes
 attribute manager More...
 

Private Types

using field_imp_type = typename nximp_map< IMPID >::field_imp
 field implementation type More...
 
using object_imp_type = typename nximp_map< IMPID >::object_imp
 object implementation type More...
 

Private Member Functions

template<typename CTYPE , typename STYPE >
CTYPE _create_auto_chunk (const STYPE &shape) const
 automatic chunk creation More...
 
template<typename T , typename CTYPE >
field_type _create_field (const pni::core::string &n, const CTYPE &shape, const CTYPE &chunk) const
 field creation function More...
 
template<typename T , typename CTYPE , typename FIMP >
field_type _create_field (const pni::core::string &n, const CTYPE &shape, const CTYPE &chunk, const nxfilter< FIMP > &filter) const
 field creation function More...
 

Private Attributes

imp_type _imp
 the implementation instance of nxgroup More...
 

Detailed Description

template<nximp_code IMPID>
class pni::io::nx::nxgroup< IMPID >

nxgroup is the basic container in Nexus. It can hold other grous, fields and of course attributes. The attributes can be accessed via the public nxattribute_manager attribute. The field and group children of a group can be accessed via the container interface. nxgroup exposes an STL compliant interface and thus can be used like many other STL containers. The value_type of nxgroup is nxobject which is a generic object that can be converted into an attribute, field, or group (provided it represents such an object). As an example we use here nxgroup in a for each loop separating the group and field children into vectors

nxgroup g = ....; std::vector<nxfield> field_vector; std::vector<nxgroup> group_vector;

for(auto child: g) { if(is_field(child)) field_vector.push_back(as_field(child)); else if(is_group(child)) group_vector.push_back(as_group(child)); else throw type_error(...); }In addition we can use lambda functions along with STL lambda functions. Consider the case where we would like to determine the number of fields and groups in a group. This could be easily done with

nxgroup g = ....; size_t number_of_fields = std::count_if(g.begin(),g.end(), [](const nxobject &child) {return is_field(child);}); size_t number_of_groups = std::count_if(g.begin(),g.end(), [](const nxobject &child) {return is_group(child);});For a more detailed explanation about groups and field see the user reference manual.

Template Parameters
IMPIDimplementation ID for the group
See also
nxattribute_manager

Member Typedef Documentation

template<nximp_code IMPID>
using pni::io::nx::nxgroup< IMPID >::attribute_type = typename nxobject_trait<IMPID>::attribute_type
template<nximp_code IMPID>
using pni::io::nx::nxgroup< IMPID >::field_imp_type = typename nximp_map<IMPID>::field_imp
private
template<nximp_code IMPID>
using pni::io::nx::nxgroup< IMPID >::field_type = typename nxobject_trait<IMPID>::field_type
template<nximp_code IMPID>
using pni::io::nx::nxgroup< IMPID >::group_type = nxgroup<IMPID>
template<nximp_code IMPID>
using pni::io::nx::nxgroup< IMPID >::imp_type = typename nximp_map<IMPID>::group_imp
template<nximp_code IMPID>
using pni::io::nx::nxgroup< IMPID >::iterator = pni::core::container_iterator<const group_type>
template<nximp_code IMPID>
using pni::io::nx::nxgroup< IMPID >::link_type = typename nxobject_trait<IMPID>::link_type
template<nximp_code IMPID>
using pni::io::nx::nxgroup< IMPID >::object_imp_type = typename nximp_map<IMPID>::object_imp
private
template<nximp_code IMPID>
using pni::io::nx::nxgroup< IMPID >::type_type = typename nximp_map<IMPID>::type_imp
template<nximp_code IMPID>
using pni::io::nx::nxgroup< IMPID >::value_type = typename nxobject_trait<IMPID>::object_type

Constructor & Destructor Documentation

template<nximp_code IMPID>
pni::io::nx::nxgroup< IMPID >::nxgroup ( )
inlineexplicit
template<nximp_code IMPID>
pni::io::nx::nxgroup< IMPID >::nxgroup ( const group_type o)
inline

The copy constructor is doing exactly the same as the assignment operator. Thus it can be used to assign an object directly at its construction.

Parameters
ooriginal group object
template<nximp_code IMPID>
pni::io::nx::nxgroup< IMPID >::nxgroup ( group_type &&  o)
inline
template<nximp_code IMPID>
pni::io::nx::nxgroup< IMPID >::nxgroup ( imp_type &&  imp)
inlineexplicit

Construction from an implementation instance has to be done via an rvalue reference. This ensures that ownership of the implementation object is passed over to the new nxgroup instance.

Parameters
imprvalue reference to the implementation instance
template<nximp_code IMPID>
pni::io::nx::nxgroup< IMPID >::nxgroup ( const typename nxobject_trait< IMPID >::object_type &  o)
inline

Member Function Documentation

template<nximp_code IMPID>
template<typename CTYPE , typename STYPE >
CTYPE pni::io::nx::nxgroup< IMPID >::_create_auto_chunk ( const STYPE &  shape) const
inlineprivate

This utility function creates auomatically a chunk shape for a given field shape. Basically, what it does is to copy the shape and than replace the first element with a 1.

Template Parameters
CTYPEcontainer type for the chunk
STYPEcontainer type for the shape
Parameters
shapereference to STYPE with shape data
Returns
instance of CTYPE with chunk data
template<nximp_code IMPID>
template<typename T , typename CTYPE >
field_type pni::io::nx::nxgroup< IMPID >::_create_field ( const pni::core::string &  n,
const CTYPE &  shape,
const CTYPE &  chunk 
) const
inlineprivate

This member function template is doing the real work on creating a field. The frontend functions provided by the public interface take only care about the shape and chunk shape configuration. This function creates a field without a filter.

Exceptions
size_mismatch_errorif chunk and shape have different size
type_errorif data type is not supported
invalid_object_errorif the group is not valid
object_errorin case of any other error
Template Parameters
Tdata type of the field to create
CTYPEcontainer type for shape and chunk shape
Parameters
nname of the field
shapecontainer with shape information
chunkcontainer with chunk shape data
Returns
field instance
template<nximp_code IMPID>
template<typename T , typename CTYPE , typename FIMP >
field_type pni::io::nx::nxgroup< IMPID >::_create_field ( const pni::core::string &  n,
const CTYPE &  shape,
const CTYPE &  chunk,
const nxfilter< FIMP > &  filter 
) const
inlineprivate

This member function template is doing the real work on creating a field. The frontend functions provided by the public interface take only care about the shape and chunk shape configuration. This function creates a field with filter.

Exceptions
size_mismatch_errorif chunk and shape have different size
type_errorif data type is not supported
invalid_object_errorif the group is not valid
object_errorin case of any other error
Template Parameters
Tdata type of the field to create
CTYPEcontainer type for shape and chunk shape
FIMPfilter implementation type
Parameters
nname of the field
shapecontainer with shape information
chunkcontainer with chunk shape data
filterreference to a filter instance
Returns
field instance
template<nximp_code IMPID>
nxobject_trait<IMPID>::object_type pni::io::nx::nxgroup< IMPID >::at ( const pni::core::string &  n) const
inline

Returns an object by name. The name can be either an absolute or relative path.

Exceptions
invalid_object_errorif group is not valid
key_errorif child does not exist
type_errorif child type is not supported
value_errorif name contains a '/' character
object_errorin case of any other error
Parameters
npath or name of the object to open
Returns
object
template<nximp_code IMPID>
nxobject_trait<IMPID>::object_type pni::io::nx::nxgroup< IMPID >::at ( size_t  i) const
inline

Unlike open(const string &n) here the object is addressed by its index. Thus only objects directly linked below this group can be accessed.

Exceptions
index_errorif the index exceeds number of childs
invalid_object_errorif the group is not valid
type_errorif the child type is not supported
object_errorin case of any other error
Parameters
iindex of the object
Returns
object
template<nximp_code IMPID>
iterator pni::io::nx::nxgroup< IMPID >::begin ( ) const
inlinenoexcept

Return an iterator on the first child stored in below the group.

Returns
iterator
template<nximp_code IMPID>
void pni::io::nx::nxgroup< IMPID >::close ( )
inline
Exceptions
type_errorif the internal type could not be determined
object_errorin case of other errors
template<nximp_code IMPID>
template<typename T , typename CTYPE = pni::core::shape_t>
field_type pni::io::nx::nxgroup< IMPID >::create_field ( const pni::core::string &  n,
const CTYPE &  shape = {1} 
) const
inline

Create a field. The shape of the field can be specified by the optional shape argument. By default this is set to {1} which means that an expandable scalar field will be created. The chunk size for the field is automatically derived by the method by replacing the first element of the shape with 1. As an example consider the following shape for the field {100,1024,3}. This would yield a chunk size of {1,1024,3}.

If the user passes a container with shape information the container must not be empty. Otherwise an exception will be thrown.

Exceptions
size_mismatch_errorif chunk and shape have different size
type_errorif data type is not supported
invalid_object_errorif the group is not valid
object_errorin case of any other error
Template Parameters
Tdata type of the field
CTYPEcontainer type for the shape
Parameters
nname of the field
shapeoptional shape argument
Returns
instance of nxfield
template<nximp_code IMPID>
template<typename T , typename CTYPE = pni::core::shape_t>
field_type pni::io::nx::nxgroup< IMPID >::create_field ( const pni::core::string &  n,
const CTYPE &  shape,
const CTYPE &  chunk 
) const
inline

Create a new data field without a filter for compression.

nxgroup g = f["/scan_1/instrument/detector"];
shape_t shape{0,1024,1024};
shape_t chunk{1,128,1024};
nxfield field = g.create_field<uint16>("data",shape,chunk);

The chunk shape here is optional. If not given a default value will be generated from the original shape where the first dimension is set to one.

Exceptions
size_mismatch_errorif chunk and shape have different size
type_errorif data type is not supported
invalid_object_errorif the group is not valid
object_errorin case of any other error
Template Parameters
Tdata type of the field
CTYPEcontainer type for the shape and chunk
Parameters
nname (path) of the field
shapeshape of the field
chunkchunk shape of the field
Returns
instane of an nxfield object
template<nximp_code IMPID>
template<typename T , typename CTYPES , typename FIMP >
field_type pni::io::nx::nxgroup< IMPID >::create_field ( const pni::core::string &  n,
const CTYPES &  shape,
const nxfilter< FIMP > &  filter 
) const
inline

Create a multidimensional field with a filter for data compression. With this method the chunk shape for the field is determined automatically.

nxgruop g = file["/scan_1/instrument/detector"];
shape_t shape{0,2048,2048};
nxfield field = g.create_field<uint16>("data",shape,filter);
Exceptions
size_mismatch_errorif chunk and shape have different size
type_errorif data type is not supported
invalid_object_errorif the group is not valid
object_errorin case of any other error
Template Parameters
Tdata type for the filed
CTYPEScontainer type for the field shape
Parameters
nname of the field
shapeshape of the field
filterimplementation
Returns
instance of NXField
template<nximp_code IMPID>
template<typename T , typename CTYPES , typename CTYPEC , typename FIMP >
field_type pni::io::nx::nxgroup< IMPID >::create_field ( const pni::core::string &  n,
const CTYPES &  s,
const CTYPEC &  cs,
const nxfilter< FIMP > &  filter 
) const
inline

Create a field with filter and adjustable chunk shape.

nxgroup g = file.create_group("scan_1/instrument/detector");
shape_t shape{0,1024,1024};
shape_t chunk{100,1024,0};
nxfield field = g.create_field<uint16>("data",shape,chunk,filter);
Exceptions
size_mismatch_errorif chunk and shape have different size
type_errorif data type is not supported
invalid_object_errorif the group is not valid
object_errorin case of any other error
Template Parameters
Tdata type of the field
CTYPEScontainer type for the shape
CTYPECcontainer type for the chunk shape
Parameters
nname or path of the field
sshape of the field
cschunk shape of the field
filterfilter instance to use
Returns
instance of NXField
template<nximp_code IMPID>
group_type pni::io::nx::nxgroup< IMPID >::create_group ( const pni::core::string &  n,
const pni::core::string &  type = pni::core::string() 
) const
inline

Create a new group. The optional argument type determines the Nexus object type the group represents. By default type is an empty string in which case the NX_class attribute will not be written.

Exceptions
invalid_object_errorif parent is not valid
object_errorin case of any other error
Parameters
ngroup name
typenexus class type
Returns
a new instance of nxgroup
template<nximp_code IMPID>
iterator pni::io::nx::nxgroup< IMPID >::end ( ) const
inline

Returns an iterator on the last+1 obejct stored in the group.

Exceptions
invalid_object_errorif group is not valid
object_errorin case of any other error
Returns
iterator
template<nximp_code IMPID>
pni::core::string pni::io::nx::nxgroup< IMPID >::filename ( ) const
inline

Returns the name of the file the group belongs too.

Exceptions
invalid_object_errorif the field is not valid
io_errorif the filename information retrieval fails
type_errorif the internal object type does not support filename retrieval
object_errorin case of any other error
Returns
name of the file
template<nximp_code IMPID>
bool pni::io::nx::nxgroup< IMPID >::has_child ( const pni::core::string &  n) const
inline

Check if a link with name n to an object can be found below this group.

Exceptions
invalid_object_errorif group is not valid
object_errorin case of any other error
Parameters
nname of the link (object) to look for
Returns
true if the object exist, false otherwise
template<nximp_code IMPID>
const imp_type& pni::io::nx::nxgroup< IMPID >::imp ( ) const
inlinenoexcept
template<nximp_code IMPID>
bool pni::io::nx::nxgroup< IMPID >::is_valid ( ) const
inline

Returns true if the group is valid, false otherwise.

Exceptions
object_errorif validity check fails
Returns
group validity
template<nximp_code IMPID>
pni::core::string pni::io::nx::nxgroup< IMPID >::name ( ) const
inline

Returns the name of the group

Exceptions
invalid_object_errorif group is not valid
type_errorif the internals object type cannot be determined
io_errorin case of errors during reading data
object_errorin case of any other error
Returns
group name
template<nximp_code IMPID>
group_type& pni::io::nx::nxgroup< IMPID >::operator= ( const group_type g)
inline
template<nximp_code IMPID>
group_type& pni::io::nx::nxgroup< IMPID >::operator= ( group_type &&  g)
inline
template<nximp_code IMPID>
group_type& pni::io::nx::nxgroup< IMPID >::operator= ( const typename nxobject_trait< IMPID >::object_type &  o)
inline
template<nximp_code IMPID>
nxobject_trait<IMPID>::object_type pni::io::nx::nxgroup< IMPID >::operator[] ( const pni::core::string &  n) const
inline

Opens an object using the [] operator. w

Exceptions
invalid_object_errorif group is not valid
key_errorif child does not exist
type_errorif child type is not supported
value_errorif name contains a '/' value error
object_errorin case of any other error
Parameters
nname or path of the object
Returns
object
template<nximp_code IMPID>
nxobject_trait<IMPID>::object_type pni::io::nx::nxgroup< IMPID >::operator[] ( size_t  i) const
inline

Opens an object by index using the [] operator.

Exceptions
index_errorif the index exceeds number of childs
invalid_object_errorif the group is not valid
type_errorif the child type is not supported
object_errorin case of any other error
Parameters
iindex of the object
Returns
object
template<nximp_code IMPID>
nxobject_trait<IMPID>::object_type pni::io::nx::nxgroup< IMPID >::parent ( ) const
inline

Return the parent object of the gruop.

Exceptions
invalid_object_errorif group is not valid
type_errorif the parents object type is unkown
object_errorin case of any other error
Returns
parent object
template<nximp_code IMPID>
void pni::io::nx::nxgroup< IMPID >::remove ( const pni::core::string &  n) const
inline

Remove the link with name n to an object. As objects are not really delted this will only remove a particular link to an object. If this was the only link the object is no longer accessible. However, the object still exists. You have to use h5repack in order to physically delete the object from the file.

Exceptions
key_errorif the child does not exist
invalid_object_errorif group is not valid
object_errorin case of any other error
Parameters
nname of the link to delete
template<nximp_code IMPID>
size_t pni::io::nx::nxgroup< IMPID >::size ( ) const
inline

Returns the number of children attached to this group.

Exceptions
invalid_object_errorif group is not valid
object_errorin case of any other error
Returns
number of children

Field Documentation

template<nximp_code IMPID>
imp_type pni::io::nx::nxgroup< IMPID >::_imp
private
template<nximp_code IMPID>
nxattribute_manager<group_type> pni::io::nx::nxgroup< IMPID >::attributes

This public attribute provides access to the groups attribute manager.

See also
nxattribute_manager

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