libpniio
field_imp.hpp
Go to the documentation of this file.
1 //
2 // (c) Copyright 2014 DESY, Eugen Wintersberger <eugen.wintersberger@desy.de>
3 //
4 // This file is part of libpniio.
5 //
6 // libpniio is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // libpniio is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with libpniio. If not, see <http://www.gnu.org/licenses/>.
18 // ===========================================================================
19 //
20 // Created on: Jul 16, 2014
21 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
22 //
23 #pragma once
24 
25 #include <pni/core/types.hpp>
26 
27 
28 #include "object_imp.hpp"
29 #include "type_imp.hpp"
30 #include "h5dataspace.hpp"
31 #include "h5datatype.hpp"
32 #include "h5filter.hpp"
33 #include "attribute_imp.hpp"
34 #include "selection.hpp"
35 
36 
37 namespace pni{
38 namespace io{
39 namespace nx{
40 namespace h5{
41 
42  //forward declarations
43  class group_imp;
44 
51  class field_imp
52  {
53  private:
62 
63  //----------------------------------------------------------------
74  void _update();
75 
76  //----------------------------------------------------------------
91  void _read_data(const h5datatype &memtype,
92  const h5dataspace &memspace,
93  const h5dataspace &filespace,
94  const object_imp &xfer_list,
95  void *ptr) const;
96 
97  //----------------------------------------------------------------
110  void _write_data(const h5datatype &memtype,
111  const h5dataspace &memspace,
112  const h5dataspace &filespace,
113  const void *ptr) const;
114 
115  //-----------------------------------------------------------------
129  void _throw_if_not_valid(const pni::core::exception_record &record,
130  const pni::core::string &message) const
131  {
132  if(!is_valid())
133  throw invalid_object_error(record,message);
134  }
135 
136  public:
137  //===================Constructors and destructors==================
141  explicit field_imp() noexcept;
142 
143  //-----------------------------------------------------------------
158  explicit field_imp(object_imp &&o);
159 
160  //-----------------------------------------------------------------
178  explicit field_imp(const group_imp &parent,
179  const pni::core::string &name,
180  pni::core::type_id_t tid,
181  const type_imp::index_vector_type &shape,
182  const type_imp::index_vector_type &chunk,
183  const h5filter &filter = h5filter());
184 
185 
186  //=================methods to modify the dataset===================
201  void grow(const size_t &e=0,const size_t &n=1) ;
202 
203  //-----------------------------------------------------------------
214  size_t size() const;
215 
216  //-----------------------------------------------------------------
227  type_imp::index_vector_type shape() const;
228 
229  //-----------------------------------------------------------------
240  size_t rank() const;
241 
242  //-----------------------------------------------------------------
254  pni::core::type_id_t type_id() const ;
255 
256  //-----------------------------------------------------------------
267  void apply_selection(const type_imp::selection_vector_type &s);
268 
269  //----------------------------------------------------------------
275  void clear_selections() ;
276 
277  //===================reading data methods==========================
294  void read(pni::core::type_id_t tid,
295  const type_imp::index_vector_type &shape,
296  void *ptr) const;
297 
298  //===============writing data methods==============================
317  void write(pni::core::type_id_t tid,
318  const type_imp::index_vector_type &shape,
319  const void *ptr) const;
320 
321 
322  //=================================================================
323  // DEFAULT OBJECT METHODS
324  //=================================================================
337  pni::core::string name() const;
338 
339  //---------------------------------------------------------------
352  object_imp parent() const;
353 
354  //----------------------------------------------------------------
367  pni::core::string filename() const;
368 
369  //-----------------------------------------------------------------
378  void close();
379 
380  //----------------------------------------------------------------
391  bool is_valid() const;
392 
393  //=================================================================
394  //ATTRIBUTE INTERFACE
395  //=================================================================
396 
397  //----------------------------------------------------------------
412  attribute_imp attr(const pni::core::string &name,
413  pni::core::type_id_t tid,
414  bool overwrite=false) const;
415 
416  //----------------------------------------------------------------
432  attribute_imp attr(const pni::core::string &name,
433  pni::core::type_id_t tid,
434  const type_imp::index_vector_type &shape,
435  bool overwrite=false) const;
436 
437  //----------------------------------------------------------------
448  attribute_imp attr(const pni::core::string &name) const;
449 
450  //----------------------------------------------------------------
461  attribute_imp attr(size_t i) const;
462 
463  //----------------------------------------------------------------
473  size_t nattr() const ;
474 
475  //----------------------------------------------------------------
488  bool has_attr(const pni::core::string &name) const;
489 
490  //----------------------------------------------------------------
502  void del_attr(const pni::core::string &name) const;
503  };
504 
505 
506 //end of namespace
507 }
508 }
509 }
510 }
object_imp _object
object guard
Definition: field_imp.hpp:55
dataspace object
Definition: h5dataspace.hpp:68
dataset object
Definition: field_imp.hpp:51
size_t rank() const
rank of the dataset
Definition: field_imp.cpp:145
size_t size() const
total number of elements
Definition: field_imp.cpp:133
field_imp() noexcept
default constructor
Definition: field_imp.cpp:57
void write(pni::core::type_id_t tid, const type_imp::index_vector_type &shape, const void *ptr) const
write a single value
Definition: field_imp.cpp:234
unexpected invalid object
Definition: exceptions.hpp:130
object_imp parent() const
get parent object
Definition: field_imp.cpp:302
bool _selection_applied
check whether to apply the selection
Definition: field_imp.hpp:61
attribute implementation
Definition: attribute_imp.hpp:45
provide implementation specific types
Definition: type_imp.hpp:46
HDF5 group object.
Definition: group_imp.hpp:47
HDF5 type wrapper.
Definition: h5datatype.hpp:43
Definition: cbf_reader.hpp:41
basic HDF5 ID wrapper
Definition: object_imp.hpp:59
describe a selection in an HDF5 file
Definition: selection.hpp:37
void _write_data(const h5datatype &memtype, const h5dataspace &memspace, const h5dataspace &filespace, const void *ptr) const
write data to file
Definition: field_imp.cpp:267
type_imp::index_vector_type shape() const
shape of dataset
Definition: field_imp.cpp:112
void _update()
update internal parameters
Definition: field_imp.cpp:46
size_t nattr() const
get number of attributes
Definition: field_imp.cpp:338
base class for filter implementations
Definition: h5filter.hpp:48
pni::core::type_id_t type_id() const
datatype ID
Definition: field_imp.cpp:123
void grow(const size_t &e=0, const size_t &n=1)
extend the shape along a dimension
Definition: field_imp.cpp:91
void del_attr(const pni::core::string &name) const
delete an attribute
Definition: field_imp.cpp:350
void clear_selections()
remove a selection
Definition: field_imp.cpp:392
pni::core::string name() const
get name
Definition: field_imp.cpp:293
bool is_valid() const
check group validity
Definition: field_imp.cpp:320
void close()
close the dataset
Definition: field_imp.cpp:286
void _read_data(const h5datatype &memtype, const h5dataspace &memspace, const h5dataspace &filespace, const object_imp &xfer_list, void *ptr) const
read data from file
Definition: field_imp.cpp:157
selection _selection
local selection object
Definition: field_imp.hpp:59
pni::core::string filename() const
get filename
Definition: field_imp.cpp:311
void apply_selection(const type_imp::selection_vector_type &s)
apply a selection
Definition: field_imp.cpp:381
h5dataspace _file_space
dataspace on file
Definition: field_imp.hpp:57
void read(pni::core::type_id_t tid, const type_imp::index_vector_type &shape, void *ptr) const
reading simple data from the dataset
Definition: field_imp.cpp:176
bool has_attr(const pni::core::string &name) const
check if attribute exists
Definition: field_imp.cpp:344
attribute_imp attr(const pni::core::string &name, pni::core::type_id_t tid, bool overwrite=false) const
create scalar attribute
void _throw_if_not_valid(const pni::core::exception_record &record, const pni::core::string &message) const
throw if not valid
Definition: field_imp.hpp:129