Skip to content

Commit 49ed242

Browse files
committed
Added versioning + APR git hash capture stuff
1 parent 00e77db commit 49ed242

File tree

6 files changed

+45
-117
lines changed

6 files changed

+45
-117
lines changed

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ cmake_minimum_required(VERSION 3.2)
55
project(LibAPR)
66
set(CMAKE_CXX_STANDARD 14)
77

8+
###############################################################################
9+
# Generate configuration file
10+
###############################################################################
11+
set (APR_VERSION_MAJOR 1)
12+
set (APR_VERSION_MINOR 0)
13+
set (APR_VERSION_PATCH 0)
14+
execute_process(COMMAND git rev-parse HEAD OUTPUT_VARIABLE APR_GIT_HASH)
15+
string(REGEX REPLACE "\n$" "" APR_GIT_HASH "${APR_GIT_HASH}")
16+
configure_file (
17+
"${PROJECT_SOURCE_DIR}/src/ConfigAPR.h.in"
18+
"${PROJECT_BINARY_DIR}/ConfigAPR.h"
19+
)
20+
include_directories("${PROJECT_BINARY_DIR}")
21+
822
###############################################################################
923
# Find all required libraries
1024
###############################################################################

examples/Example_get_apr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ Advanced (Direct) Settings:
2828

2929
#include <algorithm>
3030
#include <iostream>
31+
#include "ConfigAPR.h"
3132
#include "Example_get_apr.h"
3233

3334

