libpniio
|
![]() |
Data Structures | |
struct | pni::io::nx::xml::attribute |
read and write attributes More... | |
class | pni::io::nx::xml::data_node |
node IO More... | |
struct | pni::io::nx::xml::write_no_data |
default data predicate More... | |
class | pni::io::nx::xml::dimensions |
reading and writing dimensions More... | |
struct | pni::io::nx::xml::field |
read and write field data More... | |
struct | pni::io::nx::xml::group |
read and write groups More... | |
struct | pni::io::nx::xml::io_node |
general IO objects More... | |
class | pni::io::nx::xml::link |
manages links in XML More... | |
Typedefs | |
typedef boost::mpl::map < boost::mpl::pair < pni::core::uint8, pni::core::uint64 > , boost::mpl::pair < pni::core::uint16, pni::core::uint64 > , boost::mpl::pair < pni::core::uint32, pni::core::uint64 > , boost::mpl::pair < pni::core::uint64, pni::core::uint64 > , boost::mpl::pair < pni::core::int8, pni::core::int64 > , boost::mpl::pair < pni::core::int16, pni::core::int64 > , boost::mpl::pair < pni::core::int32, pni::core::int64 > , boost::mpl::pair < pni::core::int64, pni::core::int64 > , boost::mpl::pair < pni::core::float32, pni::core::float128 > , boost::mpl::pair < pni::core::float64, pni::core::float128 > , boost::mpl::pair < pni::core::float128, pni::core::float128 > , boost::mpl::pair < pni::core::complex32, pni::core::complex128 > , boost::mpl::pair < pni::core::complex64, pni::core::complex128 > , boost::mpl::pair < pni::core::complex128, pni::core::complex128 > > | pni::io::nx::xml::max_type_map |
maximum type maps More... | |
typedef std::pair< size_t, size_t > | pni::io::nx::xml::index_value_type |
index-value type More... | |
using | pni::io::nx::xml::node = boost::property_tree::ptree |
alias for ptree More... | |
Functions | |
template<typename ATYPE > | |
ATYPE | pni::io::nx::xml::make_array (const node &data) |
generate an array More... | |
template<> | |
pni::core::array | pni::io::nx::xml::make_array (const node &data) |
generate an array type erasure More... | |
bool | pni::io::nx::xml::operator< (const index_value_type &lhs, const index_value_type &rhs) |
comparison operator for index_value_type More... | |
template<typename T , typename OTYPE > | |
void | pni::io::nx::xml::write_object_data (OTYPE &o, node &n) |
write data from Nexus to XML More... | |
template<typename OTYPE > | |
void | pni::io::nx::xml::write_object_data (OTYPE &p, node &n) |
write data from a Nexus object to XML More... | |
template<typename OTYPE , typename PTYPE > | |
void | pni::io::nx::xml::append_attributes (const OTYPE &parent, node &p, PTYPE &write_predicate) |
append attributes from a nexus type to XML More... | |
template<typename GTYPE , typename FTYPE , typename ATYPE , typename LTYPE , typename PTYPE > | |
void | pni::io::nx::xml::nexus_to_xml (nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &p, node &n, PTYPE write_predicate) |
nexus to XML conversion More... | |
template<template< nximp_code > class OTYPE, nximp_code IMPID, typename PTYPE > | |
void | pni::io::nx::xml::nexus_to_xml (OTYPE< IMPID > &o, node &n, PTYPE write_predicate) |
nexus to XML conversion More... | |
template<typename GTYPE , typename FTYPE , typename ATYPE , typename LTYPE > | |
void | pni::io::nx::xml::nexus_to_xml (nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &p, node &n) |
nexus to XML conversion More... | |
node | pni::io::nx::xml::create_from_string (const pni::core::string &s) |
create xml node from string More... | |
node | pni::io::nx::xml::create_from_file (const pni::core::string &s) |
create xml node from file More... | |
pni::core::string | pni::io::nx::xml::attribute_path (const pni::core::string &name) |
create an attribute path More... | |
node | pni::io::nx::xml::get_attribute (const node &parent, const pni::core::string &name) |
get attribute node More... | |
bool | pni::io::nx::xml::has_attribute (const node &parent, const pni::core::string &name) |
check for attribute existence More... | |
pni::core::string | pni::io::nx::xml::get_name (const node &n) |
get name of a node More... | |
std::ostream & | pni::io::nx::xml::operator<< (std::ostream &o, const node &n) |
XML stream output. More... | |
template<typename T , typename OTYPE > | |
void | pni::io::nx::xml::write_node_data (const OTYPE &object, const node &n) |
write data from buffer More... | |
template<typename OTYPE > | |
void | pni::io::nx::xml::write_node_data (const OTYPE &object, const node &n) |
write node data More... | |
template<typename GTYPE , typename FTYPE , typename ATYPE , typename LTYPE , typename PTYPE > | |
void | pni::io::nx::xml::xml_to_nexus (const node &t, const nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &parent, PTYPE write_data) |
create objects from XML More... | |
template<typename GTYPE , typename FTYPE , typename ATYPE , typename LTYPE > | |
void | pni::io::nx::xml::xml_to_nexus (const node &t, const nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &parent) |
create objects from XML More... | |
template<template< pni::io::nx::nximp_code > class OTYPE, pni::io::nx::nximp_code IMPID, typename PTYPE > | |
void | pni::io::nx::xml::xml_to_nexus (const node &t, const OTYPE< IMPID > &group, PTYPE write_data) |
create objects from XML More... | |
template<template< pni::io::nx::nximp_code > class OTYPE, pni::io::nx::nximp_code IMPID> | |
void | pni::io::nx::xml::xml_to_nexus (const node &t, const OTYPE< IMPID > &group) |
create objects from XML More... | |
Variables | |
static const std::map < pni::core::string, bool > | pni::io::nx::xml::bool_string_map {"1",true} |
bool representation map More... | |
Creating the structure of a Nexus file can be rather tedious when coded statically. Additionally such an approach is usually rather inflexible and thus should be avoided at all. libpniio
provides utility functions to create Nexus objects using XML templates. Fortunately, Nexus comes with its own XML dialect called NXDL which already defines the XML vocabulary necessary to describie Nexus files with XML.
Using NXDL makes programs much more flexible and gives users the possibility to customize the layout of a Nexus file without rewriting code.
Under the hood the XML/NXDL facility provided here is based on BOOST::property_tree providing a non-validating XML parser. However, for our purpose validation is not really required.
typedef std::pair<size_t,size_t> pni::io::nx::xml::index_value_type |
This type describes an index value pair used in NXDL to describe a single dimension. The first component is the index of the particular dimensions while the second one denotes the number of elements along this dimension.
typedef boost::mpl::map< boost::mpl::pair<pni::core::uint8,pni::core::uint64>, boost::mpl::pair<pni::core::uint16,pni::core::uint64>, boost::mpl::pair<pni::core::uint32,pni::core::uint64>, boost::mpl::pair<pni::core::uint64,pni::core::uint64>, boost::mpl::pair<pni::core::int8,pni::core::int64>, boost::mpl::pair<pni::core::int16,pni::core::int64>, boost::mpl::pair<pni::core::int32,pni::core::int64>, boost::mpl::pair<pni::core::int64,pni::core::int64>, boost::mpl::pair<pni::core::float32,pni::core::float128>, boost::mpl::pair<pni::core::float64,pni::core::float128>, boost::mpl::pair<pni::core::float128,pni::core::float128>, boost::mpl::pair<pni::core::complex32,pni::core::complex128>, boost::mpl::pair<pni::core::complex64,pni::core::complex128>, boost::mpl::pair<pni::core::complex128,pni::core::complex128> > pni::io::nx::xml::max_type_map |
This map defines the maximum type for every numeric type provided by pnicore. It is used when reading data from an attribute or node.
using pni::io::nx::xml::node = typedef boost::property_tree::ptree |
This alias creates the new type name node which can be used within the xml namespace instead of boost::property_tree::ptree;
void pni::io::nx::xml::append_attributes | ( | const OTYPE & | parent, |
node & | p, | ||
PTYPE & | write_predicate | ||
) |
Reads all attribtues from a Nexus node and append them to an XML node. There are several attribute which are omitted as they are part of the XML tag
Whether or not data form the Nexus object is written to the XML output depends on the write_predicate. This is a callable which takes the Nexus object as its only argument and returns true if the data should be written or false otherwise.
OTYPE | Nexus object type |
PTYPE | write predicate type |
parent | the object with the attributes |
p | XML node to which attribute tags should be appended |
write_predicate | function object determinig when to write data to the XML output |
pni::core::string pni::io::nx::xml::attribute_path | ( | const pni::core::string & | name | ) |
This function is intended for internal use only. It creates a valid attribute path from an attribute name.
name | the name of the attribute |
node pni::io::nx::xml::create_from_file | ( | const pni::core::string & | s | ) |
Reads XML data from a file and returns an XML node refering to the root element of the XML tree.
pni::io::parser_error | in case of parsing issues |
file_error | in case of problems opening the file |
s | name of the file |
node pni::io::nx::xml::create_from_string | ( | const pni::core::string & | s | ) |
Parses a string provided by the user and returns an XML node from it.
parser_error | in case of parsing problems |
s | string from which to read the data |
node pni::io::nx::xml::get_attribute | ( | const node & | parent, |
const pni::core::string & | name | ||
) |
Returns an attribute node from its parent node.
key_error | if the attribute does not exist |
parser_error | in case of any other error |
parent | the node from which to retrieve the attribute |
name | the name of the attribute |
string pni::io::nx::xml::get_name | ( | const node & | n | ) |
Return the name of a node as determined by the content of its name attribute. This is a convenience function. If the node does not have a name attribute an empty string is returned.
n | node with name attribute |
bool pni::io::nx::xml::has_attribute | ( | const node & | parent, |
const pni::core::string & | name | ||
) |
Returns true if the node parent has a an attribute name attached to it. Otherwise false is returned.
parent | reference to the parent node |
name | the attributes name |
pni::core::array pni::io::nx::xml::make_array | ( | const node & | data | ) |
generate an array type erasure
This function template generates an instance of an mdarray from a data node and stores the data in this array. The data type is determined by the user and must match the data type stored in the array.
data | the XML node holding the daata |
pni::core::array pni::io::nx::xml::make_array | ( | const node & | data | ) |
This specialization of the make_array function template returns an array type erasure. This function is particularly useful in situations where we only need to transfer data and the data type is of no further important.
data | the XML node with data |
generate an array type erasure
This function template generates an instance of an mdarray from a data node and stores the data in this array. The data type is determined by the user and must match the data type stored in the array.
data | the XML node holding the daata |
void pni::io::nx::xml::nexus_to_xml | ( | nxobject< GTYPE, FTYPE, ATYPE, LTYPE > & | p, |
node & | n, | ||
PTYPE | write_predicate | ||
) |
Converts the structure of a Nexus tree stored below p into an XML tree below n. The Nexus parent object p is provided as an instance of nxobject. Which data from the Nexus file goes to the XML output is determined by the write_predicate, a functor taking a single Nexus object as its argument and returns true if the data should be written and false otherwise.
GTYPE | Nexus group type |
FTYPE | Nexus field type |
ATYPE | Nexus attribute type |
LTYPE | link type |
PTYPE | write predicate type |
p | parent object |
n | XML node |
write_data | functor determining which data to write |
void pni::io::nx::xml::nexus_to_xml | ( | OTYPE< IMPID > & | o, |
node & | n, | ||
PTYPE | write_predicate | ||
) |
Converts the content of Nexus object to XML. Here the Nexus object is is passed as an instance of nxattribute, nxgroup, or nxfield. The write_predicate functor determines which data is written to the XML output.
OTYPE | Nexus object type |
IMPID | implementation ID |
PTYPE | predicate type |
o | parent object |
n | XML node |
write_predicate | the functor determining which data to write |
void pni::io::nx::xml::nexus_to_xml | ( | nxobject< GTYPE, FTYPE, ATYPE, LTYPE > & | p, |
node & | n | ||
) |
Converts the structure of a Nexus tree stored below p into an XML tree below n. The Nexus parent object p is provided as an instance of nxobject. This template function takes no write predicate and thus no data from the Nexus file is written to the XML output.
GTYPE | Nexus group type |
FTYPE | Nexus field type |
ATYPE | Nexus attribute type |
LTYPE | link type |
p | parent object |
n | XML node |
bool pni::io::nx::xml::operator< | ( | const index_value_type & | lhs, |
const index_value_type & | rhs | ||
) |
Operator required to sort containers using index_value_type as their element type. index-value pairs are ordered by their dimension index. This operator returns true if the index component of the LHS is smaller than the index component of the RHS.
lhs | left handside of the operator |
rhs | right handside of the operator |
std::ostream & pni::io::nx::xml::operator<< | ( | std::ostream & | o, |
const node & | n | ||
) |
Write property tree structure as XML to an output stream.
o | reference output stream |
n | node to write to the output stream |
void pni::io::nx::xml::write_node_data | ( | const OTYPE & | object, |
const node & | n | ||
) |
Read data from the CDATA section of an XML tag and store it in an NeXus object. The data type used for reading the data is determined by the user supplied template parameter.
type_error | if the data type cannot be read or handled by the write function |
parser_error | if the data could not be read from the CDATA section of the tag |
invalid_object_error | if the target object is not valid |
io_error | if writing the data fails |
size_mismatch_error | if the amount of data read from CDATA does not match the size of the NeXus object |
object_error | in case of any other error |
T | data type to use for writing |
OTYPE | object type to which to write the data |
object | the object instance to which to write the data |
n | the node holding the data |
void pni::io::nx::xml::write_node_data | ( | const OTYPE & | object, |
const node & | n | ||
) |
Write the data stored in an XML tag to a NeXus object. This is a utilty function which calles an appropriate instantiation of the write_node_data function template for every particular data type.
type_error | if the data type cannot be read or handled by the write function |
parser_error | if the data could not be read from the CDATA section of the tag |
invalid_object_error | if the target object is not valid |
io_error | if writing the data fails |
size_mismatch_error | if the amount of data read from CDATA does not match the size of the NeXus object |
object_error | in case of any other error |
OTYPE | object type to which to write the data |
object | the object instance to which to write the data |
n | the node holding the data |
void pni::io::nx::xml::write_object_data | ( | OTYPE & | o, |
node & | n | ||
) |
This function template writes data from a Nexus object to the CDATA section of an XML tag.
T | data type to use |
OTYPE | Nexus object type |
o | Nexus object from which to read the data |
n | XML tag where to store the data |
void pni::io::nx::xml::write_object_data | ( | OTYPE & | p, |
node & | n | ||
) |
Read data from a Nexus object and store it to the CDATA section of an XML tag. This function template only does type dispatching.
OTYPE | Nexus object type |
p | the Nexus object from which to read the data |
n | the XML node where to store the data |
void pni::io::nx::xml::xml_to_nexus | ( | const node & | t, |
const nxobject< GTYPE, FTYPE, ATYPE, LTYPE > & | parent, | ||
PTYPE | write_data | ||
) |
Recursively creates the objects as described in the XML file below parent. The parent is passed as a reference to an instance of nxobject.
parser_error | in case of XML parsing problems |
invalid_object_error | if the parent object is not valid |
io_error | if data or metadata write failed |
type_error | if a data type is involved that cannot be handled |
object_error | in case of any other error |
GTYPE | group type |
FTYPE | field type |
ATYPE | attribute type |
LTYPE | link type |
t | ptree instance with the XML data |
parent | instance of nxobject |
write_data | predicate function determining when data should be written |
void pni::io::nx::xml::xml_to_nexus | ( | const node & | t, |
const nxobject< GTYPE, FTYPE, ATYPE, LTYPE > & | parent | ||
) |
A version of xml_to_nexus where no data is written to the file at all. The parent is passed as a reference to nxobject.
parser_error | in case of XML parsing problems |
invalid_object_error | if the parent object is not valid |
io_error | if data or metadata write failed |
type_error | if a data type is involved that cannot be handled |
object_error | in case of any other error |
GTYPE | group type |
FTYPE | field type |
ATYPE | attribute type |
LTYPE | link type |
t | ptree instance with the XML data |
parent | instance of nxobject |
void pni::io::nx::xml::xml_to_nexus | ( | const node & | t, |
const OTYPE< IMPID > & | group, | ||
PTYPE | write_data | ||
) |
An overload of the xml_to_nexus function template where the parent is passed as an instance of nxgroup.
parser_error | in case of XML parsing problems |
invalid_object_error | if the parent object is not valid |
io_error | if data or metadata write failed |
type_error | if a data type is involved that cannot be handled |
object_error | in case of any other error |
OTYPE | parent template |
IMPID | implementation ID |
PTYPE | data writer predicate |
t | XML node from which to construct the Nexus structure |
group | the parent group below which the structure should be generated |
write_data | predicate to determine whether or tag data should be written to the file |
void pni::io::nx::xml::xml_to_nexus | ( | const node & | t, |
const OTYPE< IMPID > & | group | ||
) |
An overload of the xml_to_nexus function template where the parent is passed as an instance of nxgroup.
parser_error | in case of XML parsing problems |
invalid_object_error | if the parent object is not valid |
io_error | if data or metadata write failed |
type_error | if a data type is involved that cannot be handled |
object_error | in case of any other error |
OTYPE | parent template |
IMPID | implementation ID |
PTYPE | data writer predicate |
t | XML node from which to construct the Nexus structure |
group | the parent group below which the structure should be generated |
write_data | predicate to determine whether or tag data should be written to the file |
|
static |
A static map with all valid representations of boolean values.