Data Access Library (DAL)
|
00001 /* Copyright 2011-2012 ASTRON, Netherlands Institute for Radio Astronomy 00002 * This file is part of the Data Access Library (DAL). 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 3 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 #ifndef DAL_DATASET_H 00018 #define DAL_DATASET_H 00019 00020 #include <cstddef> 00021 #include <cstdlib> 00022 #include <cstring> 00023 #include <sys/types.h> 00024 #include <sys/stat.h> 00025 #include <unistd.h> 00026 #include <fcntl.h> 00027 #ifdef __APPLE__ 00028 #include <machine/endian.h> 00029 #else 00030 #include <endian.h> 00031 #endif 00032 #if BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN 00033 #error Byte order is neither big endian nor little endian: not supported 00034 #endif 00035 00036 #include <string> 00037 #include <vector> 00038 #include <hdf5.h> 00039 #include "types/h5typemap.h" 00040 #include "exceptions/exceptions.h" 00041 #include "Group.h" 00042 00043 namespace dal { 00044 00092 template<typename T> class Dataset: public Group { 00093 public: 00094 enum Endianness { NATIVE = 0, LITTLE, BIG }; 00095 00096 Dataset( Group &parent, const std::string &name ): Group(parent, name) {} 00097 00101 virtual ~Dataset() {} 00102 00122 Dataset<T>& create( const std::vector<ssize_t> &dims, const std::vector<ssize_t> &maxdims = std::vector<ssize_t>(0), 00123 const std::string &filename = "", enum Endianness endianness = NATIVE ); 00124 00128 Dataset<T>& create1D( ssize_t len, ssize_t maxlen, const std::string &filename = "", 00129 enum Endianness endianness = NATIVE ); 00130 00134 size_t ndims(); 00135 00139 std::vector<ssize_t> dims(); 00140 00144 ssize_t dims1D(); 00145 00150 std::vector<ssize_t> maxdims(); 00151 00156 ssize_t maxdims1D(); 00157 00165 void resize( const std::vector<ssize_t> &newdims ); 00166 00170 void resize1D( ssize_t newlen ); 00171 00175 std::vector<std::string> externalFiles(); 00176 00184 void getMatrix( const std::vector<size_t> &pos, T *buffer, const std::vector<size_t> &size ); 00185 00192 void setMatrix( const std::vector<size_t> &pos, const T *buffer, const std::vector<size_t> &size ); 00193 00209 void get1D( size_t pos, T *outbuffer, size_t len, unsigned dimIndex = 0 ); 00210 00226 void set1D( size_t pos, const T *inbuffer, size_t len, unsigned dimIndex = 0 ); 00227 00244 void get2D( const std::vector<size_t> &pos, T *outbuffer2, size_t dim1, size_t dim2, unsigned dim1index = 0, unsigned dim2index = 1 ); 00245 00261 void set2D( const std::vector<size_t> &pos, const T *inbuffer2, size_t dim1, size_t dim2, unsigned dim1index = 0, unsigned dim2index = 1 ); 00262 00281 void get3D( const std::vector<size_t> &pos, T *outbuffer3, size_t dim1, size_t dim2, size_t dim3, unsigned dim1index = 0, unsigned dim2index = 1, unsigned dim3index = 2 ); 00282 00300 void set3D( const std::vector<size_t> &pos, const T *inbuffer3, size_t dim1, size_t dim2, size_t dim3, unsigned dim1index = 0, unsigned dim2index = 1, unsigned dim3index = 2 ); 00301 00308 T getScalar( const std::vector<size_t> &pos ); 00309 00313 T getScalar1D( size_t pos ); 00314 00321 void setScalar( const std::vector<size_t> &pos, const T &value ); 00322 00326 void setScalar1D( size_t pos, T value ); 00327 00328 protected: 00333 bool bigEndian( enum Endianness endianness ) const; 00334 00336 void matrixIO( const std::vector<size_t> &pos, T *buffer, const std::vector<size_t> &size, const std::vector<size_t> &strides, bool read ); 00337 00338 00344 virtual Dataset<T>& create() { 00345 throw HDF5Exception("create() without parameters not supported on a dataset " + _name); 00346 } 00347 00348 private: 00349 virtual void open( hid_t parent, const std::string &name ); 00350 }; 00351 00352 } 00353 00354 #include "Dataset.tcc" 00355 00356 #endif 00357