cctw  0.2.1
Public Slots | Public Member Functions | Private Member Functions | Private Attributes | List of all members
CctwInputDataH5 Class Reference

#include <cctwinputdatah5.h>

Inheritance diagram for CctwInputDataH5:
Inheritance graph
Collaboration diagram for CctwInputDataH5:
Collaboration graph

Public Slots

virtual double readData (int dx, int dy, int dz)
 
QVector< double > readChunk (int ix, int iy, int iz, int nx, int ny, int nz)
 
- Public Slots inherited from CctwObject
virtual void printLine (QString line)
 
virtual void printMessage (QString msg, QDateTime dt=QDateTime::currentDateTime())
 
virtual QString settingsScript ()
 
QString scriptValueLiteral (QVariant v)
 

Public Member Functions

 CctwInputDataH5 (QString filePath, QString datasetName, QString name, CctwObject *parent)
 
CctwIntVector3D dimensions () const
 
CctwIntVector3D chunkSize () const
 
- Public Member Functions inherited from CctwObject
 CctwObject (QString name, QObject *parent=0)
 
virtual void writeSettings (QSettings *set, QString section)
 
virtual void readSettings (QSettings *set, QString section)
 

Private Member Functions

bool openInputFile ()
 
void setDimensions (CctwIntVector3D dims)
 
void setChunkSize (CctwIntVector3D cksz)
 

Private Attributes

CctwIntVector3D m_Dimensions
 
CctwIntVector3D m_ChunkSize
 
QString m_InputFilePath
 
QString m_DatasetName
 
hid_t m_FileId
 
hid_t m_DatasetId
 
hid_t m_DataspaceId
 

Additional Inherited Members

- Properties inherited from CctwObject
QString name
 

Detailed Description

Definition at line 8 of file cctwinputdatah5.h.

Constructor & Destructor Documentation

CctwInputDataH5::CctwInputDataH5 ( QString  filePath,
QString  datasetName,
QString  name,
CctwObject parent 
)
explicit

Definition at line 4 of file cctwinputdatah5.cpp.

References openInputFile().

4  :
5  CctwObject(name, parent),
6  m_InputFilePath(filePath),
7  m_DatasetName(datasetName),
8  m_FileId(-1),
9  m_DatasetId(-1),
10  m_DataspaceId(-1)
11 {
12  openInputFile();
13 }
QString name
Definition: cctwobject.h:32
QString m_InputFilePath
CctwObject(QString name, QObject *parent=0)
Definition: cctwobject.cpp:7

Member Function Documentation

CctwIntVector3D CctwInputDataH5::chunkSize ( ) const

Definition at line 183 of file cctwinputdatah5.cpp.

References m_ChunkSize.

184 {
185  return m_ChunkSize;
186 }
CctwIntVector3D m_ChunkSize
CctwIntVector3D CctwInputDataH5::dimensions ( ) const

Definition at line 178 of file cctwinputdatah5.cpp.

References m_Dimensions.

Referenced by CctwImporter::checkImportedDataApproximately(), and CctwComparer::compareDatasetsApproximately().

179 {
180  return m_Dimensions;
181 }
CctwIntVector3D m_Dimensions
bool CctwInputDataH5::openInputFile ( )
private

Definition at line 15 of file cctwinputdatah5.cpp.

References m_DatasetId, m_DatasetName, m_DataspaceId, m_FileId, m_InputFilePath, CctwObject::printMessage(), setChunkSize(), and setDimensions().

Referenced by CctwInputDataH5().

16 {
17  QFileInfo f(m_InputFilePath);
18 
19  if (!f.exists()) {
20  printMessage(tr("File %1 does not exist").arg(m_InputFilePath));
21  return false;
22  }
23 
24  if (!H5Fis_hdf5(qPrintable(m_InputFilePath))) {
25  printMessage(tr("File %1 exists but is not an hdf file").arg(m_InputFilePath));
26  return false;
27  }
28 
29  m_FileId = H5Fopen(qPrintable(m_InputFilePath), H5F_ACC_RDONLY, H5P_DEFAULT);
30 
31  if (m_FileId < 0) {
32  printMessage(tr("File %1 could not be opened").arg(m_InputFilePath));
33  return false;
34  }
35 
36  m_DatasetId = H5Dopen1(m_FileId, qPrintable(m_DatasetName));
37 
38  if (m_DatasetId < 0) {
39  printMessage(tr("Dataset %1 not found in file %2").arg(m_DatasetName).arg(m_InputFilePath));
40  return false;
41  }
42 
43  m_DataspaceId = H5Dget_space(m_DatasetId);
44 
45  if (m_DataspaceId < 0) {
46  printMessage(tr("Couldn't get dataspace of dataset %1").arg(m_DatasetName));
47  return false;
48  }
49 
50  int ndims = H5Sget_simple_extent_ndims(m_DataspaceId);
51 
52  if (ndims != 3) {
53  printMessage(tr("Dataspace is not 3 dimensional (%1)").arg(ndims));
54  return false;
55  }
56 
57  hsize_t dims[3];
58 
59  int ndims2 = H5Sget_simple_extent_dims(m_DataspaceId, dims, NULL);
60 
61  if (ndims2 != 3) {
62  printMessage("Couldnt get dataspace dimensions");
63  return false;
64  }
65 
66  setDimensions(CctwIntVector3D(dims[2], dims[1], dims[0]));
67 
68  hid_t pl = H5Dget_create_plist(m_DatasetId);
69 
70  if (pl < 0) {
71  printMessage("Couldn't get dataset property list");
72  return false;
73  }
74 
75  hsize_t cksz[3];
76 
77  int chnks = H5Pget_chunk(pl, 3, cksz);
78 
79  if (chnks != 3) {
80  printMessage("Chunks are not 3 dimensional");
81  return false;
82  }
83 
84  setChunkSize(CctwIntVector3D(cksz[2], cksz[1], cksz[0]));
85 
86  return true;
87 }
QString m_InputFilePath
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
void setChunkSize(CctwIntVector3D cksz)
CctwVector3D< int > CctwIntVector3D
Definition: cctwvector3d.h:70
void setDimensions(CctwIntVector3D dims)
QVector< double > CctwInputDataH5::readChunk ( int  ix,
int  iy,
int  iz,
int  nx,
int  ny,
int  nz 
)
slot

