6 #ifndef PYNE_MRNAFG5GNZDNPCRPX3UCBZ5MFE 7 #define PYNE_MRNAFG5GNZDNPCRPX3UCBZ5MFE 21 #ifndef PYNE_IS_AMALGAMATED 32 virtual const char* what()
const throw()
34 return "Index of point is out of bounds. Cannot handle in HDF5 file.";
57 virtual const char*
what()
const throw()
59 std::string FNH5str (
"Not a valid HDF5 file: ");
60 if (!filename.empty())
63 return (
const char *) FNH5str.c_str();
89 virtual const char*
what()
const throw()
91 std::string msg (
"the group ");
93 msg +=
" not found in the file ";
95 return (
const char *) msg.c_str();
100 std::string groupname;
122 virtual const char*
what()
const throw()
124 std::string msg (
"the path ");
126 msg +=
" was not found in the HDF5 file ";
128 return (
const char *) msg.c_str();
132 std::string filename;
142 template <
typename T>
145 hsize_t count [1] = {1};
146 hsize_t offset [1] = {
static_cast<hsize_t
>(n)};
148 hid_t dspace = H5Dget_space(dset);
149 hsize_t npoints = H5Sget_simple_extent_npoints(dspace);
153 offset[0] = offset[0] + npoints;
156 if (npoints <= offset[0])
159 H5Sselect_hyperslab(dspace, H5S_SELECT_SET, offset, NULL, count, NULL);
162 hsize_t dimsm[1] = {1};
163 hid_t memspace = H5Screate_simple(1, dimsm, NULL);
165 hsize_t count_out [1] = {1};
166 hsize_t offset_out [1] = {0};
168 H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset_out, NULL,
172 H5Dread(dset, dtype, memspace, dspace, H5P_DEFAULT, data_out);
186 template <
typename T>
189 std::set<T> cpp_set = std::set<T>();
191 hid_t dset = H5Dopen2(h5file, data_path.c_str(), H5P_DEFAULT);
194 hid_t arr_space = H5Dget_space(dset);
195 int arr_dim = H5Sget_simple_extent_dims(arr_space, arr_len, NULL);
198 T * mem_arr =
new T [arr_len[0]];
199 H5Dread(dset, dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, mem_arr);
202 cpp_set.insert(&mem_arr[0], &mem_arr[arr_len[0]]);
217 template <
typename T>
219 hid_t dtype=H5T_NATIVE_DOUBLE)
221 std::vector<T> cpp_vec;
222 hsize_t arr_dims [1];
223 hid_t dset = H5Dopen2(h5file, data_path.c_str(), H5P_DEFAULT);
226 hid_t arr_space = H5Dget_space(dset);
227 int arr_ndim = H5Sget_simple_extent_dims(arr_space, arr_dims, NULL);
230 T mem_arr [arr_dims[0]];
231 H5Dread(dset, dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, mem_arr);
234 cpp_vec.assign(mem_arr, mem_arr+arr_dims[0]);
247 template <
typename T>
249 hid_t dtype=H5T_NATIVE_DOUBLE)
251 hsize_t arr_dims [2];
252 hid_t dset = H5Dopen2(h5file, data_path.c_str(), H5P_DEFAULT);
255 hid_t arr_space = H5Dget_space(dset);
256 int arr_ndim = H5Sget_simple_extent_dims(arr_space, arr_dims, NULL);
261 T mem_arr [arr_dims[0] * arr_dims[1]];
262 H5Dread(dset, dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, mem_arr);
265 std::vector< std::vector<T> > cpp_vec (arr_dims[0], std::vector<T>(arr_dims[1]));
266 for(
int i = 0; i < arr_dims[0]; i++)
268 cpp_vec[i].assign(mem_arr+(i*arr_dims[1]), mem_arr+((i+1)*arr_dims[1]));
282 template <
typename T>
284 std::string data_path,
285 hid_t dtype=H5T_NATIVE_DOUBLE)
287 hsize_t arr_dims [3];
288 hid_t dset = H5Dopen2(h5file, data_path.c_str(), H5P_DEFAULT);
291 hid_t arr_space = H5Dget_space(dset);
292 int arr_ndim = H5Sget_simple_extent_dims(arr_space, arr_dims, NULL);
297 T mem_arr [arr_dims[0] * arr_dims[1] * arr_dims[2]];
298 H5Dread(dset, dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, mem_arr);
301 std::vector< std::vector< std::vector<T> > > cpp_vec (arr_dims[0], std::vector< std::vector<T> >(arr_dims[1], std::vector<T>(arr_dims[2])));
302 for(
int i = 0; i < arr_dims[0]; i++)
304 for(
int j = 0; j < arr_dims[1]; j++)
306 cpp_vec[i][j].assign(mem_arr+((i*arr_dims[1]*arr_dims[2]) + (j*arr_dims[2])), mem_arr+((i*arr_dims[1]*arr_dims[2]) + ((j+1)*arr_dims[2])));
319 template <
typename T>
337 hid_t h5_set = H5Dopen2(h5file, data_path.c_str(), H5P_DEFAULT);
338 hid_t h5_space = H5Dget_space(h5_set);
339 hid_t h5_type = H5Dget_type(h5_set);
345 shape[0] = H5Sget_simple_extent_npoints(h5_space);
346 shape[1] = H5Tget_nmembers(h5_type);
349 std::string * cols_buf =
new std::string [shape[1]];
350 for(
int n = 0; n < shape[1]; n++)
351 cols_buf[n] = H5Tget_member_name(h5_type, n);
352 cols.assign(cols_buf, cols_buf+shape[1]);
356 T * col_buf =
new T [shape[0]];
359 for(
int n = 0; n < shape[1]; n++)
362 col_type = H5Tcreate(H5T_COMPOUND,
sizeof(T));
363 H5Tinsert(col_type, cols[n].c_str(), 0, dtype);
366 H5Dread(h5_set, col_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, col_buf);
369 data[cols[n]] = std::vector<T>(col_buf, col_buf+shape[0]);
378 std::map<std::string, std::vector<T> > data;
385 std::vector<T> operator[] (std::string col_name)
387 return data[col_name];
391 std::map<std::string, T> operator[] (
int m)
393 std::map<std::string, T> row = std::map<std::string, T>();
395 for(
int n = 0; n < shape[1]; n++)
396 row[cols[n]] = data[cols[n]][m];
407 hid_t ct = H5Tcreate(H5T_COMPOUND,
sizeof(
xd_complex_t));
408 H5Tinsert(ct,
"r", HOFFSET(
xd_complex_t, re), H5T_NATIVE_DOUBLE);
409 H5Tinsert(ct,
"i", HOFFSET(
xd_complex_t, im), H5T_NATIVE_DOUBLE);
424 hid_t ds = H5Dopen2(h5file, path.c_str(), H5P_DEFAULT);
432 hid_t grp = H5Gopen2(h5file, path.c_str(), H5P_DEFAULT);
std::vector< std::string > cols
Definition: h5wrap.h:377
~PathNotFound()
default destructor
Definition: h5wrap.h:112
FileNotHDF5(std::string fname)
constructor with the filename
Definition: h5wrap.h:51
PathNotFound()
default constructor
Definition: h5wrap.h:109
virtual const char * what() const
helpful error message that includes the filename and the groupname
Definition: h5wrap.h:89
complex type struct, matching PyTables definition
Definition: extra_types.h:56
std::string path
path in file to the data
Definition: h5wrap.h:372
std::set< T > h5_array_to_cpp_set(hid_t h5file, std::string data_path, hid_t dtype=H5T_NATIVE_DOUBLE)
Definition: h5wrap.h:187
HomogenousTypeTable(hid_t h5file, std::string data_path, hid_t dtype=H5T_NATIVE_DOUBLE)
Definition: h5wrap.h:335
Custom exception for when a path is not found in an HDF5 file.
Definition: h5wrap.h:104
~GroupNotFound()
default destructor
Definition: h5wrap.h:80
GroupNotFound()
default constructor
Definition: h5wrap.h:77
~HomogenousTypeTable()
default destructor
Definition: h5wrap.h:328
std::vector< T > h5_array_to_cpp_vector_1d(hid_t h5file, std::string data_path, hid_t dtype=H5T_NATIVE_DOUBLE)
Definition: h5wrap.h:218
PathNotFound(std::string fname, std::string pname)
constructor with the filename and the pathname
Definition: h5wrap.h:115
std::vector< std::vector< T > > h5_array_to_cpp_vector_2d(hid_t h5file, std::string data_path, hid_t dtype=H5T_NATIVE_DOUBLE)
Definition: h5wrap.h:248
FileNotHDF5()
default constructor
Definition: h5wrap.h:45
Custom exception for when an existing file is not in a valid HDF5 format.
Definition: h5wrap.h:40
HomogenousTypeTable()
default constructor
Definition: h5wrap.h:325
Custom exception for when a group cannot be found in an HDF5 file.
Definition: h5wrap.h:72
std::vector< std::vector< std::vector< T > > > h5_array_to_cpp_vector_3d(hid_t h5file, std::string data_path, hid_t dtype=H5T_NATIVE_DOUBLE)
Definition: h5wrap.h:283
~FileNotHDF5()
default destructor
Definition: h5wrap.h:48
Wrapper for standard HDF5 operations.
Definition: h5wrap.h:26
virtual const char * what() const
helpful error message that includes the filename
Definition: h5wrap.h:57
hid_t _get_PYTABLES_COMPLEX128()
Definition: h5wrap.h:405
Custom exception for HDF5 indexing errors.
Definition: h5wrap.h:29
GroupNotFound(std::string fname, std::string gname)
constructor with the filename and the groupname
Definition: h5wrap.h:83
T get_array_index(hid_t dset, int n, hid_t dtype=H5T_NATIVE_DOUBLE)
Definition: h5wrap.h:143
virtual const char * what() const
helpful error message that includes the filename and the pathname
Definition: h5wrap.h:122
bool path_exists(hid_t h5file, std::string path)
Definition: h5wrap.h:421