44 #ifndef _INCLUDED_Field3D_SparseDataReader_H_ 45 #define _INCLUDED_Field3D_SparseDataReader_H_ 69 template <
class Data_T>
88 void readBlockList(
int idx,
const std::vector<Data_T*>& memoryList);
106 template <
class Data_T>
119 template <
class Data_T>
137 if (dataSet.
id() < 0)
138 throw OpenDataSetException(
"Couldn't open data set: " +
k_dataStr);
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");
150 memDataSpace.
create(H5S_SIMPLE);
151 H5Sset_extent_simple(memDataSpace.
id(), 1, memDims, NULL);
154 H5Sget_simple_extent_dims(fileDataSpace.
id(), dims, NULL);
156 throw FileIntegrityException(
"Block length mismatch in " 160 throw FileIntegrityException(
"Block count mismatch in " 172 status = H5Sselect_hyperslab(fileDataSpace.
id(), H5S_SELECT_SET,
173 offset, NULL, count, NULL);
176 throw ReadHyperSlabException(
"Couldn't select slab in readBlock(): " +
177 boost::lexical_cast<std::string>(idx));
181 memDataSpace.
id(), fileDataSpace.
id(),
182 H5P_DEFAULT, &result);
187 template <
class Data_T>
189 (
int idxLo,
const std::vector<Data_T*>& memoryList)
206 if (dataSet.
id() < 0)
207 throw OpenDataSetException(
"Couldn't open data set: " +
k_dataStr);
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");
219 memDataSpace.
create(H5S_SIMPLE);
220 H5Sset_extent_simple(memDataSpace.
id(), 1, memDims, NULL);
223 H5Sget_simple_extent_dims(fileDataSpace.
id(), dims, NULL);
225 throw FileIntegrityException(
"Block length mismatch in " 229 throw FileIntegrityException(
"Block count mismatch in " 238 count[0] = memoryList.size();
241 status = H5Sselect_hyperslab(fileDataSpace.
id(), H5S_SELECT_SET,
242 offset, NULL, count, NULL);
244 throw ReadHyperSlabException(
"Couldn't select slab in readBlockList():" +
245 boost::lexical_cast<std::string>(idxLo));
252 fileDims[0] = memoryList.size();
254 localMemDataSpace.
create(H5S_SIMPLE);
255 H5Sset_extent_simple(localMemDataSpace.
id(), 2, fileDims, NULL);
259 int bytesPerValue = 0;
262 if (t == H5T_NATIVE_CHAR)
264 else if (t == H5T_NATIVE_SHORT)
266 else if (t == H5T_NATIVE_FLOAT)
268 else if (t == H5T_NATIVE_DOUBLE)
272 int dim =
sizeof(Data_T) / bytesPerValue;
275 status = H5Dread(dataSet.
id(),
277 localMemDataSpace.
id(),
279 H5P_DEFAULT, &bigblock[0]);
282 throw Hdf5DataReadException(
"Couldn't read slab " +
283 boost::lexical_cast<std::string>(idxLo));
287 for (
size_t i = 0; i < memoryList.size(); ++i) {
288 memcpy(memoryList[i],
void open(hid_t dataset_id)
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Contains utility functions and classes for Hdf5 files.
Scoped object - opens a dataset on creation and closes it on destruction.
Namespace for Exception objects.
SparseDataReader(hid_t location, int valuesPerBlock, int occupiedBlocks)
Constructor. Requires knowledge of the Hdf5 location where data is stored.
Scoped object - opens a dataset on creation and closes it on destruction.
boost::recursive_mutex::scoped_lock GlobalLock
Contains various utility functions for Hdf5.
Contains the Log class which can be used to redirect output to an arbitrary destination.
void open(hid_t dataset_id)
void readBlock(int idx, Data_T &result)
Reads a block, storing the data in result, which is assumed to contain enough room for m_valuesPerBlo...
const std::string k_dataStr
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.
void open(hid_t parentLocation, const std::string &name, hid_t dapl_id)
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 enoug...
Scoped object - creates a dataspace on creation and closes it on destruction.
FIELD3D_NAMESPACE_OPEN FIELD3D_API boost::recursive_mutex g_hdf5Mutex
hid_t id() const
Query the hid_t value.
void create(H5S_class_t type)
Scoped object - opens a dataset on creation and closes it on destruction.