OpendTect  6.6
hdf5access.h
Go to the documentation of this file.
1 #pragma once
2 /*+
3 ________________________________________________________________________
4 
5  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
6  Author: Bert
7  Date: Feb 2018
8 ________________________________________________________________________
9 
10 -*/
11 
12 #include "generalmod.h"
13 #include "arrayndinfo.h"
14 #include "factory.h"
15 
16 namespace H5 { class DataSet; class Group; class H5File; class H5Object; }
17 
18 #define mDefHDF5FileExt "h5"
19 
20 
21 namespace HDF5
22 {
23 
24 class Reader;
25 class Writer;
26 
28 
29 
30 /*\brief Key to groups and data sets in HDF5 files.
31 
32  The group name and dataset key correspond to one dataset. Some attributes
33  are valid for an entire group, then leave the dataset name empty.
34  Leave the group name empty (null) for a top level DataSet
35 
36  One can set edition and chunk sizes properties, which will be
37  used when creating the dataset and writing to it.
38 
39  */
40 
42 {
43 public:
44  DataSetKey(const char* grpnm=nullptr,
45  const char* dsnm=nullptr);
47 
48  inline const char* groupName() const { return grpnm_; }
49  inline DataSetKey& setGroupName( const char* nm )
50  { grpnm_.set( nm ); return *this; }
51  bool hasGroup(const char* nm) const;
52 
53  inline const char* dataSetName() const { return dsnm_; }
54  inline DataSetKey& setDataSetName( const char* nm )
55  { dsnm_.set( nm ); return *this; }
56  inline bool dataSetEmpty() const { return dsnm_.isEmpty(); }
57  inline bool hasDataSet( const char* nm ) const
58  { return dsnm_ == nm; }
59 
60  bool isEditable() const;
61  void setEditable(bool yn);
62 
64 
65  static DataSetKey groupKey(const DataSetKey& parentgrp,
66  const char* subgrpnm);
67  static DataSetKey groupKey(const char* parentfulldsnm,const char* grpnm);
68 
69  void setChunkSize(int idim,int sz);
70  void setChunkSize(const int* szs,int nrdims=1,
71  int from=0);
72  //<! Pass nullptr to disable
73  void setMaximumSize(int idim,int maxsz=256);
77  int chunkSz(int idim) const;
78  int maxDimSz(int idim) const;
79 
80 protected:
81 
84 
85 };
86 
87 
88 /*\brief simple specification of the 'hyperslab' concept in HDF5.
89 
90  Basically, we offer a range + step in all dimensions, which seems enough for
91  almost all normal work.
92 
93  */
94 
96 {
97 public:
98 
100 
101  ArrayNDInfo::idx_type start_=0, step_=1, count_=-1;
102  bool operator==( const SlabDimSpec& oth ) const
103  { return start_==oth.start_ && step_==oth.step_
104  && count_==oth.count_; }
105 
106 };
107 
109 {
110 public:
111 
113 
114  SlabSpec() {}
115  SlabSpec( nr_dims_type nrdims ) { setNrDims( nrdims ); }
116 
117  void setNrDims( nr_dims_type nrdims )
118  {
119  for ( int idim=nrdims; idim<size(); idim++ )
120  removeSingle( size()-1 );
121  for ( int idim=size(); idim<nrdims; idim++ )
122  *this += SlabDimSpec();
123  }
124 };
125 
126 
127 /*\brief baseclass for reader and writer of HDF5 files.
128 
129  HDF5 can be seen as a (simple) database in a file. As usual with this sort of
130  general-purpose utilities, the data model is bloated by many options that are
131  only interesting for some. As usual, we take our pick of the core stuff:
132 
133  * The database is essentially a tree of nodes that are called 'Group'.
134  You can see this structure as a file system and it does use names like in a
135  UNIX file system. The root group '/' is always there, and it is the 'H5File'
136  itself. Thus, the Group is a 'directory'. Actually, it maps to a class
137  called H5::CommonFG, the base class for H5::H5File and H5::Group.
138 
139  * Where 'Group' is like a directory, the files are 'DataSet' objects. Every
140  'DataSet' can be seen as an N-dimensional array of data. The dimensionalities
141  are covered by the 'DataSpace' object, which maps to our ArrayNDInfo.
142  Actually, as you will most likely get/put ArrayND data there, you can
143  see a DataSet as an ArrayND with accompanying properties.
144 
145  * Each DataSet can have properties attached, like 'file header values'.
146  These are key-value pairs. The value can be anything - but our interface
147  will only read and write strings. This maps the set of properties to one
148  IOPar.
149 
150  Notes:
151  * HDF5 'stores' can refer to more than 1 file. We do not use or support this
152  facilty.
153  * If you read HDF5 files not produced by us, there may be 'advanced' stuff
154  in there that we don't handle. The strategy is to do as if they do not
155  exist, and handle everything gracefully.
156  * The HDF5 data type system is richer than ours. We'll try to map to the
157  'nearest'.
158  * HDF5 and this interface are *not* MT-safe. Build your own locking.
159 
160  */
161 
162 
165 public:
167 
168  virtual ~Access();
169 
170  uiRetVal open(const char*);
171  virtual const char* fileName() const = 0;
172  virtual bool isReader() const = 0;
173 
174  virtual DataSetKey scope() const = 0;
175  virtual od_int64 curGroupID() const = 0;
176 
177  bool isOpen() const { return file_; }
178  H5::H5File* getHDF5File() { return file_; }
179  bool hasGroup(const char* grpnm) const;
180  bool hasDataSet(const DataSetKey&) const;
181 
184  static uiString sHDF5NotAvailable(const char* fnm);
185  static uiString sNotHDF5File(const char*);
190  static const char* sFileExtension() { return mDefHDF5FileExt; }
191 
192  static bool isEnabled(const char* fortype=0);
193  static bool isEnvBlocked(const char* fortype=0);
194  static bool isHDF5File(const char*);
195  static const char* sSettingsEnabKey() { return "dTect.Use HDF5"; }
196 
197 protected:
198 
200 
201  H5::H5File* file_;
202  bool myfile_;
203 
204  virtual void closeFile() = 0;
205  virtual void openFile(const char*,uiRetVal&,bool ed) = 0;
206 
207  virtual H5::H5Object* setScope(const DataSetKey*) = 0;
208  virtual H5::H5Object* getScope(const DataSetKey*) const = 0;
209  virtual H5::Group* setGrpScope(const DataSetKey*) = 0;
210  virtual H5::Group* getGrpScope(const DataSetKey*) const = 0;
211  virtual H5::DataSet* setDSScope(const DataSetKey&) = 0;
212  virtual H5::DataSet* getDSScope(const DataSetKey&) const = 0;
214 
215  static uiString sHDF5Err(const uiString&);
217 
218  static const char* sOpenFileFirst();
219  static const char* sNeedScope();
220  static const char* sNoDataPassed();
221 
222  friend class AccessImpl;
223 
224 };
225 
226 
228 {
229 public:
230 
231  virtual ~AccessProvider() {}
232 
234 
235  virtual Reader* getReader() const = 0;
236  virtual Writer* getWriter() const = 0;
237 
238  static Reader* mkReader(int n=-1);
239  static Writer* mkWriter(int n=-1);
240 
241 protected:
242 
243  static AccessProvider* mkProv(int);
244 
245 };
246 
247 inline Reader* mkReader() { return AccessProvider::mkReader(); }
248 inline Writer* mkWriter() { return AccessProvider::mkWriter(); }
249 inline const char* sFileExtension() { return Access::sFileExtension(); }
250 
251 inline bool isAvailable()
252 { return !AccessProvider::factory().isEmpty(); }
253 inline bool isEnabled( const char* typ=0 )
254 { return Access::isEnabled(typ); }
255 inline bool isEnvBlocked( const char* typ=0 )
256 { return Access::isEnvBlocked(typ);}
257 inline bool isHDF5File( const char* fnm )
258 { return Access::isHDF5File(fnm); }
259 
260 inline const char* sSeismicsType() { return "Seismics"; }
261 inline const char* sPickSetType() { return "PickSets"; }
262 inline const char* sWellType() { return "Wells"; }
263 
264 } // namespace HDF5
265 
HDF5::Access::sCannotReadDataSet
static uiString sCannotReadDataSet(const DataSetKey &)
HDF5::sSeismicsType
const char * sSeismicsType()
Definition: hdf5access.h:260
HDF5::Access::sHDF5Err
static uiString sHDF5Err(const uiString &)
HDF5::SlabDimSpec::step_
ArrayNDInfo::idx_type step_
Definition: hdf5access.h:101
HDF5::Access::fileName
virtual const char * fileName() const =0
HDF5::Access::sNotHDF5File
static uiString sNotHDF5File(const char *)
HDF5::Access::sHDF5FileNoLongerAccessibe
static uiString sHDF5FileNoLongerAccessibe()
HDF5::isAvailable
bool isAvailable()
Definition: hdf5access.h:251
HDF5::DataSetKey::~DataSetKey
~DataSetKey()
HDF5::DataSetKey::groupKey
static DataSetKey groupKey(const DataSetKey &parentgrp, const char *subgrpnm)
HDF5::Access::curGroupID
virtual od_int64 curGroupID() const =0
factory.h
HDF5::Access::isOpen
bool isOpen() const
Definition: hdf5access.h:177
HDF5::DataSetKey::setDataSetName
DataSetKey & setDataSetName(const char *nm)
Definition: hdf5access.h:54
HDF5::DataSetKey::dsnm_
BufferString dsnm_
Definition: hdf5access.h:83
HDF5::Access::sOpenFileFirst
static const char * sOpenFileFirst()
HDF5::DataSetKey::groupKey
static DataSetKey groupKey(const char *parentfulldsnm, const char *grpnm)
od_int64
#define od_int64
Definition: plftypes.h:35
HDF5::Writer
writes to HDF5 file
Definition: hdf5writer.h:43
HDF5::Reader
Reads HDF5 file data.
Definition: hdf5reader.h:34
HDF5::DataSetKey::hasDataSet
bool hasDataSet(const char *nm) const
Definition: hdf5access.h:57
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
HDF5
Definition: hdf5access.h:22
HDF5::Access::sCantSetScope
uiString sCantSetScope(const DataSetKey &) const
HDF5::Access::sFileNotOpen
static uiString sFileNotOpen()
HDF5::Access::getScope
virtual H5::H5Object * getScope(const DataSetKey *) const =0
HDF5::Access::hasDataSet
bool hasDataSet(const DataSetKey &) const
HDF5::Access::scope
virtual DataSetKey scope() const =0
HDF5::Access::setScope
virtual H5::H5Object * setScope(const DataSetKey *)=0
sKey::DataSet
FixedString DataSet()
Definition: keystrs.h:56
HDF5::DataSetKey::fullDataSetName
BufferString fullDataSetName() const
HDF5::SlabDimSpec::operator==
bool operator==(const SlabDimSpec &oth) const
Definition: hdf5access.h:102
HDF5::DataSetKey::maxDimSz
int maxDimSz(int idim) const
HDF5::DataSetKey::setChunkSize
void setChunkSize(const int *szs, int nrdims=1, int from=0)
uiRetVal
Definition: uistringset.h:105
HDF5::SlabSpec::setNrDims
void setNrDims(nr_dims_type nrdims)
Definition: hdf5access.h:117
HDF5::mkWriter
Writer * mkWriter()
Definition: hdf5access.h:248
HDF5::Access::getHDF5File
H5::H5File * getHDF5File()
Definition: hdf5access.h:178
HDF5::DataSetKey::chunkSz
int chunkSz(int idim) const
HDF5::DataSetKey::DataSetKey
DataSetKey(const char *grpnm=nullptr, const char *dsnm=nullptr)
HDF5::AccessProvider::mDefineFactoryInClass
mDefineFactoryInClass(AccessProvider, factory) virtual Reader *getReader() const =0
HDF5::Access::Access
Access()
HDF5::Access::sHDF5NotAvailable
static uiString sHDF5NotAvailable()
HDF5::Access::sDataSetNotFound
static uiString sDataSetNotFound(const DataSetKey &)
arrayndinfo.h
HDF5::DataSetKey::hasGroup
bool hasGroup(const char *nm) const
HDF5::ODDataType
OD::DataRepType ODDataType
Definition: hdf5access.h:25
HDF5::Access::setGrpScope
virtual H5::Group * setGrpScope(const DataSetKey *)=0
HDF5::Access::myfile_
bool myfile_
Definition: hdf5access.h:202
HDF5::SlabSpec::SlabSpec
SlabSpec()
Definition: hdf5access.h:114
HDF5::Access::getDSScope
virtual H5::DataSet * getDSScope(const DataSetKey &) const =0
Returns (new) scope. null for root scope.
HDF5::Access::isEnvBlocked
static bool isEnvBlocked(const char *fortype=0)
HDF5::DataSetKey::dataSetName
const char * dataSetName() const
Definition: hdf5access.h:53
HDF5::Access::isEnabled
static bool isEnabled(const char *fortype=0)
HDF5::Access
Definition: hdf5access.h:164
HDF5::sFileExtension
const char * sFileExtension()
Definition: hdf5access.h:249
HDF5::AccessProvider::mkProv
static AccessProvider * mkProv(int)
mDefHDF5FileExt
#define mDefHDF5FileExt
Definition: hdf5access.h:18
HDF5::DataSetKey::isEditable
bool isEditable() const
HDF5::Access::mODTextTranslationClass
mODTextTranslationClass(HDF5::Access)
HDF5::Access::setDSScope
virtual H5::DataSet * setDSScope(const DataSetKey &)=0
HDF5::Access::getGrpScope
virtual H5::Group * getGrpScope(const DataSetKey *) const =0
HDF5::Access::mTypeDefArrNDTypes
mTypeDefArrNDTypes
Definition: hdf5access.h:166
HDF5::AccessProvider::mkReader
static Reader * mkReader(int n=-1)
HDF5::Access::sFileExtension
static const char * sFileExtension()
Definition: hdf5access.h:190
HDF5::Access::sHDF5NotAvailable
static uiString sHDF5NotAvailable(const char *fnm)
HDF5::DataSetKey::setChunkSize
void setChunkSize(int idim, int sz)
H5
Definition: hdf5access.h:16
HDF5::Access::openFile
virtual void openFile(const char *, uiRetVal &, bool ed)=0
HDF5::SlabDimSpec::count_
ArrayNDInfo::idx_type count_
-1 == full size
Definition: hdf5access.h:101
HDF5::DataSetKey::setEditable
void setEditable(bool yn)
HDF5::SlabDimSpec::idx_type
ArrayNDInfo::idx_type idx_type
Definition: hdf5access.h:99
HDF5::Access::hasGroup
bool hasGroup(const char *grpnm) const
HDF5::isEnabled
bool isEnabled(const char *typ=0)
Definition: hdf5access.h:253
BufferString
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size.
Definition: bufstring.h:40
ArrayNDInfo::idx_type
size_type idx_type
Definition: arrayndinfo.h:31
HDF5::DataSetKey::setGroupName
DataSetKey & setGroupName(const char *nm)
Definition: hdf5access.h:49
HDF5::Access::sSettingsEnabKey
static const char * sSettingsEnabKey()
Definition: hdf5access.h:195
HDF5::sWellType
const char * sWellType()
Definition: hdf5access.h:262
HDF5::Access::sHDF5PackageDispName
static uiString sHDF5PackageDispName()
HDF5::SlabDimSpec::start_
ArrayNDInfo::idx_type start_
Definition: hdf5access.h:101
HDF5::isEnvBlocked
bool isEnvBlocked(const char *typ=0)
Definition: hdf5access.h:255
HDF5::Access::~Access
virtual ~Access()
uiString
String that is able to hold international (UTF-8) strings for the user interface.
Definition: uistring.h:121
HDF5::isHDF5File
bool isHDF5File(const char *fnm)
Definition: hdf5access.h:257
OD::DataRepType
DataRepType
Definition: commontypes.h:49
HDF5::mkReader
Reader * mkReader()
Definition: hdf5access.h:247
HDF5::SlabSpec::mTypeDefArrNDTypes
mTypeDefArrNDTypes
Definition: hdf5access.h:112
HDF5::Access::isReader
virtual bool isReader() const =0
HDF5::Access::open
uiRetVal open(const char *)
HDF5::DataSetKey::dataSetEmpty
bool dataSetEmpty() const
Definition: hdf5access.h:56
HDF5::AccessProvider::~AccessProvider
virtual ~AccessProvider()
Definition: hdf5access.h:231
HDF5::AccessProvider::getWriter
virtual Writer * getWriter() const =0
HDF5::AccessProvider::mkWriter
static Writer * mkWriter(int n=-1)
HDF5::Access::isHDF5File
static bool isHDF5File(const char *)
MPE::step_
RowCol step_
Definition: horizontracker.h:140
HDF5::Access::sNoDataPassed
static const char * sNoDataPassed()
HDF5::Access::sNeedScope
static const char * sNeedScope()
HDF5::DataSetKey
Definition: hdf5access.h:42
HDF5::DataSetKey::grpnm_
BufferString grpnm_
Definition: hdf5access.h:82
HDF5::SlabDimSpec
Definition: hdf5access.h:96
HDF5::DataSetKey::setMaximumSize
void setMaximumSize(int idim, int maxsz=256)
HDF5::AccessProvider
Definition: hdf5access.h:228
HDF5::AccessImpl
brief Mixin for common stuff
Definition: hdf5accessimpl.h:25
HDF5::sPickSetType
const char * sPickSetType()
Definition: hdf5access.h:261
HDF5::Access::closeFile
virtual void closeFile()=0
HDF5::DataSetKey::groupName
const char * groupName() const
Definition: hdf5access.h:48
HDF5::Access::file_
H5::H5File * file_
Definition: hdf5access.h:201
HDF5::SlabSpec
Definition: hdf5access.h:109
HDF5::SlabSpec::SlabSpec
SlabSpec(nr_dims_type nrdims)
Definition: hdf5access.h:115
TypeSet< SlabDimSpec >

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2021