File indexing completed on 2024-04-06 12:01:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "h5_Attribute.h"
0017 #include "FWCore/Utilities/interface/Exception.h"
0018
0019
0020
0021
0022
0023 namespace cms::h5 {
0024
0025
0026
0027
0028
0029
0030
0031 Attribute::Attribute(hid_t iParentID, std::string const& iName)
0032 : id_(H5Aopen(iParentID, iName.c_str(), H5P_DEFAULT)) {
0033 if (id_ < 1) {
0034 throw cms::Exception("UnknownH5Attribute") << "unknown attribute " << iName;
0035 }
0036 }
0037
0038
0039
0040
0041
0042
0043 Attribute::~Attribute() { H5Aclose(id_); }
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064 std::string Attribute::readString() const {
0065
0066 char* strg_C;
0067
0068 hid_t attr_type = H5Tcopy(H5T_C_S1);
0069 (void)H5Tset_size(attr_type, H5T_VARIABLE);
0070
0071
0072 herr_t ret_value = H5Aread(id_, attr_type, &strg_C);
0073 H5Tclose(attr_type);
0074
0075 if (ret_value < 0) {
0076 throw cms::Exception("H5AttributeReadStrinFailed") << " failed to read string from attribute";
0077 }
0078
0079
0080 std::string strg = strg_C;
0081 free(strg_C);
0082
0083 return strg;
0084 }
0085
0086 uint32_t Attribute::readUInt32() const {
0087 unsigned int ret;
0088
0089 herr_t ret_value = H5Aread(id_, H5T_NATIVE_UINT, &ret);
0090
0091 if (ret_value < 0) {
0092 throw cms::Exception("H5AttributeReadStrinFailed") << " failed to read unsigned int from attribute";
0093 }
0094 return ret;
0095 }
0096
0097
0098
0099
0100 }