h5cpp 0.7
A modern C++ wrapper for the HDF5 C library
Loading...
Searching...
No Matches
dataset.hpp
Go to the documentation of this file.
1//
2// (c) Copyright 2017 DESY,ESS
3//
4// This file is part of h5cpp.
5//
6// This library is free software; you can redistribute it and/or modify it
7// under the terms of the GNU Lesser General Public License as published
8// by the Free Software Foundation; either version 2.1 of the License, or
9// (at your option) any later version.
10//
11// This library is distributed in the hope that it will be useful, but
12// WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY
13// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14// License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public License
17// along with this library; if not, write to the
18// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor
19// Boston, MA 02110-1301 USA
20// ===========================================================================
21//
22// Authors:
23// Eugen Wintersberger <eugen.wintersberger@desy.de>
24// Jan Kotanski <jan.kotanski@desy.de>
25//
26// Created on: Sep 7, 2017
27//
28#pragma once
29
30#include <h5cpp/node/node.hpp>
36#include <h5cpp/core/types.hpp>
45#include <h5cpp/error/error.hpp>
46#include <vector>
48
49namespace hdf5 {
50namespace node {
51
52class Selection;
53
54#ifdef __clang__
55#pragma clang diagnostic push
56#pragma clang diagnostic ignored "-Wpadded"
57#pragma clang diagnostic ignored "-Wweak-vtables"
58#endif
59class DLL_EXPORT Dataset : public Node
60{
61 public:
70 Dataset() = default;
71
81 Dataset(const Node &node);
82
95 Dataset(const Group &base,const Path &path,
96 const datatype::Datatype &type,
101
111
122
133
144
159 #ifdef __clang__
160 #pragma clang diagnostic push
161 #pragma clang diagnostic ignored "-Wdocumentation-deprecated-sync"
162 #endif
163 void extent(const Dimensions &dims) const;
164 #ifdef __clang__
165 #pragma clang diagnostic pop
166 #endif
167
168
169
170 void extent(size_t dim,ssize_t delta_elements) const;
171
172
186 void resize(const Dimensions &dims) const;
187
188
189
190#if (defined(_DOXYGEN_) || H5_VERSION_GE(1,10,0))
197 void refresh() const;
198#endif
199
200
218 template<typename T>
219 void write(const T &data,const datatype::Datatype &mem_type,
220 const dataspace::Dataspace &mem_space,
221 const dataspace::Dataspace &file_space,
223 property::DatasetTransferList::get()) const;
224
231 template<typename T>
232 void write(const T &data,const datatype::Datatype &mem_type,
233 const dataspace::Dataspace &mem_space,
235 property::DatasetTransferList::get()) const;
236
254 template<typename T>
255 void read(T &data,const datatype::Datatype &mem_type,
256 const dataspace::Dataspace &mem_space,
257 const dataspace::Dataspace &file_space,
259 property::DatasetTransferList::get()) const;
260
261 template<typename T>
262 void read(T &data,
263 const datatype::Datatype &mem_type,
264 const dataspace::Dataspace &mem_space,
266 property::DatasetTransferList::get()) const;
267
268 template<typename T>
269 void read_reshape(T &data,
270 const datatype::Datatype &mem_type,
271 const dataspace::Dataspace &mem_space,
273 property::DatasetTransferList::get()) const;
274
275
286 template<typename T>
287 void write(const T &data,const property::DatasetTransferList &dtpl =
288 property::DatasetTransferList::get());
289 template<typename T>
290 void write(const T &data,const property::DatasetTransferList &dtpl =
291 property::DatasetTransferList::get()) const;
292
306 template<typename T>
307 void write_reshape(const T &data,
308 const datatype::Datatype &mem_type,
309 const dataspace::Dataspace &mem_space,
311 property::DatasetTransferList::get()) const;
312
322 void write(const char *data,const property::DatasetTransferList &dtpl =
323 property::DatasetTransferList::get());
324 void write(const char *data,const property::DatasetTransferList &dtpl =
325 property::DatasetTransferList::get()) const;
326
339 template<typename T>
340 void write_chunk(const T &data,
341 std::vector<hsize_t> offset,
342 std::uint32_t filter_mask = 0,
344 property::DatasetTransferList::get());
345
346 template<typename T>
347 void write_chunk(const T &data,
348 std::vector<hsize_t> offset,
349 std::uint32_t filter_mask = 0,
351 property::DatasetTransferList::get()) const;
352
367 template<typename T>
368 void write_chunk(const T &data,
369 const datatype::Datatype &mem_type,
370 const dataspace::Dataspace &mem_space,
371 std::vector<hsize_t> & offset,
372 std::uint32_t filter_mask = 0,
374 property::DatasetTransferList::get()) const;
375
376#if (defined(_DOXYGEN_) || H5_VERSION_GE(1,10,2))
377
390 template<typename T>
391 std::uint32_t read_chunk(T &data,
392 std::vector<hsize_t> offset,
394 property::DatasetTransferList::get()) const;
395
396
410 template<typename T>
411 std::uint32_t read_chunk(T &data,
412 const datatype::Datatype &mem_type,
413 std::vector<hsize_t> & offset,
415 property::DatasetTransferList::get()) const;
416
417
427 hsize_t chunk_storage_size(std::vector<hsize_t> offset) const;
428
429#endif
430
441 template<typename T>
442 void read(T &data,const property::DatasetTransferList &dtpl =
443 property::DatasetTransferList::get());
444 template<typename T>
445 void read(T &data,const property::DatasetTransferList &dtpl =
446 property::DatasetTransferList::get()) const;
447
459 template<typename T>
460 void write(const T &data,const dataspace::Selection &selection,
462 property::DatasetTransferList::get());
463 template<typename T>
464 void write(const T &data,const dataspace::Selection &selection,
466 property::DatasetTransferList::get()) const;
467
482 template<typename T>
483 void write_reshape(const T &data,
484 const datatype::Datatype &mem_type,
485 const dataspace::Dataspace &mem_space,
486 const dataspace::Selection &selection,
488 property::DatasetTransferList::get()) const;
489
502 template<typename T>
503 void read(T &data,const dataspace::Selection &selection,
505 property::DatasetTransferList::get());
506 template<typename T>
507 void read(T &data,const dataspace::Selection &selection,
509 property::DatasetTransferList::get()) const;
510
527 template<typename T>
528 void read_reshape(T &data,
529 const datatype::Datatype &mem_type,
530 const dataspace::Dataspace &mem_space,
531 const dataspace::Selection &selection,
533 property::DatasetTransferList::get()) const;
534
545 template<typename T>
546 void read(T &data,
547 const datatype::Datatype &memory_type,
548 const dataspace::Dataspace &memory_space,
549 const dataspace::Selection &file_selection,
550 const property::DatasetTransferList &dtpl = property::DatasetTransferList::get()) const;
551
562
563 private:
564 datatype::Datatype file_type_;
565 datatype::Class file_type_class;
566 dataspace::DataspacePool space_pool;
573 static Node create_dataset(const Group &base,
574 const Path &path,
575 const datatype::Datatype &type,
576 const dataspace::Dataspace &space,
577 const property::LinkCreationList &lcpl,
579 const property::DatasetAccessList &dapl);
580
581 //
582 // writing template methods for various data configurations
583 //
584 template<typename T>
585 void write_variable_length_data(const T &data,
586 const datatype::Datatype &mem_type,
587 const dataspace::Dataspace &mem_space,
588 const datatype::Datatype &,
589 const dataspace::Dataspace &file_space,
590 const property::DatasetTransferList &dtpl) const
591 {
592 VarLengthDataBuffer buffer;
594 if(H5Dwrite(static_cast<hid_t>(*this),
595 static_cast<hid_t>(mem_type),
596 static_cast<hid_t>(mem_space),
597 static_cast<hid_t>(file_space),
598 static_cast<hid_t>(dtpl),
599 buffer.data())<0)
600 {
601 std::stringstream ss;
602 ss<<"Failure to write variable length data to dataset ["<<link().path()<<"]!";
603 error::Singleton::instance().throw_with_stack(ss.str());
604 }
605 }
606
607 template<typename T>
608 void write_contiguous_data(const T &data,
609 const datatype::Datatype &mem_type,
610 const dataspace::Dataspace &mem_space,
611 const datatype::Datatype &,
612 const dataspace::Dataspace &file_space,
613 const property::DatasetTransferList &dtpl) const
614 {
615 if(H5Dwrite(static_cast<hid_t>(*this),
616 static_cast<hid_t>(mem_type),
617 static_cast<hid_t>(mem_space),
618 static_cast<hid_t>(file_space),
619 static_cast<hid_t>(dtpl),
620 dataspace::cptr(data))<0)
621 {
622 std::stringstream ss;
623 ss<<"Failure to write contiguous data to dataset ["<<link().path()<<"]!";
624 error::Singleton::instance().throw_with_stack(ss.str());
625 }
626 }
627
628 template<typename T>
629 void write_variable_length_string_data(const T &data,
630 const datatype::Datatype &mem_type,
631 const dataspace::Dataspace &mem_space,
632 const datatype::Datatype &,
633 const dataspace::Dataspace &file_space,
634 const property::DatasetTransferList &dtpl) const
635 {
636 using Trait = VarLengthStringTrait<T>;
637 auto buffer = Trait::to_buffer(data);
638
639 if(H5Dwrite(static_cast<hid_t>(*this),
640 static_cast<hid_t>(mem_type),
641 static_cast<hid_t>(mem_space),
642 static_cast<hid_t>(file_space),
643 static_cast<hid_t>(dtpl),
644 reinterpret_cast<void*>(buffer.data()))<0)
645 {
646 std::stringstream ss;
647 ss<<"Failure to write variable length string data to dataset ["<<link().path()<<"]!";
648 error::Singleton::instance().throw_with_stack(ss.str());
649 }
650 }
651
652 template<typename T>
653 void write_fixed_length_string_data(const T &data,
654 const datatype::Datatype &mem_type,
655 const dataspace::Dataspace &mem_space,
656 const datatype::Datatype &,
657 const dataspace::Dataspace &file_space,
658 const property::DatasetTransferList &dtpl) const
659 {
660 using Trait = FixedLengthStringTrait<T>;
661 auto buffer = Trait::to_buffer(data,mem_type,mem_space);
662
663 if(H5Dwrite(static_cast<hid_t>(*this),
664 static_cast<hid_t>(mem_type),
665 static_cast<hid_t>(mem_space),
666 static_cast<hid_t>(file_space),
667 static_cast<hid_t>(dtpl),
668 reinterpret_cast<void*>(buffer.data()))<0)
669 {
670 std::stringstream ss;
671 ss<<"Failure to write fixed length string data to dataset ["<<link().path()<<"]!";
672 error::Singleton::instance().throw_with_stack(ss.str());
673 }
674
675
676 }
677
678 //
679 // reading template methods for various data configurations
680 //
681 template<typename T>
682 void read_variable_length_data(T &data,
683 const datatype::Datatype &mem_type,
684 const dataspace::Dataspace &mem_space,
685 const datatype::Datatype &file_type,
686 const dataspace::Dataspace &file_space,
687 const property::DatasetTransferList &dtpl) const
688 {
689 VarLengthDataBuffer buffer;
690 if(file_space.selection.type() != dataspace::SelectionType::All)
691 {
692 buffer.resize(file_space.selection.size());
693 }
694 else
695 {
696 buffer.resize(signed2unsigned<size_t>(file_space.size()));
697 }
698
699 if(H5Dread(static_cast<hid_t>(*this),
700 static_cast<hid_t>(mem_type),
701 static_cast<hid_t>(mem_space),
702 static_cast<hid_t>(file_space),
703 static_cast<hid_t>(dtpl),
704 buffer.data())<0)
705 {
706 std::stringstream ss;
707 ss<<"Failure to read variable length data from dataset ["<<link().path()<<"]!";
708 error::Singleton::instance().throw_with_stack(ss.str());
709 }
710
711 VarLengthBufferTrait<T>::from_buffer(buffer,data);
712
713 if(H5Dvlen_reclaim(static_cast<hid_t>(file_type),
714 static_cast<hid_t>(file_space),
715 static_cast<hid_t>(dtpl),
716 buffer.data())<0)
717 {
718 error::Singleton::instance().throw_with_stack("Error reclaiming variable length memory!");
719 }
720 }
721
722 template<typename T>
723 void read_contiguous_data(T &data,
724 const datatype::Datatype &mem_type,
725 const dataspace::Dataspace &mem_space,
726 const datatype::Datatype &,
727 const dataspace::Dataspace &file_space,
728 const property::DatasetTransferList &dtpl) const
729 {
730 if(H5Dread(static_cast<hid_t>(*this),
731 static_cast<hid_t>(mem_type),
732 static_cast<hid_t>(mem_space),
733 static_cast<hid_t>(file_space),
734 static_cast<hid_t>(dtpl),
735 dataspace::ptr(data))<0)
736 {
737 std::stringstream ss;
738 ss<<"Failure to read contiguous data from dataset ["<<link().path()<<"]!";
739 error::Singleton::instance().throw_with_stack(ss.str());
740 }
741 }
742
743 template<typename T>
744 void read_variable_length_string_data(T &data,
745 const datatype::Datatype &mem_type,
746 const dataspace::Dataspace &mem_space,
747 const datatype::Datatype &,
748 const dataspace::Dataspace &file_space,
749 const property::DatasetTransferList &dtpl) const
750 {
751 using Trait = VarLengthStringTrait<T>;
752 using size_type = typename std::vector<T>::size_type;
753
754 typename Trait::BufferType buffer(static_cast<size_type>(mem_space.size()));
755
756
757 if(H5Dread(static_cast<hid_t>(*this),
758 static_cast<hid_t>(mem_type),
759 static_cast<hid_t>(mem_space),
760 static_cast<hid_t>(file_space),
761 static_cast<hid_t>(dtpl),
762 buffer.data())<0)
763 {
764 std::stringstream ss;
765 ss<<"Failure to read variable length string data from dataset ["
766 <<link().path()<<"]!";
767 error::Singleton::instance().throw_with_stack(ss.str());
768 }
769
770 Trait::from_buffer(buffer,data);
771
772 if(buffer.size() > 0)
773 {
774 if(H5Dvlen_reclaim(static_cast<hid_t>(mem_type),
775 static_cast<hid_t>(mem_space),
776 static_cast<hid_t>(dtpl),
777 buffer.data())<0)
778 {
779 std::stringstream ss;
780 ss<<"Error reclaiming memory from variable length string data in "
781 <<"dataset ["<<link().path()<<"]!";
782 error::Singleton::instance().throw_with_stack(ss.str());
783 }
784 }
785 }
786
787 template<typename T>
788 void read_fixed_length_string_data(T &data,
789 const datatype::Datatype &mem_type,
790 const dataspace::Dataspace &mem_space,
791 const datatype::Datatype &,
792 const dataspace::Dataspace &file_space,
793 const property::DatasetTransferList &dtpl) const
794 {
795 using Trait = FixedLengthStringTrait<T>;
796
797 auto buffer = Trait::BufferType::create(mem_type,mem_space);
798
799 if(file_space.size() > 0)
800 {
801 if(H5Dread(static_cast<hid_t>(*this),
802 static_cast<hid_t>(mem_type),
803 static_cast<hid_t>(mem_space),
804 static_cast<hid_t>(file_space),
805 static_cast<hid_t>(dtpl),
806 buffer.data())<0)
807 {
808 std::stringstream ss;
809 ss<<"Failure to read fixed length string data to dataset ["<<link().path()<<"]!";
810 error::Singleton::instance().throw_with_stack(ss.str());
811 }
812
813 //get data out of the buffer
814 data = Trait::from_buffer(buffer,mem_type,mem_space);
815 }
816 }
817};
818#ifdef __clang__
819#pragma clang diagnostic pop
820#endif
821
822template<typename T>
823void Dataset::write(const T &data,const datatype::Datatype &mem_type,
824 const dataspace::Dataspace &mem_space,
825 const dataspace::Dataspace &file_space,
826 const property::DatasetTransferList &dtpl) const
827{
828 if(file_type_class == datatype::Class::VarLength)
829 {
830 write_variable_length_data(data,mem_type,mem_space,file_type_,file_space,dtpl);
831 }
832 else if(file_type_class == datatype::Class::String)
833 {
834 datatype::String string_type(file_type_);
835 if(string_type.is_variable_length())
836 {
837 write_variable_length_string_data(data,mem_type,mem_space,file_type_,file_space,dtpl);
838 }
839 else
840 {
841 write_fixed_length_string_data(data,mem_type,mem_space,file_type_,file_space,dtpl);
842 }
843 }
844 else
845 {
846 write_contiguous_data(data,mem_type,mem_space,file_type_,file_space,dtpl);
847 }
848
849}
850
851template<typename T>
852void Dataset::write(const T &data,
853 const datatype::Datatype &mem_type,
854 const dataspace::Dataspace &mem_space,
855 const property::DatasetTransferList &dtpl) const
856{
857 auto file_space = dataspace();
858 file_space.selection.all();
859
860 write(data,mem_type,mem_space,file_space,dtpl);
861
862}
863
864template<typename T>
865void Dataset::write_chunk(const T &data,
866 std::vector<hsize_t> offset,
867 std::uint32_t filter_mask,
869{
870 hdf5::datatype::DatatypeHolder mem_type_holder;
871 hdf5::dataspace::DataspaceHolder mem_space_holder(space_pool);
872 write_chunk(data, mem_type_holder.get(data), mem_space_holder.get(data), offset, filter_mask, dtpl);
873}
874
875template<typename T>
876void Dataset::write_chunk(const T &data,
877 std::vector<hsize_t> offset,
878 std::uint32_t filter_mask,
879 const property::DatasetTransferList &dtpl) const
880{
881 hdf5::datatype::DatatypeHolder mem_type_holder;
882 hdf5::dataspace::DataspaceHolder mem_space_holder;
883 write_chunk(data, mem_type_holder.get(data), mem_space_holder.get(data), offset, filter_mask, dtpl);
884}
885
886template<typename T>
887void Dataset::write_chunk(const T &data,
888 const datatype::Datatype &mem_type,
889 const dataspace::Dataspace &mem_space,
890 std::vector<hsize_t> & offset,
891 std::uint32_t filter_mask,
892 const property::DatasetTransferList &dtpl) const
893{
894 size_t databytesize = signed2unsigned<hsize_t>(mem_space.size()) * mem_type.size();
895
896 if(mem_type.get_class() == datatype::Class::Integer)
897 {
898#if H5_VERSION_GE(1,10,3)
899 if(H5Dwrite_chunk(static_cast<hid_t>(*this),
900 static_cast<hid_t>(dtpl),
901 filter_mask,
902 offset.data(),
903 databytesize,
904 dataspace::cptr(data))<0)
905 {
906 std::stringstream ss;
907 ss<<"Failure to write chunk data to dataset ["<<link().path()<<"]!";
909 }
910#else
911 if(H5DOwrite_chunk(static_cast<hid_t>(*this),
912 static_cast<hid_t>(dtpl),
913 filter_mask,
914 offset.data(),
915 databytesize,
916 dataspace::cptr(data))<0)
917 {
918 std::stringstream ss;
919 ss<<"Failure to write chunk data to dataset ["<<link().path()<<"]!";
921 }
922#endif
923 }
924 else
925 {
926 std::stringstream ss;
927 ss<<"Failure to write non-integer chunk data to dataset ["<<link().path()<<"]!";
929 }
930}
931
932#if H5_VERSION_GE(1,10,2)
933
934template<typename T>
935std::uint32_t Dataset::read_chunk(T &data,
936 std::vector<hsize_t> offset,
937 const property::DatasetTransferList &dtpl) const
938{
939 hdf5::datatype::DatatypeHolder mem_type_holder;
940 return read_chunk(data, mem_type_holder.get(data), offset, dtpl);
941}
942
943template<typename T>
944std::uint32_t Dataset::read_chunk(T &data,
945 const datatype::Datatype &mem_type,
946 std::vector<hsize_t> & offset,
947 const property::DatasetTransferList &dtpl) const
948{
949 std::uint32_t filter_mask;
950 if(mem_type.get_class() == datatype::Class::Integer)
951 {
952#if H5_VERSION_GE(1,10,3)
953 if(H5Dread_chunk(static_cast<hid_t>(*this),
954 static_cast<hid_t>(dtpl),
955 offset.data(),
956 &filter_mask,
957 dataspace::ptr(data))<0)
958 {
959 std::stringstream ss;
960 ss<<"Failure to read chunk data from dataset ["<<link().path()<<"]!";
962 }
963#else
964 if(H5DOread_chunk(static_cast<hid_t>(*this),
965 static_cast<hid_t>(dtpl),
966 offset.data(),
967 &filter_mask,
968 dataspace::ptr(data))<0)
969 {
970 std::stringstream ss;
971 ss<<"Failure to read chunk data from dataset ["<<link().path()<<"]!";
973 }
974#endif
975 }
976 else
977 {
978 std::stringstream ss;
979 ss<<"Failure to read non-integer chunk data from dataset ["<<link().path()<<"]!";
981 }
982 return filter_mask;
983}
984
985#endif
986
987template<typename T>
988void Dataset::write(const T &data,const property::DatasetTransferList &dtpl)
989{
990 hdf5::dataspace::DataspaceHolder mem_space_holder(space_pool);
991 if(file_type_.get_class() == datatype::Class::String)
992 {
993 write_reshape(data, file_type_, mem_space_holder.get(data), dtpl);
994 }
995 else
996 {
997 hdf5::datatype::DatatypeHolder mem_type_holder;
998 write_reshape(data, mem_type_holder.get(data), mem_space_holder.get(data), dtpl);
999 }
1000}
1001
1002template<typename T>
1003void Dataset::write(const T &data,const property::DatasetTransferList &dtpl) const
1004{
1005 hdf5::dataspace::DataspaceHolder mem_space_holder;
1006 if(file_type_.get_class() == datatype::Class::String)
1007 {
1008 write_reshape(data, file_type_, mem_space_holder.get(data), dtpl);
1009 }
1010 else
1011 {
1012 hdf5::datatype::DatatypeHolder mem_type_holder;
1013 write_reshape(data, mem_type_holder.get(data), mem_space_holder.get(data), dtpl);
1014 }
1015}
1016
1017template<typename T>
1018void Dataset::write_reshape(const T &data,
1019 const datatype::Datatype &mem_type,
1020 const dataspace::Dataspace &mem_space,
1021 const property::DatasetTransferList &dtpl) const
1022{
1023 auto file_space = dataspace();
1024 file_space.selection.all();
1025
1026 if (file_space.size() == mem_space.size() &&
1027 mem_space.type() == dataspace::Type::Simple &&
1028 file_space.type() == dataspace::Type::Simple){
1029 const dataspace::Simple & mem_simple_space = dataspace::Simple(mem_space);
1030 const dataspace::Simple & file_simple_space = dataspace::Simple(file_space);
1031 if(file_simple_space.rank() > 1 && mem_simple_space.rank() == 1){
1032 return write(data,mem_type,file_space,file_space,dtpl);
1033 }
1034 }
1035 write(data,mem_type,mem_space,file_space,dtpl);
1036}
1037
1038
1039template<typename T>
1040void Dataset::read(T &data,const datatype::Datatype &mem_type,
1041 const dataspace::Dataspace &mem_space,
1042 const dataspace::Dataspace &file_space,
1043 const property::DatasetTransferList &dtpl) const
1044{
1045 if(file_type_class == datatype::Class::VarLength)
1046 {
1047 read_variable_length_data(data,mem_type,mem_space,file_type_,file_space,dtpl);
1048 }
1049 else if(file_type_class == datatype::Class::String)
1050 {
1051 datatype::String string_type(file_type_);
1052 if(string_type.is_variable_length())
1053 {
1054 read_variable_length_string_data(data,mem_type,mem_space,file_type_,file_space,dtpl);
1055 }
1056 else
1057 {
1058 read_fixed_length_string_data(data,mem_type,mem_space,file_type_,file_space,dtpl);
1059 }
1060 }
1061 else
1062 {
1063 read_contiguous_data(data,mem_type,mem_space,file_type_,file_space,dtpl);
1064 }
1065
1066}
1067
1068template<typename T>
1069void Dataset::read(T &data,const dataspace::Selection &selection,
1071{
1072 hdf5::datatype::DatatypeHolder mem_type_holder;
1073 hdf5::dataspace::DataspaceHolder mem_space_holder(space_pool);
1074 read_reshape(data, mem_type_holder.get(data), mem_space_holder.get(data), selection, dtpl);
1075}
1076
1077template<typename T>
1078void Dataset::read(T &data,const dataspace::Selection &selection,
1079 const property::DatasetTransferList &dtpl) const
1080{
1081 hdf5::datatype::DatatypeHolder mem_type_holder;
1082 hdf5::dataspace::DataspaceHolder mem_space_holder;
1083 read_reshape(data, mem_type_holder.get(data), mem_space_holder.get(data), selection, dtpl);
1084}
1085
1086template<typename T>
1088 const datatype::Datatype &mem_type,
1089 const dataspace::Dataspace &mem_space,
1090 const dataspace::Selection &selection,
1091 const property::DatasetTransferList &dtpl) const
1092{
1093 dataspace::Dataspace file_space = dataspace();
1094 file_space.selection(dataspace::SelectionOperation::Set,selection);
1095 if (selection.type() != dataspace::SelectionType::Hyperslab)
1096 return read(data,mem_type,mem_space,file_space,dtpl);
1097 try{
1098 const dataspace::Hyperslab & hyper = dynamic_cast<const dataspace::Hyperslab &>(selection);
1099 if(hyper.rank() > 1) {
1100 dataspace::Simple selected_space(hyper.dimensions());
1101 if (selected_space.size() == mem_space.size()) {
1102 // reads to the reshaped memory data buffer
1103 return read(data,mem_type,selected_space,file_space,dtpl);
1104 }
1105 }
1106 }
1107 catch(const std::bad_cast&) { }
1108 read(data,mem_type,mem_space,file_space,dtpl);
1109}
1110
1111template<typename T>
1112void Dataset::read(T &data,
1113 const datatype::Datatype &memory_type,
1114 const dataspace::Dataspace &memory_space,
1115 const dataspace::Selection &file_selection,
1116 const property::DatasetTransferList &dtpl) const
1117{
1118 dataspace::Dataspace file_space = dataspace();
1119 file_space.selection(dataspace::SelectionOperation::Set,file_selection);
1120 read(data,memory_type,memory_space,file_space,dtpl);
1121}
1122
1123template<typename T>
1124void Dataset::read(T &data,
1125 const datatype::Datatype &memory_type,
1126 const dataspace::Dataspace &memory_space,
1127 const property::DatasetTransferList &dtpl) const
1128{
1129 dataspace::Dataspace file_space = dataspace();
1130 file_space.selection.all();
1131 read(data,memory_type,memory_space,file_space,dtpl);
1132}
1133
1134template<typename T>
1135void Dataset::write(const T &data,const dataspace::Selection &selection,
1137{
1138 hdf5::datatype::DatatypeHolder mem_type_holder;
1139 hdf5::dataspace::DataspaceHolder mem_space_holder(space_pool);
1140 write_reshape(data, mem_type_holder.get(data), mem_space_holder.get(data), selection, dtpl);
1141}
1142
1143template<typename T>
1144void Dataset::write(const T &data,const dataspace::Selection &selection,
1145 const property::DatasetTransferList &dtpl) const
1146{
1147 hdf5::datatype::DatatypeHolder mem_type_holder;
1148 hdf5::dataspace::DataspaceHolder mem_space_holder;
1149 write_reshape(data, mem_type_holder.get(data), mem_space_holder.get(data), selection, dtpl);
1150}
1151
1152template<typename T>
1153void Dataset::write_reshape(const T &data,
1154 const datatype::Datatype &mem_type,
1155 const dataspace::Dataspace &mem_space,
1156 const dataspace::Selection &selection,
1157 const property::DatasetTransferList &dtpl) const
1158{
1159 dataspace::Dataspace file_space = dataspace();
1160 file_space.selection(dataspace::SelectionOperation::Set,selection);
1161 if (mem_space.type() != dataspace::Type::Simple
1162 || selection.type() != dataspace::SelectionType::Hyperslab)
1163 return write(data,mem_type,mem_space,file_space,dtpl);
1164 try{
1165 const dataspace::Hyperslab & hyper = dynamic_cast<const dataspace::Hyperslab &>(selection);
1166 if(hyper.rank() > 1) {
1167 const dataspace::Simple & mem_simple_space = dataspace::Simple(mem_space);
1168 dataspace::Simple selected_space(hyper.dimensions());
1169 if(selected_space.rank() > 1 &&
1170 mem_simple_space.rank() == 1 &&
1171 selected_space.size() == mem_space.size()) {
1172 // writes from the reshaped memory data buffer
1173 return write(data,mem_type,selected_space,file_space,dtpl);
1174 }
1175 }
1176 }
1177 catch(const std::bad_cast&) { }
1178 write(data,mem_type,mem_space,file_space,dtpl);
1179}
1180
1181
1182template<typename T>
1184{
1185 hdf5::dataspace::DataspaceHolder mem_space_holder(space_pool);
1186 if(file_type_class == datatype::Class::String){
1187 // in hdf5 1.12.1 UFT8 data cannot be read to an ASCII buffer
1188 read_reshape(data, file_type_, mem_space_holder.get(data), dtpl);
1189 }
1190 else {
1191 hdf5::datatype::DatatypeHolder mem_type_holder;
1192 read_reshape(data, mem_type_holder.get(data), mem_space_holder.get(data), dtpl);
1193 }
1194}
1195
1196template<typename T>
1197void Dataset::read(T &data,const property::DatasetTransferList &dtpl) const
1198{
1199 hdf5::datatype::DatatypeHolder mem_type_holder;
1200 hdf5::dataspace::DataspaceHolder mem_space_holder;
1201 read_reshape(data, mem_type_holder.get(data), mem_space_holder.get(data), dtpl);
1202}
1203
1204
1205template<typename T>
1207 const datatype::Datatype &mem_type,
1208 const dataspace::Dataspace &mem_space,
1209 const property::DatasetTransferList &dtpl) const
1210{
1211 auto file_space = dataspace();
1212 file_space.selection.all();
1213
1214 if (file_space.size() == mem_space.size()){
1215 read(data,mem_type,file_space,file_space,dtpl);
1216 }
1217 else{
1218 read(data,mem_type,mem_space,file_space,dtpl);
1219 }
1220
1221}
1222
1223
1236DLL_EXPORT void resize_by(const Dataset &dataset,size_t dimension_index,ssize_t delta);
1237
1238
1239
1240} // namespace node
1241} // namespace hdf5
path to a node object
Definition path.hpp:54
data space object holder
Definition type_trait.hpp:124
const Dataspace & get(const T &v)
factory holder method for getting reference of data spaces
Definition type_trait.hpp:158
data space object pool
Definition pool.hpp:42
dataspace base class
Definition dataspace.hpp:41
SelectionManager selection
access to selection manager
Definition dataspace.hpp:144
Type type() const
get the type of the dataspace
virtual hssize_t size() const
number of elements in the dataspace
hyperslab selection class
Definition hyperslab.hpp:52
size_t rank() const noexcept
get rank
virtual Dimensions dimensions() const override
get current dimensions
scalar dataspace
Definition scalar.hpp:44
void all() const
select everything
selection base class
Definition selection.hpp:42
virtual SelectionType type() const =0
get the selection type
simple multidimensional dataspace
Definition simple.hpp:43
size_t rank() const
get number of dimensions
data type object holder
Definition factory.hpp:54
const Datatype & get(const T &v=T{})
factory holder method for getting reference of data types
Definition factory.hpp:74
base class for all data types
Definition datatype.hpp:42
Class get_class() const
returns the datatypes class
virtual size_t size() const
get size of type in bytes
string datatype
Definition string.hpp:40
bool is_variable_length() const
return true if type is a variable length string
static Singleton & instance()
reference to singleton
Definition error.hpp:59
void throw_with_stack(const std::string &message)
throws an exception, potentially nested with error stack
utility container for external filters
Definition external_filter.hpp:123
Definition dataset.hpp:60
hsize_t chunk_storage_size(std::vector< hsize_t > offset) const
read dataset chunk
void write(const T &data, const datatype::Datatype &mem_type, const dataspace::Dataspace &mem_space, const dataspace::Dataspace &file_space, const property::DatasetTransferList &dtpl=property::DatasetTransferList::get()) const
write data to the dataset
Definition dataset.hpp:823
void read_reshape(T &data, const datatype::Datatype &mem_type, const dataspace::Dataspace &mem_space, const property::DatasetTransferList &dtpl=property::DatasetTransferList::get()) const
Definition dataset.hpp:1206
void write(const char *data, const property::DatasetTransferList &dtpl=property::DatasetTransferList::get()) const
dataspace::Dataspace dataspace() const
get dataspace of dataset
void extent(const Dimensions &dims) const
set extent of the dataset
void refresh() const
refresh the dataset (since hdf5 1.10.0)
property::DatasetAccessList access_list() const
get the dataset access property list for the instance
void write_chunk(const T &data, std::vector< hsize_t > offset, std::uint32_t filter_mask=0, const property::DatasetTransferList &dtpl=property::DatasetTransferList::get())
write dataset chunk
Definition dataset.hpp:865
Dataset()=default
default constructor
void resize(const Dimensions &dims) const
resize the dataset
std::uint32_t read_chunk(T &data, const datatype::Datatype &mem_type, std::vector< hsize_t > &offset, const property::DatasetTransferList &dtpl=property::DatasetTransferList::get()) const
read dataset chunk
datatype::Datatype datatype() const
get datatype of dataset
Dataset(const Node &node)
construct
void extent(size_t dim, ssize_t delta_elements) const
void write(const char *data, const property::DatasetTransferList &dtpl=property::DatasetTransferList::get())
write entire dataset
Dataset(const Group &base, const Path &path, const datatype::Datatype &type, const dataspace::Dataspace &space=dataspace::Scalar(), const property::LinkCreationList &lcpl=property::LinkCreationList(), const property::DatasetCreationList &dcpl=property::DatasetCreationList(), const property::DatasetAccessList &dapl=property::DatasetAccessList())
constructor
property::DatasetCreationList creation_list() const
get the dataset creation property list used for creation
std::uint32_t read_chunk(T &data, std::vector< hsize_t > offset, const property::DatasetTransferList &dtpl=property::DatasetTransferList::get()) const
read dataset chunk (since hdf5 1.10.2)
void read(T &data, const datatype::Datatype &mem_type, const dataspace::Dataspace &mem_space, const dataspace::Dataspace &file_space, const property::DatasetTransferList &dtpl=property::DatasetTransferList::get()) const
read data from the dataset
Definition dataset.hpp:1040
filter::ExternalFilters filters() const
get the dataset external filters for the instance
void write_reshape(const T &data, const datatype::Datatype &mem_type, const dataspace::Dataspace &mem_space, const property::DatasetTransferList &dtpl=property::DatasetTransferList::get()) const
write entire dataset
Definition dataset.hpp:1018
Definition group.hpp:51
Definition node.hpp:40
const Link & link() const
return link to object
dataset access property list
Definition dataset_access.hpp:76
dataset creation property list
Definition dataset_creation.hpp:111
class for a dataset transfer property list
Definition dataset_transfer.hpp:57
Definition link_creation.hpp:35
void * ptr(T &value)
Definition type_trait.hpp:111
const void * cptr(const T &value)
Definition type_trait.hpp:116
Class
Definition types.hpp:53
@ String
indicates a string type
@ VarLength
indicates a variable length type
@ Integer
indicates an integer type
void resize_by(const Dataset &dataset, size_t dimension_index, ssize_t delta)
resize a dataset by a particular offset
void link(const Node &target, const Group &link_base, const Path &link_path, const property::LinkCreationList &lcpl=property::LinkCreationList(), const property::LinkAccessList &lapl=property::LinkAccessList())
Create a soft or external link.
top-level namespace of the entire library
Definition attribute.hpp:45
std::vector< hsize_t > Dimensions
Definition types.hpp:32
std::vector< hvl_t > VarLengthDataBuffer
Definition types.hpp:34
variable length buffer trait
Definition types.hpp:44
#define DLL_EXPORT
Definition windows.hpp:29