31 #include <pni/core/types.hpp>
32 #include <pni/core/arrays/mdarray.hpp>
33 #include <pni/core/arrays/array_view.hpp>
34 #include <pni/core/arrays/slice.hpp>
35 #include <pni/core/type_erasures/array.hpp>
36 #include <pni/core/error.hpp>
117 template<nximp_code IMPID>
class nxfield
150 static pni::core::string
152 const pni::core::shape_t &fshape)
154 std::stringstream ss;
155 ss<<
"Array shape ( ";
156 for(
auto v: ashape) ss<<v<<
" ";
157 ss<<
") and field shape ( ";
158 for(
auto v: fshape) ss<<v<<
" ";
159 ss<<
") do not match!";
183 template<
typename ATYPE>
188 typedef typename type_type::index_vector_type index_vector_type;
189 check_allocation_state(a,EXCEPTION_RECORD);
190 check_equal_size(a,*
this,EXCEPTION_RECORD);
193 a.template shape<index_vector_type>(),a.data());
215 template<
typename ATYPE>
220 typedef typename type_type::index_vector_type index_vector_type;
221 check_allocation_state(a,EXCEPTION_RECORD);
222 check_equal_size(a,*
this,EXCEPTION_RECORD);
225 a.template shape<index_vector_type>(),a.data());
262 _imp(
std::move(o._imp)),
298 _imp.clear_selections();
310 if(
this == &f)
return *
this;
325 if(
this == &f)
return *
this;
327 _imp = std::move(f._imp);
358 template<
typename CTYPE> CTYPE
shape()
const
360 return type_type::template from_index_vector<CTYPE>(_imp.shape());
393 return _imp.type_id();
414 return group_type(group_imp_type(_imp.parent()));
433 void grow(
const size_t &e,
const size_t &n=1)
467 template<
typename T>
void read(T &value)
const
481 typedef typename type_type::index_vector_type index_vector_type;
483 throw size_mismatch_error(EXCEPTION_RECORD,
484 "Field is not scalar!");
509 void read(
size_t n,T *values)
const
512 typedef typename type_type::index_vector_type index_vector_type;
514 throw size_mismatch_error(EXCEPTION_RECORD,
515 "Field size does not match memory size!");
538 void read(std::vector<T> &data)
const
540 read(data.size(),data.data());
577 void read(pni::core::mdarray<STORAGE,IMAP,IPA> &array)
const
583 template<
typename ATYPE>
584 void read(pni::core::array_view<ATYPE> &v)
const
586 if(v.is_contiguous())
590 typedef typename ATYPE::value_type value_type;
591 typedef dynamic_array<value_type> buffer_type;
592 auto buffer = buffer_type::create(v.template shape<pni::core::shape_t>());
594 std::copy(buffer.begin(),buffer.end(),v.begin());
599 template<
typename ATYPE>
600 void read(pni::core::array_view<ATYPE> &&v)
const
640 template<
typename T>
void write(
const T &value)
const
653 typedef typename type_type::index_vector_type index_vector_type;
654 static_assert(!std::is_pointer<T>::value,
"no pointer");
656 throw size_mismatch_error(EXCEPTION_RECORD,
657 "Field is not scalar!");
683 template<
typename T>
void write(
size_t n,
const T *value)
const
686 typedef typename type_type::index_vector_type index_vector_type;
689 throw size_mismatch_error(EXCEPTION_RECORD,
690 "Field size does not match memory size!");
694 static_cast<const void*
>(value));
697 static_cast<const void*
>(value));
720 void write(
const std::vector<T> &data)
const
722 write(data.size(),data.data());
751 void write(
const pni::core::mdarray<STORAGE,IMAP,IPA> &a)
const
779 template<
typename ATYPE>
780 void write(
const pni::core::array_view<ATYPE> &v)
const
782 if(v.is_contiguous())
786 typedef typename ATYPE::value_type value_type;
787 typedef dynamic_array<value_type> array_type;
788 auto buffer = array_type::create(v.template shape<pni::core::shape_t>());
789 std::copy(v.begin(),v.end(),buffer.begin());
836 void write(
const pni::core::array &a)
const
857 template<
typename ...ITYPES>
872 typedef std::vector<pni::core::slice> container_type;
873 field_type new_field(*
this);
875 new_field.
_imp.apply_selection(container_type({pni::core::slice(indices)...}));
892 _imp.clear_selections();
914 field_type
operator()(
const std::vector<pni::core::slice> &selection)
const
916 field_type new_field(*
this);
917 new_field.
_imp.apply_selection(selection);
953 return _imp.filename();
978 return _imp.is_valid();
attribute manager template
Definition: nxattribute_manager.hpp:42
void read(size_t n, T *values) const
reading data to memory
Definition: nxfield.hpp:509
size_t size() const
return size
Definition: nxfield.hpp:374
pni::io::nx::nxfield< nximp_code::HDF5 > nxfield
Definition: nx_hdf5_implementation.hpp:50
nxobject_trait< IMPID >::attribute_type attribute_type
attribute type
Definition: nxfield.hpp:135
void write(const T &value) const
write a single value
Definition: nxfield.hpp:650
nxfield(field_type &&o)
move constructor
Definition: nxfield.hpp:261
void grow(const size_t &e, const size_t &n=1)
grow field along a particular dimension
Definition: nxfield.hpp:433
imp_type _imp
field implementation
Definition: nxfield.hpp:138
implementation map
Definition: nximp_map.hpp:50
void read(pni::core::array_view< ATYPE > &&v) const
Definition: nxfield.hpp:600
nexus object traits
Definition: nxobject_traits.hpp:44
bool is_valid() const noexcept
check validity
Definition: nxfield.hpp:976
size_t rank() const
number of dimensions
Definition: nxfield.hpp:449
field_type & operator=(const field_type &f)
copy assignment operator
Definition: nxfield.hpp:308
void read(array &a) const
read data to a array instance
Definition: nxfield.hpp:622
nxfield base class
Definition: nxfield.hpp:124
void read(pni::core::mdarray< STORAGE, IMAP, IPA > &array) const
read data to array
Definition: nxfield.hpp:577
nxfield(imp_type &&o)
move constructor from implementation object
Definition: nxfield.hpp:270
pni::core::string name() const
return field name
Definition: nxfield.hpp:932
pni::core::type_id_t type_id(const h5datatype &o)
get type code
Definition: h5datatype.cpp:240
Definition: cbf_reader.hpp:41
field_type operator()(ITYPES...indices) const
set a selection on the field
Definition: nxfield.hpp:870
void write(const pni::core::array &a) const
write array erasure
Definition: nxfield.hpp:836
field_type & operator=(const typename nxobject_trait< IMPID >::object_type &o)
conversion assignment
Definition: nxfield.hpp:340
~nxfield()
destructor
Definition: nxfield.hpp:296
field_type & operator=(field_type &&f)
move assignment operator
Definition: nxfield.hpp:323
nxattribute_manager< field_type > attributes
attribute manager
Definition: nxfield.hpp:238
nxobject_trait< IMPID >::object_type parent() const
get parent object
Definition: nxfield.hpp:409
void _write_array(const ATYPE &a) const
write data from array
Definition: nxfield.hpp:216
static pni::core::string _shape_mismatch_error_message(const pni::core::shape_t &ashape, const pni::core::shape_t &fshape)
gernerate error message
Definition: nxfield.hpp:151
FTYPE as_field(const nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &o)
as field wrapper
Definition: as_field.hpp:166
void write(const pni::core::array_view< ATYPE > &v) const
write data from array view
Definition: nxfield.hpp:780
void close()
close field
Definition: nxfield.hpp:964
nximp_map< IMPID >::type_imp type_type
type implementation type
Definition: nxfield.hpp:130
nxfield< IMPID > field_type
typedef for this type
Definition: nxfield.hpp:132
CTYPE shape() const
field shape
Definition: nxfield.hpp:358
void read(std::vector< T > &data) const
reading data vector
Definition: nxfield.hpp:538
pni::core::string filename() const
return filename
Definition: nxfield.hpp:951
field_type operator()(const std::vector< pni::core::slice > &selection) const
set a selection on the field
Definition: nxfield.hpp:914
nxfield(const field_type &o)
copy constructor
Definition: nxfield.hpp:252
void write(size_t n, const T *value) const
write data from memory
Definition: nxfield.hpp:683
void write(const char *value) const
write old style string
Definition: nxfield.hpp:812
void read(pni::core::array_view< ATYPE > &v) const
Definition: nxfield.hpp:584
field_type operator()()
clear a selection
Definition: nxfield.hpp:890
nxfield(const typename nxobject_trait< IMPID >::object_type &o)
constructor
Definition: nxfield.hpp:284
void write(const std::vector< T > &data) const
write data from vector
Definition: nxfield.hpp:720
void write(const pni::core::mdarray< STORAGE, IMAP, IPA > &a) const
write data from mdarray
Definition: nxfield.hpp:751
nxfield()
default constructor
Definition: nxfield.hpp:243
nximp_map< IMPID >::field_imp imp_type
implementation type
Definition: nxfield.hpp:128
void read(T &value) const
reading simple data from the dataset
Definition: nxfield.hpp:477
pni::core::type_id_t type_id() const
get the type ID
Definition: nxfield.hpp:391
void _read_array(ATYPE &a) const
read data to array
Definition: nxfield.hpp:184