AbstractHdf5Access.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "Exception.hpp"
00037 #include "AbstractHdf5Access.hpp"
00038
00039 bool AbstractHdf5Access::DoesDatasetExist(const std::string& rDatasetName)
00040 {
00041 #if H5_VERS_MAJOR>=1 && H5_VERS_MINOR>=8
00042
00043 htri_t dataset_status = H5Lexists(mFileId, rDatasetName.c_str(), H5P_DEFAULT);
00044 return (dataset_status>0);
00045 #else
00046 bool result=false;
00047
00048
00049 H5E_BEGIN_TRY
00050 {
00051 hid_t dataset_id = H5Dopen(mFileId, rDatasetName.c_str());
00052 if (dataset_id>0)
00053 {
00054 H5Dclose(dataset_id);
00055 result = true;
00056 }
00057 }
00058 H5E_END_TRY;
00059
00060 return result;
00061 #endif
00062 }
00063
00064 void AbstractHdf5Access::SetUnlimitedDatasetId()
00065 {
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 if (DoesDatasetExist(mDatasetName + "_Unlimited"))
00079 {
00080 mUnlimitedDatasetId = H5Dopen(mFileId, (mDatasetName + "_Unlimited").c_str());
00081 hid_t name_attribute_id = H5Aopen_name(mUnlimitedDatasetId, "Name");
00082 hid_t unit_attribute_id = H5Aopen_name(mUnlimitedDatasetId, "Unit");
00083
00084 hid_t attribute_type = H5Aget_type(name_attribute_id);
00085
00086
00087 char* string_array = (char *)malloc(sizeof(char)*MAX_STRING_SIZE);
00088 H5Aread( name_attribute_id, attribute_type, string_array);
00089 std::string name_string(&string_array[0]);
00090 mUnlimitedDimensionName = name_string;
00091
00092 H5Aread( unit_attribute_id, attribute_type, string_array);
00093 std::string unit_string(&string_array[0]);
00094 mUnlimitedDimensionUnit = unit_string;
00095
00096 free(string_array);
00097 H5Tclose(attribute_type);
00098 H5Aclose(name_attribute_id);
00099 H5Aclose(unit_attribute_id);
00100 }
00101 else if (DoesDatasetExist("Time"))
00102 {
00103 mUnlimitedDimensionName = "Time";
00104 mUnlimitedDimensionUnit = "msec";
00105 mUnlimitedDatasetId = H5Dopen(mFileId, mUnlimitedDimensionName.c_str());
00106 }
00107 else
00108 {
00109 NEVER_REACHED;
00110 }
00111 mIsUnlimitedDimensionSet = true;
00112 }
00113
00114 AbstractHdf5Access::AbstractHdf5Access(const std::string& rDirectory,
00115 const std::string& rBaseName,
00116 const std::string& rDatasetName,
00117 bool makeAbsolute)
00118 : mBaseName(rBaseName),
00119 mDatasetName(rDatasetName),
00120 mIsDataComplete(true),
00121 mIsUnlimitedDimensionSet(false)
00122 {
00123 RelativeTo::Value relative_to;
00124 if (makeAbsolute)
00125 {
00126 relative_to = RelativeTo::ChasteTestOutput;
00127 }
00128 else
00129 {
00130 relative_to = RelativeTo::Absolute;
00131 }
00132 mDirectory.SetPath(rDirectory, relative_to);
00133 }
00134
00135 AbstractHdf5Access::AbstractHdf5Access(const FileFinder& rDirectory,
00136 const std::string& rBaseName,
00137 const std::string& rDatasetName)
00138 : mBaseName(rBaseName),
00139 mDatasetName(rDatasetName),
00140 mDirectory(rDirectory),
00141 mIsDataComplete(true),
00142 mIsUnlimitedDimensionSet(false)
00143 {
00144 }
00145
00146 AbstractHdf5Access::~AbstractHdf5Access()
00147 {
00148 }
00149
00150
00151 bool AbstractHdf5Access::IsDataComplete()
00152 {
00153 return mIsDataComplete;
00154 }
00155
00156
00157 std::vector<unsigned> AbstractHdf5Access::GetIncompleteNodeMap()
00158 {
00159 return mIncompleteNodeIndices;
00160 }
00161
00162 std::string AbstractHdf5Access::GetUnlimitedDimensionName()
00163 {
00164 return mUnlimitedDimensionName;
00165 }
00166
00167 std::string AbstractHdf5Access::GetUnlimitedDimensionUnit()
00168 {
00169 return mUnlimitedDimensionUnit;
00170 }
00171
00172 void AbstractHdf5Access::SetMainDatasetRawChunkCache()
00173 {
00174
00175
00176
00177
00178
00179 hsize_t max_objects_in_chunk_cache = 12799u;
00180 hsize_t max_bytes_in_cache = 128u*1024u*1024u;
00181 #if H5_VERS_MAJOR>=1 && H5_VERS_MINOR>=8 && H5_VERS_RELEASE>=3 // HDF5 1.8.3+
00182
00183 hid_t dapl_id = H5Dget_access_plist( mVariablesDatasetId );
00184 H5Pset_chunk_cache( dapl_id,
00185 max_objects_in_chunk_cache ,
00186 max_bytes_in_cache ,
00187 H5D_CHUNK_CACHE_W0_DEFAULT);
00188 #else
00189
00190 hid_t fapl_id = H5Fget_access_plist( mFileId );
00191 H5Pset_cache( fapl_id,
00192 0,
00193 max_objects_in_chunk_cache,
00194 max_bytes_in_cache,
00195 0.75);
00196 #endif
00197 }
00198
00199