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 const char* FNH5str_rtn = FNH5str.c_str();
90 virtual const char*
what()
const throw()
92 std::string msg (
"the group ");
94 msg +=
" not found in the file ";
96 const char* msg_rtn = msg.c_str();
101 std::string filename;
102 std::string groupname;
124 virtual const char*
what()
const throw()
126 std::string msg (
"the path ");
128 msg +=
" was not found in the HDF5 file ";
130 const char* msg_rtn = msg.c_str();
135 std::string filename;
145 template <
typename T>
148 hsize_t count [1] = {1};
149 hsize_t offset [1] = {
static_cast<hsize_t
>(n)};
151 hid_t dspace = H5Dget_space(dset);
152 hsize_t npoints = H5Sget_simple_extent_npoints(dspace);
156 offset[0] = offset[0] + npoints;
159 if (npoints <= offset[0])
162 H5Sselect_hyperslab(dspace, H5S_SELECT_SET, offset, NULL, count, NULL);
165 hsize_t dimsm[1] = {1};
166 hid_t memspace = H5Screate_simple(1, dimsm, NULL);
168 hsize_t count_out [1] = {1};
169 hsize_t offset_out [1] = {0};
171 H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset_out, NULL,
175 H5Dread(dset, dtype, memspace, dspace, H5P_DEFAULT, data_out);
189 template <
typename T>
192 std::set<T> cpp_set = std::set<T>();
194 hid_t dset = H5Dopen2(h5file, data_path.c_str(), H5P_DEFAULT);
197 hid_t arr_space = H5Dget_space(dset);
198 int arr_dim = H5Sget_simple_extent_dims(arr_space, arr_len, NULL);
201 T * mem_arr =
new T [arr_len[0]];
202 H5Dread(dset, dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, mem_arr);
205 cpp_set.insert(&mem_arr[0], &mem_arr[arr_len[0]]);
220 template <
typename T>
222 hid_t dtype=H5T_NATIVE_DOUBLE)
224 std::vector<T> cpp_vec;
225 hsize_t arr_dims [1];
226 hid_t dset = H5Dopen2(h5file, data_path.c_str(), H5P_DEFAULT);
229 hid_t arr_space = H5Dget_space(dset);
230 int arr_ndim = H5Sget_simple_extent_dims(arr_space, arr_dims, NULL);
233 T mem_arr [arr_dims[0]];
234 H5Dread(dset, dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, mem_arr);
237 cpp_vec.assign(mem_arr, mem_arr+arr_dims[0]);
250 template <
typename T>
252 hid_t dtype=H5T_NATIVE_DOUBLE)
254 hsize_t arr_dims [2];
255 hid_t dset = H5Dopen2(h5file, data_path.c_str(), H5P_DEFAULT);
258 hid_t arr_space = H5Dget_space(dset);
259 int arr_ndim = H5Sget_simple_extent_dims(arr_space, arr_dims, NULL);
264 T mem_arr [arr_dims[0] * arr_dims[1]];
265 H5Dread(dset, dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, mem_arr);
268 std::vector< std::vector<T> > cpp_vec (arr_dims[0], std::vector<T>(arr_dims[1]));
269 for(
int i = 0; i < arr_dims[0]; i++)
271 cpp_vec[i].assign(mem_arr+(i*arr_dims[1]), mem_arr+((i+1)*arr_dims[1]));
285 template <
typename T>
287 std::string data_path,
288 hid_t dtype=H5T_NATIVE_DOUBLE)
290 hsize_t arr_dims [3];
291 hid_t dset = H5Dopen2(h5file, data_path.c_str(), H5P_DEFAULT);
294 hid_t arr_space = H5Dget_space(dset);
295 int arr_ndim = H5Sget_simple_extent_dims(arr_space, arr_dims, NULL);
300 T mem_arr [arr_dims[0] * arr_dims[1] * arr_dims[2]];
301 H5Dread(dset, dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, mem_arr);
304 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])));
305 for(
int i = 0; i < arr_dims[0]; i++)
307 for(
int j = 0; j < arr_dims[1]; j++)
309 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])));
322 template <
typename T>
340 hid_t h5_set = H5Dopen2(h5file, data_path.c_str(), H5P_DEFAULT);
341 hid_t h5_space = H5Dget_space(h5_set);
342 hid_t h5_type = H5Dget_type(h5_set);
348 shape[0] = H5Sget_simple_extent_npoints(h5_space);
349 shape[1] = H5Tget_nmembers(h5_type);
352 std::string * cols_buf =
new std::string [shape[1]];
353 for(
int n = 0; n < shape[1]; n++)
354 cols_buf[n] = H5Tget_member_name(h5_type, n);
355 cols.assign(cols_buf, cols_buf+shape[1]);
359 T * col_buf =
new T [shape[0]];
362 for(
int n = 0; n < shape[1]; n++)
365 col_type = H5Tcreate(H5T_COMPOUND,
sizeof(T));
366 H5Tinsert(col_type, cols[n].c_str(), 0, dtype);
369 H5Dread(h5_set, col_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, col_buf);
372 data[cols[n]] = std::vector<T>(col_buf, col_buf+shape[0]);
381 std::map<std::string, std::vector<T> > data;
388 std::vector<T> operator[] (std::string col_name)
390 return data[col_name];
394 std::map<std::string, T> operator[] (
int m)
396 std::map<std::string, T> row = std::map<std::string, T>();
398 for(
int n = 0; n < shape[1]; n++)
399 row[cols[n]] = data[cols[n]][m];
410 hid_t ct = H5Tcreate(H5T_COMPOUND,
sizeof(
xd_complex_t));
411 H5Tinsert(ct,
"r", HOFFSET(
xd_complex_t, re), H5T_NATIVE_DOUBLE);
412 H5Tinsert(ct,
"i", HOFFSET(
xd_complex_t, im), H5T_NATIVE_DOUBLE);
427 hid_t ds = H5Dopen2(h5file, path.c_str(), H5P_DEFAULT);
435 hid_t grp = H5Gopen2(h5file, path.c_str(), H5P_DEFAULT);
std::vector< std::string > cols
Definition: h5wrap.h:380
~PathNotFound()
default destructor
Definition: h5wrap.h:114
FileNotHDF5(std::string fname)
constructor with the filename
Definition: h5wrap.h:51
PathNotFound()
default constructor
Definition: h5wrap.h:111
complex type struct, matching PyTables definition
Definition: extra_types.h:56
std::string path
path in file to the data
Definition: h5wrap.h:375
std::set< T > h5_array_to_cpp_set(hid_t h5file, std::string data_path, hid_t dtype=H5T_NATIVE_DOUBLE)
Definition: h5wrap.h:190
HomogenousTypeTable(hid_t h5file, std::string data_path, hid_t dtype=H5T_NATIVE_DOUBLE)
Definition: h5wrap.h:338
Custom exception for when a path is not found in an HDF5 file.
Definition: h5wrap.h:106
~GroupNotFound()
default destructor
Definition: h5wrap.h:81
GroupNotFound()
default constructor
Definition: h5wrap.h:78
virtual const char * what() const
helpful error message that includes the filename and the groupname
Definition: h5wrap.h:90
~HomogenousTypeTable()
default destructor
Definition: h5wrap.h:331
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:221
PathNotFound(std::string fname, std::string pname)
constructor with the filename and the pathname
Definition: h5wrap.h:117
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:251
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:328
Custom exception for when a group cannot be found in an HDF5 file.
Definition: h5wrap.h:73
virtual const char * what() const
helpful error message that includes the filename and the pathname
Definition: h5wrap.h:124
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:286
~FileNotHDF5()
default destructor
Definition: h5wrap.h:48
Wrapper for standard HDF5 operations.
Definition: h5wrap.h:26
hid_t _get_PYTABLES_COMPLEX128()
Definition: h5wrap.h:408
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:84
virtual const char * what() const
helpful error message that includes the filename
Definition: h5wrap.h:57
T get_array_index(hid_t dset, int n, hid_t dtype=H5T_NATIVE_DOUBLE)
Definition: h5wrap.h:146
bool path_exists(hid_t h5file, std::string path)
Definition: h5wrap.h:424