libpniio
attribute_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<sstream>
26 
27 #include <pni/core/types.hpp>
28 
29 #include "object_imp.hpp"
30 #include "type_imp.hpp"
31 #include "h5dataspace.hpp"
32 #include "h5datatype.hpp"
33 #include "selection.hpp"
34 #include "selection_guard.hpp"
35 
36 namespace pni{
37 namespace io{
38 namespace nx{
39 namespace h5{
40 
46  {
47  private:
54 
59 
60  //-----------------------------------------------------------------
72  void __update();
73 
74  //----------------------------------------------------------------
86  void _from_disk(const h5datatype &memtype,void *ptr) const;
87 
88  //----------------------------------------------------------------
102  void _read_all(pni::core::type_id_t tid,void *ptr) const;
103 
104  //----------------------------------------------------------------
121  void _read_selection(pni::core::type_id_t tid, void *ptr) const;
122 
123  //-----------------------------------------------------------------
133 
134  //----------------------------------------------------------------
154  template<typename T>
155  void _read_selection_typed(pni::core::type_id_t tid,T *ptr) const
156  {
157  typedef pni::core::dynamic_array<T> array_type;
158 
159  //create buffer array and read data
160  auto a = array_type::create(_get_io_shape());
161  _read_all(tid,a.data());
162 
163  //apply selection and copy data to the output buffer
164  auto view = a(create_slice_vector(_selection));
165  std::copy(view.begin(),view.end(),ptr);
166  }
167 
168  //-----------------------------------------------------------------
179  void _to_disk(const h5datatype &memtype,const void *ptr) const;
180 
181  //----------------------------------------------------------------
191  void _write_all(pni::core::type_id_t tid,const void *ptr) const;
192 
193  //----------------------------------------------------------------
202  void _write_selection(const pni::core::type_id_t tid,
203  const void *ptr) const;
204 
205  //------------------------------------------------------------------
220  template<typename T>
221  void _write_selection_typed(pni::core::type_id_t tid,const T *ptr) const
222  {
223  typedef pni::core::dynamic_array<T> array_type;
224 
225  //create buffer array and read data
226  auto a = array_type::create(_get_io_shape());
227  _read_all(tid,a.data());
228 
229  //get view on the array and copy original data
230  auto view = a(create_slice_vector(_selection));
231  std::copy(ptr,ptr+view.size(),view.begin());
232 
233  //write data back
234  _write_all(tid,a.data());
235  }
236 
237 
238  public:
239  //==============-====constructors and destructors===================
243  explicit attribute_imp() noexcept;
244 
245  //-----------------------------------------------------------------
258  explicit attribute_imp(object_imp &&object);
259 
260  //===================reading and writting data=====================
275  void write(pni::core::type_id_t tid,const void *ptr) const;
276 
277  //----------------------------------------------------------------
293  void read(pni::core::type_id_t tid,void *ptr) const;
294 
295  //=================attribute inquery methods=======================
302  type_imp::index_vector_type shape() const;
303 
304  //-----------------------------------------------------------------
316  pni::core::type_id_t type_id() const;
317 
318  //-----------------------------------------------------------------
329  size_t size() const;
330 
331  //-----------------------------------------------------------------
342  size_t rank() const;
343 
344  //-----------------------------------------------------------------
355  bool is_valid() const;
356 
357  //-----------------------------------------------------------------
370  pni::core::string name() const;
371 
372  //----------------------------------------------------------------
385  pni::core::string filename() const;
386 
387  //-----------------------------------------------------------------
400  object_imp parent() const;
401 
402  //-----------------------------------------------------------------
409  void close();
410 
411  //=================================================================
412  // selection management
413  //=================================================================
421  void apply_selection(const type_imp::selection_vector_type &s);
422 
423  //----------------------------------------------------------------
429  void clear_selection();
430  };
431 
432 
433 //end of namespace
434 }
435 }
436 }
437 }
pni::core::string name() const
get name
Definition: attribute_imp.cpp:91
dataspace object
Definition: h5dataspace.hpp:68
void _write_selection(const pni::core::type_id_t tid, const void *ptr) const
write selection
Definition: attribute_imp.cpp:217
h5dataspace _dspace
handler to the dataspace object of the attribute
Definition: attribute_imp.hpp:51
void clear_selection()
remove selection
Definition: attribute_imp.cpp:370
selection _selection
selection instance
Definition: attribute_imp.hpp:56
void _read_all(pni::core::type_id_t tid, void *ptr) const
read the entire attribute
Definition: attribute_imp.cpp:277
h5datatype _dtype
handler to the datatype object of the attribute
Definition: attribute_imp.hpp:53
bool _apply_selection
flag determining whether or not the selection is set
Definition: attribute_imp.hpp:58
void _read_selection_typed(pni::core::type_id_t tid, T *ptr) const
read part of the attribute
Definition: attribute_imp.hpp:155
pni::core::string filename() const
get filename
Definition: attribute_imp.cpp:113
pni::core::type_id_t type_id() const
return type_id
Definition: attribute_imp.cpp:85
object_imp _object
handler to the undlying attribute object
Definition: attribute_imp.hpp:49
bool is_valid() const
check validity
Definition: attribute_imp.cpp:103
attribute implementation
Definition: attribute_imp.hpp:45
provide implementation specific types
Definition: type_imp.hpp:46
void close()
close object
Definition: attribute_imp.cpp:357
void _write_all(pni::core::type_id_t tid, const void *ptr) const
write all data
Definition: attribute_imp.cpp:175
type_imp::selection_vector_type create_slice_vector(const selection &s)
Definition: selection.cpp:201
object_imp parent() const
get parent
Definition: attribute_imp.cpp:97
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(pni::core::type_id_t tid, const void *ptr) const
write data from void
Definition: attribute_imp.cpp:202
attribute_imp() noexcept
default constructor
Definition: attribute_imp.cpp:58
size_t rank() const
get rank
Definition: attribute_imp.cpp:148
void _read_selection(pni::core::type_id_t tid, void *ptr) const
read part of the attribute
Definition: attribute_imp.cpp:311
type_imp::index_vector_type _get_io_shape() const
get shape for IO
Definition: attribute_imp.cpp:377
void _write_selection_typed(pni::core::type_id_t tid, const T *ptr) const
write data to selection
Definition: attribute_imp.hpp:221
std::vector< index_type > index_vector_type
container type for counters
Definition: type_imp.hpp:52
void _from_disk(const h5datatype &memtype, void *ptr) const
copy data from disk to memory
Definition: attribute_imp.cpp:193
void __update()
set dataspace and datatype
Definition: attribute_imp.cpp:40
size_t size() const
get size
Definition: attribute_imp.cpp:134
void read(pni::core::type_id_t tid, void *ptr) const
read data to void
Definition: attribute_imp.cpp:263
type_imp::index_vector_type shape() const
obtain attribute shape
Definition: attribute_imp.cpp:119
void apply_selection(const type_imp::selection_vector_type &s)
apply a selection to the attribute
Definition: attribute_imp.cpp:363
void _to_disk(const h5datatype &memtype, const void *ptr) const
write data from memory
Definition: attribute_imp.cpp:163