Skip to content

Commit c365186

Browse files
committed
Merge branch 'master' into newTestForGradient
2 parents b4a413c + c58fda6 commit c365186

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

src/io/APRWriter.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
struct AprType {hid_t hdf5type; const char * const typeName;};
1717
namespace AprTypes {
18+
1819
const AprType TotalNumberOfParticlesType = {H5T_NATIVE_UINT64, "total_number_particles"};
1920
const AprType TotalNumberOfGapsType = {H5T_NATIVE_UINT64, "total_number_gaps"};
2021
const AprType TotalNumberOfNonEmptyRowsType = {H5T_NATIVE_UINT64, "total_number_non_empty_rows"};
@@ -42,7 +43,6 @@ namespace AprTypes {
4243
const AprType NumberOfLevelXType = {H5T_NATIVE_INT, "x_num_"};
4344
const AprType NumberOfLevelYType = {H5T_NATIVE_INT, "y_num_"};
4445
const AprType NumberOfLevelZType = {H5T_NATIVE_INT, "z_num_"};
45-
const AprType ParticleIntensitiesDataType = {H5T_NATIVE_INT64, "data_type"};
4646
const AprType MapGlobalIndexType = {H5T_NATIVE_INT16, "map_global_index"};
4747
const AprType MapYendType = {H5T_NATIVE_INT16, "map_y_end"};
4848
const AprType MapYbeginType = {H5T_NATIVE_INT16, "map_y_begin"};
@@ -128,11 +128,9 @@ class APRWriter {
128128
}
129129

130130
// ------------- read data ------------------------------
131-
hid_t dataType;
132-
readAttr(AprTypes::ParticleIntensitiesDataType, f.groupId, &dataType);
133131
apr.particles_intensities.data.resize(apr.apr_access.total_number_particles);
134132
if (apr.particles_intensities.data.size() > 0) {
135-
readData({dataType, AprTypes::ParticleIntensitiesType}, f.objectId, apr.particles_intensities.data.data());
133+
readData(AprTypes::ParticleIntensitiesType, f.objectId, apr.particles_intensities.data.data());
136134
}
137135
apr.apr_access.y_num[apr.apr_access.level_max] = apr.apr_access.org_dims[0];
138136
apr.apr_access.x_num[apr.apr_access.level_max] = apr.apr_access.org_dims[1];
@@ -233,7 +231,6 @@ class APRWriter {
233231
apr_compressor.compress(apr,apr.particles_intensities);
234232
}
235233
hid_t type = Hdf5Type<ImageType>::type();
236-
writeAttr(AprTypes::ParticleIntensitiesDataType, f.groupId, &type);
237234
writeData({type, AprTypes::ParticleIntensitiesType}, f.objectId, apr.particles_intensities.data, blosc_comp_type, blosc_comp_level, blosc_shuffle);
238235
write_timer.stop_timer();
239236

@@ -341,8 +338,6 @@ class APRWriter {
341338
if (!f.isOpened()) return 0;
342339

343340
// ------------- write metadata -------------------------
344-
hid_t type = Hdf5Type<S>::type();
345-
writeAttr(AprTypes::ParticleIntensitiesDataType, f.groupId, &type);
346341
uint64_t total_number_parts = parts_extra.data.size();
347342
writeAttr(AprTypes::TotalNumberOfParticlesType, f.groupId, &total_number_parts);
348343
writeString(AprTypes::GitType, f.groupId, ConfigAPR::APR_GIT_HASH);
@@ -351,6 +346,7 @@ class APRWriter {
351346
unsigned int blosc_comp_type = BLOSC_ZSTD;
352347
unsigned int blosc_comp_level = 3;
353348
unsigned int blosc_shuffle = 2;
349+
hid_t type = Hdf5Type<S>::type();
354350
writeData({type, AprTypes::ExtraParticleDataType}, f.objectId, parts_extra.data, blosc_comp_type, blosc_comp_level, blosc_shuffle);
355351

356352
// ------------- output the file size -------------------
@@ -369,12 +365,10 @@ class APRWriter {
369365
// ------------- read metadata --------------------------
370366
uint64_t numberOfParticles;
371367
readAttr(AprTypes::TotalNumberOfParticlesType, f.groupId, &numberOfParticles);
372-
hid_t data_type;
373-
readAttr(AprTypes::ParticleIntensitiesDataType, f.groupId, &data_type);
374368

375369
// ------------- read data -----------------------------
376370
extra_parts.data.resize(numberOfParticles);
377-
readData({data_type, AprTypes::ExtraParticleDataType}, f.objectId, extra_parts.data.data());
371+
readData(AprTypes::ExtraParticleDataType, f.objectId, extra_parts.data.data());
378372
}
379373

380374
private:
@@ -455,6 +449,10 @@ class APRWriter {
455449
hdf5_load_data_blosc(aObjectId, aType.hdf5type, aDest, aType.typeName);
456450
}
457451

452+
void readData(const char * const aAprTypeName, hid_t aObjectId, void *aDest) {
453+
hdf5_load_data_blosc(aObjectId, aDest, aAprTypeName);
454+
}
455+
458456
template<typename T>
459457
void writeData(const AprType &aType, hid_t aObjectId, T aContainer, unsigned int blosc_comp_type, unsigned int blosc_comp_level,unsigned int blosc_shuffle) {
460458
hsize_t dims[] = {aContainer.size()};
@@ -478,6 +476,7 @@ class APRWriter {
478476
template<typename T> struct Hdf5Type {static hid_t type() {return T::CANNOT_DETECT_TYPE_AND_WILL_NOT_COMPILE;}};
479477
};
480478

479+
481480
template<> struct APRWriter::Hdf5Type<int8_t> {static hid_t type() {return H5T_NATIVE_INT8;}};
482481
template<> struct APRWriter::Hdf5Type<uint8_t> {static hid_t type() {return H5T_NATIVE_UINT8;}};
483482
template<> struct APRWriter::Hdf5Type<int16_t> {static hid_t type() {return H5T_NATIVE_INT16;}};
@@ -489,4 +488,5 @@ template<> struct APRWriter::Hdf5Type<uint64_t> {static hid_t type() {return H5T
489488
template<> struct APRWriter::Hdf5Type<float> {static hid_t type() {return H5T_NATIVE_FLOAT;}};
490489
template<> struct APRWriter::Hdf5Type<double> {static hid_t type() {return H5T_NATIVE_DOUBLE;}};
491490

491+
492492
#endif //APRWRITER_HPP

src/io/hdf5functions_blosc.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,20 @@ void register_blosc(){
2121
/**
2222
* reads data from hdf5
2323
*/
24-
void hdf5_load_data_blosc(hid_t obj_id, hid_t data_type, void* buff, const char* data_name) {
24+
void hdf5_load_data_blosc(hid_t obj_id, hid_t dataType, void* buff, const char* data_name) {
2525
hid_t data_id = H5Dopen2(obj_id, data_name ,H5P_DEFAULT);
26-
H5Dread(data_id, data_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, buff);
26+
H5Dread(data_id, dataType, H5S_ALL, H5S_ALL, H5P_DEFAULT, buff);
27+
H5Dclose(data_id);
28+
}
29+
30+
/**
31+
* reads data from hdf5 (data type auto-detection)
32+
*/
33+
void hdf5_load_data_blosc(hid_t obj_id, void* buff, const char* data_name) {
34+
hid_t data_id = H5Dopen2(obj_id, data_name ,H5P_DEFAULT);
35+
hid_t dataType = H5Dget_type(data_id);
36+
H5Dread(data_id, dataType, H5S_ALL, H5S_ALL, H5P_DEFAULT, buff);
37+
H5Tclose(dataType);
2738
H5Dclose(data_id);
2839
}
2940

src/io/hdf5functions_blosc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ extern "C" {
2424

2525
void register_blosc();
2626
hid_t hdf5_create_file_blosc(std::string file_name);
27-
void hdf5_load_data_blosc(hid_t obj_id,hid_t data_type,void* buff, const char* data_name);
27+
void hdf5_load_data_blosc(hid_t obj_id, void* buff, const char* data_name);
28+
void hdf5_load_data_blosc(hid_t obj_id, hid_t dataType, void* buff, const char* data_name);
2829
void hdf5_write_attribute_blosc(hid_t obj_id,hid_t type_id,const char* attr_name,hsize_t rank,hsize_t* dims, const void * const data );
29-
void hdf5_write_string_blosc(hid_t obj_id,const char* attr_name, const std::string &output_str);
3030
void hdf5_write_data_blosc(hid_t obj_id,hid_t type_id,const char* ds_name,hsize_t rank,hsize_t* dims, void* data ,unsigned int comp_type,unsigned int comp_level,unsigned int shuffle);
3131

3232
void write_main_paraview_xdmf_xml(std::string save_loc,std::string file_name,uint64_t num_parts);
-80 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)