1313#include < memory>
1414
1515
16+ struct FileSizeInfo {
17+ float total_file_size=0 ;
18+ float intensity_data=0 ;
19+ float access_data=0 ;
20+ };
21+
22+
1623struct AprType {hid_t hdf5type; const char * const typeName;};
1724namespace AprTypes {
1825
@@ -174,7 +181,7 @@ class APRWriter {
174181 }
175182
176183 template <typename ImageType>
177- float write_apr (APR<ImageType>& apr, const std::string &save_loc, const std::string &file_name) {
184+ FileSizeInfo write_apr (APR<ImageType>& apr, const std::string &save_loc, const std::string &file_name) {
178185 APRCompress<ImageType> apr_compressor;
179186 apr_compressor.set_compression_type (0 );
180187 return write_apr (apr, save_loc, file_name, apr_compressor);
@@ -184,13 +191,14 @@ class APRWriter {
184191 * Writes the APR to the particle cell structure sparse format, using the p_map for reconstruction
185192 */
186193 template <typename ImageType>
187- float write_apr (APR<ImageType> &apr, const std::string &save_loc, const std::string &file_name, APRCompress<ImageType> &apr_compressor, unsigned int blosc_comp_type = BLOSC_ZSTD, unsigned int blosc_comp_level = 2 , unsigned int blosc_shuffle=1 ) {
194+ FileSizeInfo write_apr (APR<ImageType> &apr, const std::string &save_loc, const std::string &file_name, APRCompress<ImageType> &apr_compressor, unsigned int blosc_comp_type = BLOSC_ZSTD, unsigned int blosc_comp_level = 2 , unsigned int blosc_shuffle=1 ) {
188195 APRTimer write_timer;
189196 write_timer.verbose_flag = false ;
190197
191198 std::string hdf5_file_name = save_loc + file_name + " _apr.h5" ;
192199 AprFile f{hdf5_file_name, AprFile::Operation::WRITE};
193- if (!f.isOpened ()) return 0 ;
200+ FileSizeInfo fileSizeInfo1;
201+ if (!f.isOpened ()) return fileSizeInfo1;
194202
195203 // ------------- write metadata -------------------------
196204 writeAttr (AprTypes::NumberOfXType, f.groupId , &apr.apr_access .org_dims [1 ]);
@@ -225,14 +233,7 @@ class APRWriter {
225233 writeAttr (AprTypes::NoiseSdEstimateType, f.groupId , &apr.parameters .noise_sd_estimate );
226234 writeAttr (AprTypes::BackgroundIntensityEstimateType, f.groupId , &apr.parameters .background_intensity_estimate );
227235
228- // ------------- write data ----------------------------
229- write_timer.start_timer (" intensities" );
230- if (compress_type_num > 0 ){
231- apr_compressor.compress (apr,apr.particles_intensities );
232- }
233- hid_t type = Hdf5Type<ImageType>::type ();
234- writeData ({type, AprTypes::ParticleIntensitiesType}, f.objectId , apr.particles_intensities .data , blosc_comp_type, blosc_comp_level, blosc_shuffle);
235- write_timer.stop_timer ();
236+
236237
237238 write_timer.start_timer (" access_data" );
238239 MapStorageData map_data;
@@ -262,13 +263,35 @@ class APRWriter {
262263 writeAttr (AprTypes::NumberOfLevelZType, i, f.groupId , &z_num);
263264 }
264265
266+
265267 // ------------- output the file size -------------------
266268 hsize_t file_size = f.getFileSize ();
269+ double sizeMB_access = file_size / 1e6 ;
270+
271+ FileSizeInfo fileSizeInfo;
272+ fileSizeInfo.access_data = sizeMB_access;
273+
274+ // ------------- write data ----------------------------
275+ write_timer.start_timer (" intensities" );
276+ if (compress_type_num > 0 ){
277+ apr_compressor.compress (apr,apr.particles_intensities );
278+ }
279+ hid_t type = Hdf5Type<ImageType>::type ();
280+ writeData ({type, AprTypes::ParticleIntensitiesType}, f.objectId , apr.particles_intensities .data , blosc_comp_type, blosc_comp_level, blosc_shuffle);
281+ write_timer.stop_timer ();
282+
283+ // ------------- output the file size -------------------
284+ file_size = f.getFileSize ();
267285 double sizeMB = file_size / 1e6 ;
268- std::cout << " HDF5 Filesize: " << sizeMB << " MB\n " << " Writing Complete" << std::endl;
269- return sizeMB;
286+
287+ fileSizeInfo.total_file_size = sizeMB;
288+ fileSizeInfo.intensity_data = fileSizeInfo.total_file_size - fileSizeInfo.access_data ;
289+
290+ std::cout << " HDF5 Total Filesize: " << sizeMB << " MB\n " << " Writing Complete" << std::endl;
291+ return fileSizeInfo;
270292 }
271293
294+
272295 template <typename ImageType,typename T>
273296 void write_apr_paraview (APR<ImageType> &apr, const std::string &save_loc, const std::string &file_name, const ExtraParticleData<T> &parts) {
274297 std::string hdf5_file_name = save_loc + file_name + " _paraview.h5" ;
@@ -284,10 +307,7 @@ class APRWriter {
284307 writeAttr (AprTypes::TotalNumberOfParticlesType, f.groupId , &apr.apr_access .total_number_particles );
285308
286309 // ------------- write data ----------------------------
287- unsigned int blosc_comp_level = 1 ;
288- unsigned int blosc_shuffle = 2 ;
289- unsigned int blosc_comp_type = BLOSC_ZSTD;
290- writeData ({(Hdf5Type<T>::type ()), AprTypes::ParticlePropertyType}, f.objectId , parts.data , blosc_comp_type, blosc_comp_level, blosc_shuffle);
310+ writeDataStandard ({(Hdf5Type<T>::type ()), AprTypes::ParticlePropertyType}, f.objectId , parts.data );
291311
292312 APRIterator<ImageType> apr_iterator (apr);
293313 std::vector<uint16_t > xv (apr_iterator.total_number_particles ());
@@ -296,9 +316,9 @@ class APRWriter {
296316 std::vector<uint8_t > levelv (apr_iterator.total_number_particles ());
297317 std::vector<uint8_t > typev (apr_iterator.total_number_particles ());
298318
299- #ifdef HAVE_OPENMP
300- #pragma omp parallel for schedule(static) firstprivate(apr_iterator)
301- #endif
319+ #ifdef HAVE_OPENMP
320+ #pragma omp parallel for schedule(static) firstprivate(apr_iterator)
321+ #endif
302322 for (uint64_t particle_number= 0 ; particle_number < apr_iterator.total_number_particles (); ++particle_number) {
303323 apr_iterator.set_iterator_to_particle_by_number (particle_number);
304324 xv[particle_number] = apr_iterator.x_global ();
@@ -307,11 +327,11 @@ class APRWriter {
307327 levelv[particle_number] = apr_iterator.level ();
308328 typev[particle_number] = apr_iterator.type ();
309329 }
310- writeData (AprTypes::ParaviewXType, f.objectId , xv, blosc_comp_type, blosc_comp_level, blosc_shuffle );
311- writeData (AprTypes::ParaviewYType, f.objectId , yv, blosc_comp_type, blosc_comp_level, blosc_shuffle );
312- writeData (AprTypes::ParaviewZType, f.objectId , zv, blosc_comp_type, blosc_comp_level, blosc_shuffle );
313- writeData (AprTypes::ParaviewLevelType, f.objectId , levelv, blosc_comp_type, blosc_comp_level, blosc_shuffle );
314- writeData (AprTypes::ParaviewTypeType, f.objectId , typev, blosc_comp_type, blosc_comp_level, blosc_shuffle );
330+ writeDataStandard (AprTypes::ParaviewXType, f.objectId , xv);
331+ writeDataStandard (AprTypes::ParaviewYType, f.objectId , yv);
332+ writeDataStandard (AprTypes::ParaviewZType, f.objectId , zv);
333+ writeDataStandard (AprTypes::ParaviewLevelType, f.objectId , levelv);
334+ writeDataStandard (AprTypes::ParaviewTypeType, f.objectId , typev);
315335
316336 // TODO: This needs to be able extended to handle more general type, currently it is assuming uint16
317337 write_main_paraview_xdmf_xml (save_loc,hdf5_file_name, file_name,apr_iterator.total_number_particles ());
@@ -487,6 +507,13 @@ class APRWriter {
487507 hdf5_write_data_blosc (aObjectId, aType.hdf5type , aType.typeName , rank, dims, aContainer.data (), blosc_comp_type, blosc_comp_level, blosc_shuffle);
488508 }
489509
510+ template <typename T>
511+ void writeDataStandard (const AprType &aType, hid_t aObjectId, T aContainer) {
512+ hsize_t dims[] = {aContainer.size ()};
513+ const hsize_t rank = 1 ;
514+ hdf5_write_data_standard (aObjectId, aType.hdf5type , aType.typeName , rank, dims, aContainer.data ());
515+ }
516+
490517 void writeString (AprType aTypeName, hid_t aGroupId, const std::string &aValue) {
491518 if (aValue.size () > 0 ){
492519 hid_t aid = H5Screate (H5S_SCALAR);
0 commit comments