35+
3436
int main(int argc, char **argv) {
3537

3638
//input parsing
@@ -132,6 +134,7 @@ cmdLineOptions read_command_line_options(int argc, char **argv){
132134

133135
if(argc == 1) {
134136
std::cerr << argv[0] << std::endl;
137+
std::cerr << "APR version " << ConfigAPR::getVersionString() << std::endl;
135138
std::cerr << "Short usage: \"" << argv[0] << " -i inputfile [-d directory] [-o outputfile]\"" << std::endl;
136139

137140
std::cerr << usage << std::endl;

src/ConfigAPR.h.in

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Template configuration file for APR.
3+
*
4+
* Krzysztof Gonciarz 2018
5+
*/
6+
#ifndef CONFIG_APR_H
7+
#define CONFIG_APR_H
8+
9+
10+
#include <string>
11+
12+
namespace ConfigAPR {
13+
const unsigned int APR_VERSION_MAJOR = @APR_VERSION_MAJOR@;
14+
const unsigned int APR_VERSION_MINOR = @APR_VERSION_MINOR@;
15+
const unsigned int APR_VERSION_PATCH = @APR_VERSION_PATCH@;
16+
const std::string APR_GIT_HASH = "@APR_GIT_HASH@";
17+
18+
static constexpr auto getVersionString() {
19+
return "@APR_VERSION_MAJOR@.@APR_VERSION_MINOR@.@APR_VERSION_PATCH@";
20+
}
21+
}
22+
23+
#endif

src/io/APRWriter.hpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "src/data_structures/APR/APR.hpp"
1010
#include <src/data_structures/APR/APRAccess.hpp>
1111
#include <numeric>
12+
#include "ConfigAPR.h"
1213

1314
template<typename U>
1415
class APR;
@@ -178,8 +179,6 @@ class APRWriter {
178179
H5Aread(attr_id,H5T_NATIVE_FLOAT,&apr.parameters.noise_sd_estimate ) ;
179180
H5Aclose(attr_id);
180181

181-
//std::cout << "Number particles: " << num_parts << " Number Cells: " << num_cells << std::endl;
182-
183182
apr.apr_access.x_num.resize(apr.apr_access.level_max+1);
184183
apr.apr_access.y_num.resize(apr.apr_access.level_max+1);
185184
apr.apr_access.z_num.resize(apr.apr_access.level_max+1);
@@ -403,9 +402,7 @@ class APRWriter {
403402

404403
hdf5_write_string_blosc(pr_groupid,"name",apr.name);
405404

406-
std::string git_hash = exec_blosc("git rev-parse HEAD");
407-
408-
hdf5_write_string_blosc(pr_groupid,"githash",git_hash);
405+
hdf5_write_string_blosc(pr_groupid,"githash", ConfigAPR::APR_GIT_HASH);
409406

410407
hdf5_write_attribute_blosc(pr_groupid,H5T_NATIVE_INT,"compress_type",1,dims_out, &compress_type_num);
411408

@@ -632,9 +629,7 @@ class APRWriter {
632629

633630
hdf5_write_string_blosc(pr_groupid,"name",apr.name);
634631

635-
std::string git_hash = exec_blosc("git rev-parse HEAD");
636-
637-
hdf5_write_string_blosc(pr_groupid,"githash",git_hash);
632+
hdf5_write_string_blosc(pr_groupid,"githash", ConfigAPR::APR_GIT_HASH);
638633

639634
//////////////////////////////////////////////////////////////////
640635
//
@@ -779,7 +774,7 @@ class APRWriter {
779774

780775
//just an identifier in here for the reading of the parts
781776
S val = 0;
782-
hid_t type_id = get_type_blosc(val);
777+
hid_t type_id = get_type_data_hdf5(val);
783778
hid_t type = get_type_data_hdf5(val);
784779

785780
hdf5_write_attribute_blosc(pr_groupid,H5T_NATIVE_INT,"data_type",1,dims_out, &type_id);
@@ -806,10 +801,7 @@ class APRWriter {
806801

807802

808803
// New parameter and background data
809-
810-
std::string git_hash = exec_blosc("git rev-parse HEAD");
811-
812-
hdf5_write_string_blosc(pr_groupid,"githash",git_hash);
804+
hdf5_write_string_blosc(pr_groupid,"githash", ConfigAPR::APR_GIT_HASH);
813805

814806
// output the file size
815807
hsize_t file_size;

src/io/hdf5functions_blosc.cpp

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,7 @@
1010

1111
#include "hdf5functions_blosc.h"
1212
#include <array>
13-
#include <string>
14-
#include <memory>
1513

16-
// TODO: This is not supported for UWP, find a replacement
17-
#ifdef _WINDOWS
18-
#define popen _popen
19-
#define pclose _pclose
20-
#endif
21-
22-
std::string exec_blosc(const char* cmd) {
23-
std::array<char, 128> buffer;
24-
std::string result;
25-
std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
26-
if (!pipe) throw std::runtime_error("popen() failed!");
27-
while (!feof(pipe.get())) {
28-
if (fgets(buffer.data(), 128, pipe.get()) != NULL)
29-
result += buffer.data();
30-
}
31-
return result;
32-
}
3314

3415
void register_bosc(){
3516
/* Register the filter with the library */
@@ -51,65 +32,6 @@ void hdf5_load_data_blosc(hid_t obj_id,hid_t data_type,void* buff, const char* d
5132
H5Dclose(data_id);
5233
}
5334

54-
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 ){
55-
//writes data to the hdf5 file or group identified by obj_id of hdf5 datatype data_type
56-
57-
unsigned int cd_values[7];
58-
//Declare the required hdf5 shiz
59-
hid_t space_id,dset_id,plist_id;
60-
hsize_t *cdims = new hsize_t[rank]; //chunking dims
61-
62-
//compression parameters
63-
64-
65-
//int szip_options_mask = H5_SZIP_NN_OPTION_MASK;
66-
//int szip_pixels_per_block = 8;
67-
68-
//dataspace id
69-
space_id = H5Screate_simple(rank, dims, NULL);
70-
plist_id = H5Pcreate(H5P_DATASET_CREATE);
71-
72-
/* Dataset must be chunked for compression */
73-
//cdims[0] = 20; //Could try playing with these for compression performance
74-
//cdims[1] = 20;
75-
76-
uint64_t max_size = 100000;
77-
78-
if (rank == 1) {
79-
if (dims[0] < max_size){
80-
cdims[0] = dims[0];
81-
}else {
82-
cdims[0] = max_size;
83-
}
84-
}
85-
else {
86-
cdims[0] = 100;
87-
cdims[1] = 100;
88-
}
89-
90-
H5Pset_chunk(plist_id, rank, cdims);
91-
92-
/////SET COMPRESSION TYPE /////
93-
94-
/* But you can also taylor Blosc parameters to your needs */
95-
/* 0 to 3 (inclusive) param slots are reserved. */
96-
cd_values[4] = 6; /* compression level */
97-
cd_values[5] = 2; /* 0: shuffle not active, 1: shuffle active */
98-
cd_values[6] = BLOSC_ZSTD; /* the actual compressor to use */
99-
100-
/* Set the filter with 7 params */
101-
H5Pset_filter(plist_id, FILTER_BLOSC, H5Z_FLAG_OPTIONAL, 7, cd_values);
102-
103-
//create write and close
104-
dset_id = H5Dcreate2(obj_id,ds_name,type_id,space_id,H5P_DEFAULT,plist_id,H5P_DEFAULT);
105-
106-
H5Dwrite(dset_id,type_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,data);
107-
108-
H5Dclose(dset_id);
109-
110-
111-
}
112-
11335
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){
11436
//writes data to the hdf5 file or group identified by obj_id of hdf5 datatype data_type
11537

src/io/hdf5functions_blosc.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,15 @@ extern "C" {
2121
#include <vector>
2222
#include <fstream>
2323

24-
std::string exec_blosc(const char* cmd);
2524

2625
void register_bosc();
2726
void hdf5_create_file_blosc(std::string file_name);
2827
void hdf5_load_data_blosc(hid_t obj_id,hid_t data_type,void* buff, const char* data_name);
2928
void hdf5_write_attribute_blosc(hid_t obj_id,hid_t type_id,const char* attr_name,hsize_t rank,hsize_t* dims, void* data );
30-
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 );
3129
void hdf5_write_string_blosc(hid_t obj_id,const char* attr_name,std::string output_str);
3230
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);
3331

3432
void write_main_paraview_xdmf_xml(std::string save_loc,std::string file_name,uint64_t num_parts);
3533

36-
template <typename T>
37-
hid_t get_type_blosc(T data_type){
38-
//
39-
// Return the type id
40-
//
41-
//
42-
43-
int num_byts = sizeof(data_type);
44-
45-
46-
if (num_byts == 0) {
47-
return H5T_NATIVE_INT;
48-
} else if(num_byts == 2){
49-
return H5T_NATIVE_UINT16;
50-
51-
} else if(num_byts == 1){
52-
return H5T_NATIVE_UINT8;
53-
} else {
54-
return H5T_NATIVE_FLOAT;
55-
}
56-
57-
58-
}
59-
6034

6135
#endif

0 commit comments

Comments
 (0)