Definition at line 129 of file cctwinputdatah5.cpp.

References m_DatasetId, m_DataspaceId, m_FileId, and CctwObject::printMessage().

Referenced by CctwComparer::compareDatasetsApproximately().

130 {
131  QVector<double> data(nx*ny*nz);
132 
133  if (m_FileId >= 0) {
134  hid_t memspace_id;
135  hsize_t offset[3], count[3], stride[3], block[3];
136 
137  count[0] = nz;
138  count[1] = ny;
139  count[2] = nx;
140 
141  stride[0] = 1;
142  stride[1] = 1;
143  stride[2] = 1;
144 
145  block[0] = 1;
146  block[1] = 1;
147  block[2] = 1;
148 
149  offset[0] = iz;
150  offset[1] = iy;
151  offset[2] = ix;
152 
153 
154  memspace_id = H5Screate_simple(3, count, NULL);
155 
156  herr_t selerr = H5Sselect_hyperslab(m_DataspaceId, H5S_SELECT_SET, offset, stride, count, block);
157  herr_t rderr = H5Dread(m_DatasetId, H5T_NATIVE_DOUBLE, memspace_id, m_DataspaceId, H5P_DEFAULT, data.data());
158 
159  if (selerr || rderr) {
160  printMessage(tr("Error reading x:%1, y:%2, z:%3, selerr = %4, wrterr = %5")
161  .arg(ix).arg(iy).arg(iz).arg(selerr).arg(rderr));
162  }
163  }
164 
165  return data;
166 }
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
double CctwInputDataH5::readData ( int  dx,
int  dy,
int  dz 
)
virtualslot

Definition at line 89 of file cctwinputdatah5.cpp.

References m_DatasetId, m_DataspaceId, m_FileId, and CctwObject::printMessage().

Referenced by CctwImporter::checkImportedDataApproximately().

90 {
91  if (m_FileId >= 0) {
92  hid_t memspace_id;
93  hsize_t offset[3], count[3], stride[3], block[3];
94  double data[10];
95 
96  count[0] = 1;
97  count[1] = 1;
98  count[2] = 1;
99 
100  stride[0] = 1;
101  stride[1] = 1;
102  stride[2] = 1;
103 
104  block[0] = 1;
105  block[1] = 1;
106  block[2] = 1;
107 
108  offset[0] = dz;
109  offset[1] = dy;
110  offset[2] = dx;
111 
112 
113  memspace_id = H5Screate_simple(3, count, NULL);
114 
115  herr_t selerr = H5Sselect_hyperslab(m_DataspaceId, H5S_SELECT_SET, offset, stride, count, block);
116  herr_t rderr = H5Dread(m_DatasetId, H5T_NATIVE_DOUBLE, memspace_id, m_DataspaceId, H5P_DEFAULT, data);
117 
118  if (selerr || rderr) {
119  printMessage(tr("Error reading x:%1, y:%2, z:%3, selerr = %4, wrterr = %5")
120  .arg(dx).arg(dy).arg(dz).arg(selerr).arg(rderr));
121  }
122 
123  return data[0];
124  }
125 
126  return 0;
127 }
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
void CctwInputDataH5::setChunkSize ( CctwIntVector3D  cksz)
private

Definition at line 173 of file cctwinputdatah5.cpp.

References m_ChunkSize.

Referenced by openInputFile().

174 {
175  m_ChunkSize = cksz;
176 }
CctwIntVector3D m_ChunkSize
void CctwInputDataH5::setDimensions ( CctwIntVector3D  dims)
private

Definition at line 168 of file cctwinputdatah5.cpp.

References m_Dimensions.

Referenced by openInputFile().

169 {
170  m_Dimensions = dims;
171 }
CctwIntVector3D m_Dimensions

Member Data Documentation

CctwIntVector3D CctwInputDataH5::m_ChunkSize
private

Definition at line 35 of file cctwinputdatah5.h.

Referenced by chunkSize(), and setChunkSize().

hid_t CctwInputDataH5::m_DatasetId
private

Definition at line 39 of file cctwinputdatah5.h.

Referenced by openInputFile(), readChunk(), and readData().

QString CctwInputDataH5::m_DatasetName
private

Definition at line 37 of file cctwinputdatah5.h.

Referenced by openInputFile().

hid_t CctwInputDataH5::m_DataspaceId
private

Definition at line 40 of file cctwinputdatah5.h.

Referenced by openInputFile(), readChunk(), and readData().

CctwIntVector3D CctwInputDataH5::m_Dimensions
private

Definition at line 34 of file cctwinputdatah5.h.

Referenced by dimensions(), and setDimensions().

hid_t CctwInputDataH5::m_FileId
private

Definition at line 38 of file cctwinputdatah5.h.

Referenced by openInputFile(), readChunk(), and readData().

QString CctwInputDataH5::m_InputFilePath
private

Definition at line 36 of file cctwinputdatah5.h.

Referenced by openInputFile().


The documentation for this class was generated from the following files: