23 #include "splash/core/SDCHelper.hpp" 25 #include "splash/version.hpp" 26 #include "splash/basetypes/basetypes.hpp" 27 #include "splash/core/DCAttribute.hpp" 28 #include "splash/core/logging.hpp" 35 std::string SDCHelper::getExceptionString(std::string msg)
37 return (std::string(
"Exception for [SDCHelper] ") + msg);
40 void SDCHelper::getReferenceData(
const char* filename, int32_t* maxID, Dimensions *mpiSize)
43 log_msg(1,
"loading reference data from %s", filename);
46 hid_t reference_file = H5Fopen(filename, H5F_ACC_RDONLY, H5P_FILE_ACCESS_DEFAULT);
47 if (reference_file < 0)
48 throw DCException(getExceptionString(std::string(
"Failed to open reference file ") +
49 std::string(filename)));
52 hid_t group_header = H5Gopen(reference_file, SDC_GROUP_HEADER, H5P_DEFAULT);
53 if (group_header < 0) {
54 H5Fclose(reference_file);
55 throw DCException(getExceptionString(
56 std::string(
"Failed to open header group in reference file ") +
57 std::string(filename)));
62 DCAttribute::readAttribute(SDC_ATTR_MAX_ID,
66 if (mpiSize != NULL) {
68 DCAttribute::readAttribute(SDC_ATTR_MPI_SIZE,
69 group_header, mpiSize->getPointer());
72 }
catch (
const DCException&) {
73 H5Fclose(reference_file);
74 throw DCException(getExceptionString(
75 std::string(
"Failed to read attributes from reference file ") +
76 std::string(filename)));
80 H5Gclose(group_header);
81 H5Fclose(reference_file);
84 void SDCHelper::writeHeader(hid_t file, Dimensions mpiPosition,
85 int32_t *maxID,
bool *enableCompression, Dimensions *mpiSize,
90 hid_t group_header = H5Gcreate(file, SDC_GROUP_HEADER, H5P_LINK_CREATE_DEFAULT,
91 H5P_GROUP_CREATE_DEFAULT, H5P_GROUP_ACCESS_DEFAULT);
93 throw DCException(getExceptionString(
"Failed to create header group in reference file"));
96 std::stringstream splashVersion;
97 splashVersion << SPLASH_VERSION_MAJOR <<
"." 98 << SPLASH_VERSION_MINOR <<
"." 99 << SPLASH_VERSION_PATCH;
100 std::stringstream splashFormat;
101 splashFormat << SPLASH_FILE_FORMAT_MAJOR <<
"." 102 << SPLASH_FILE_FORMAT_MINOR;
104 ColTypeInt32 ctInt32;
107 ColTypeString ctStringVersion(splashVersion.str().length());
108 ColTypeString ctStringFormat(splashFormat.str().length());
112 DCAttribute::writeAttribute(SDC_ATTR_MAX_ID, ctInt32.getDataType(),
113 group_header, maxID);
115 DCAttribute::writeAttribute(SDC_ATTR_MPI_POSITION, dim_t.getDataType(),
116 group_header, mpiPosition.getPointer());
119 DCAttribute::writeAttribute(SDC_ATTR_COMPRESSION, ctBool.getDataType(),
120 group_header, enableCompression);
122 DCAttribute::writeAttribute(SDC_ATTR_MPI_SIZE, dim_t.getDataType(),
123 group_header, mpiSize->getPointer());
125 DCAttribute::writeAttribute(SDC_ATTR_VERSION, ctStringVersion.getDataType(),
126 group_header, splashVersion.str().c_str());
128 DCAttribute::writeAttribute(SDC_ATTR_FORMAT, ctStringFormat.getDataType(),
129 group_header, splashFormat.str().c_str());
131 }
catch (
const DCException& attr_error) {
132 throw DCException(getExceptionString(
133 std::string(
"Failed to write header attribute in reference file. Error was: ") +
134 std::string(attr_error.what())));
137 H5Gclose(group_header);
EXTERN void log_msg(int level, const char *fmt,...)