Field3D

This class gets used by SparseFieldIO and SparseFileManager to read the block data. On creation it will open the data set and not close it until the object is destroyed. More...

#include <SparseDataReader.h>

Public Member Functions

void readBlock (int idx, Data_T &result)
 Reads a block, storing the data in result, which is assumed to contain enough room for m_valuesPerBlock entries.
 
void readBlockList (int idx, const std::vector< Data_T * > &memoryList)
 Reads a series of blocks, storing each block of data in memoryList, which is assumed to contain enough room for m_valuesPerBlock entries.
 
 SparseDataReader (hid_t location, int valuesPerBlock, int occupiedBlocks)
 Constructor. Requires knowledge of the Hdf5 location where data is stored.
 

Private Attributes

const std::string k_dataStr
 
hid_t m_location
 
int m_occupiedBlocks
 
int m_valuesPerBlock
 

Detailed Description

template<class Data_T>
class SparseDataReader< Data_T >

This class gets used by SparseFieldIO and SparseFileManager to read the block data. On creation it will open the data set and not close it until the object is destroyed.

Definition at line 70 of file SparseDataReader.h.

Constructor & Destructor Documentation

◆ SparseDataReader()

template<class Data_T >
SparseDataReader< Data_T >::SparseDataReader ( hid_t location,
int valuesPerBlock,
int occupiedBlocks )

Constructor. Requires knowledge of the Hdf5 location where data is stored.

Definition at line 107 of file SparseDataReader.h.

109 : m_location(location),
110 m_valuesPerBlock(valuesPerBlock),
111 m_occupiedBlocks(occupiedBlocks),
112 k_dataStr("data")
113{
114
115}
const std::string k_dataStr

Member Function Documentation

◆ readBlock()

template<class Data_T >
void SparseDataReader< Data_T >::readBlock ( int idx,
Data_T & result )

Reads a block, storing the data in result, which is assumed to contain enough room for m_valuesPerBlock entries.

Definition at line 120 of file SparseDataReader.h.

121{
122 using namespace Hdf5Util;
123 using namespace Exc;
124
126
131
132 hsize_t dims[2];
133 hsize_t memDims[1];
134
135 // Open the data set
137 if (dataSet.id() < 0)
138 throw OpenDataSetException("Couldn't open data set: " + k_dataStr);
139
140 // Get the space and type
141 fileDataSpace.open(dataSet.id());
142 dataType.open(dataSet.id());
143 if (fileDataSpace.id() < 0)
144 throw GetDataSpaceException("Couldn't get data space");
145 if (dataType.id() < 0)
146 throw GetDataTypeException("Couldn't get data type");
147
148 // Make the memory data space
150 memDataSpace.create(H5S_SIMPLE);
152
153 // Get the dimensions and check they match
155 if (dims[1] != static_cast<hsize_t>(m_valuesPerBlock)) {
156 throw FileIntegrityException("Block length mismatch in "
157 "SparseDataReader");
158 }
159 if (dims[0] != static_cast<hsize_t>(m_occupiedBlocks))
160 throw FileIntegrityException("Block count mismatch in "
161 "SparseDataReader");
162
163 hsize_t offset[2];
164 hsize_t count[2];
166
167 offset[0] = idx; // Index of block
168 offset[1] = 0; // Index of first data in block. Always 0
169 count[0] = 1; // Number of columns to read. Always 1
170 count[1] = m_valuesPerBlock; // Number of values in one column
171
173 offset, NULL, count, NULL);
174
175 if (status < 0) {
176 throw ReadHyperSlabException("Couldn't select slab in readBlock(): " +
177 boost::lexical_cast<std::string>(idx));
178 }
179
181 memDataSpace.id(), fileDataSpace.id(),
182 H5P_DEFAULT, &result);
183}
FIELD3D_NAMESPACE_OPEN FIELD3D_API boost::recursive_mutex g_hdf5Mutex
Definition Hdf5Util.cpp:67
boost::recursive_mutex::scoped_lock GlobalLock
Definition Hdf5Util.h:78
#define FIELD3D_MTX_T
Definition StdMathLib.h:99
Scoped object - opens a dataset on creation and closes it on destruction.
Definition Hdf5Util.h:387
Scoped object - opens a dataset on creation and closes it on destruction.
Definition Hdf5Util.h:417
Scoped object - opens a dataset on creation and closes it on destruction.
Definition Hdf5Util.h:357
Scoped object - creates a dataspace on creation and closes it on destruction.
Definition Hdf5Util.h:235
Namespace for Exception objects.
Definition Exception.h:57
Contains utility functions and classes for Hdf5 files.
Definition Hdf5Util.h:86

References FIELD3D_MTX_T, and g_hdf5Mutex.

◆ readBlockList()

template<class Data_T >
void SparseDataReader< Data_T >::readBlockList ( int idx,
const std::vector< Data_T * > & memoryList )

Reads a series of blocks, storing each block of data in memoryList, which is assumed to contain enough room for m_valuesPerBlock entries.

Definition at line 188 of file SparseDataReader.h.

190{
191 using namespace Hdf5Util;
192 using namespace Exc;
193
195
200
201 hsize_t dims[2];
202 hsize_t memDims[1];
203
204 // Open the data set
206 if (dataSet.id() < 0)
207 throw OpenDataSetException("Couldn't open data set: " + k_dataStr);
208
209 // Get the space and type
210 fileDataSpace.open(dataSet.id());
211 dataType.open(dataSet.id());
212 if (fileDataSpace.id() < 0)
213 throw GetDataSpaceException("Couldn't get data space");
214 if (dataType.id() < 0)
215 throw GetDataTypeException("Couldn't get data type");
216
217 // Make the memory data space
219 memDataSpace.create(H5S_SIMPLE);
221
222 // Get the dimensions and check they match
224 if (dims[1] != static_cast<hsize_t>(m_valuesPerBlock)) {
225 throw FileIntegrityException("Block length mismatch in "
226 "SparseDataReader");
227 }
228 if (dims[0] != static_cast<hsize_t>(m_occupiedBlocks))
229 throw FileIntegrityException("Block count mismatch in "
230 "SparseDataReader");
231
232 hsize_t offset[2];
233 hsize_t count[2];
235
236 offset[0] = idxLo; // Index of block
237 offset[1] = 0; // Index of first data in block. Always 0
238 count[0] = memoryList.size(); // Number of columns to read.
239 count[1] = m_valuesPerBlock; // Number of values in one column
240
242 offset, NULL, count, NULL);
243 if (status < 0) {
244 throw ReadHyperSlabException("Couldn't select slab in readBlockList():" +
245 boost::lexical_cast<std::string>(idxLo));
246 }
247
248 // Make the memory data space ---
249
251 hsize_t fileDims[2];
252 fileDims[0] = memoryList.size();
256
257 // Setup the temporary memory region ---
258
259 int bytesPerValue = 0;
260 {
262 if (t == H5T_NATIVE_CHAR)
263 bytesPerValue = 1;
264 else if (t == H5T_NATIVE_SHORT)
265 bytesPerValue = 2;
266 else if (t == H5T_NATIVE_FLOAT)
267 bytesPerValue = 4;
268 else if (t == H5T_NATIVE_DOUBLE)
269 bytesPerValue = 8;
270 }
271
272 int dim = sizeof(Data_T) / bytesPerValue;
273 std::vector<Data_T> bigblock(memoryList.size() * m_valuesPerBlock/dim);
274
275 status = H5Dread(dataSet.id(),
278 fileDataSpace.id(),
279 H5P_DEFAULT, &bigblock[0]);
280
281 if (status < 0) {
282 throw Hdf5DataReadException("Couldn't read slab " +
283 boost::lexical_cast<std::string>(idxLo));
284 }
285
286 // Distribute block data into memory slots ---
287 for (size_t i = 0; i < memoryList.size(); ++i) {
291 }
292}
void create(H5S_class_t type)
Definition Hdf5Util.h:246
static hid_t h5type()

References Hdf5Util::H5ScopedScreate::create(), FIELD3D_MTX_T, g_hdf5Mutex, and DataTypeTraits< T >::h5type().

Member Data Documentation

◆ m_location

template<class Data_T >
hid_t SparseDataReader< Data_T >::m_location
private

Definition at line 94 of file SparseDataReader.h.

◆ m_valuesPerBlock

template<class Data_T >
int SparseDataReader< Data_T >::m_valuesPerBlock
private

Definition at line 96 of file SparseDataReader.h.

◆ m_occupiedBlocks

template<class Data_T >
int SparseDataReader< Data_T >::m_occupiedBlocks
private

Definition at line 97 of file SparseDataReader.h.

◆ k_dataStr

template<class Data_T >
const std::string SparseDataReader< Data_T >::k_dataStr
private

Definition at line 99 of file SparseDataReader.h.


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