1515
1616struct AprType {hid_t hdf5type; const char * const typeName;};
1717namespace 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
380374private:
@@ -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+
481480template <> struct APRWriter ::Hdf5Type<int8_t > {static hid_t type () {return H5T_NATIVE_INT8;}};
482481template <> struct APRWriter ::Hdf5Type<uint8_t > {static hid_t type () {return H5T_NATIVE_UINT8;}};
483482template <> 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
489488template <> struct APRWriter ::Hdf5Type<float > {static hid_t type () {return H5T_NATIVE_FLOAT;}};
490489template <> struct APRWriter ::Hdf5Type<double > {static hid_t type () {return H5T_NATIVE_DOUBLE;}};
491490
491+
492492#endif // APRWRITER_HPP
0 commit comments