void ReadStringsT( hid_t iParent, const std::string &iAttrName, size_t iNumStrings, StringT *oStrings ) { ABCA_ASSERT( iParent >= 0, "Invalid parent in ReadStringsT" ); // Open the attribute. hid_t attrId = H5Aopen( iParent, iAttrName.c_str(), H5P_DEFAULT ); ABCA_ASSERT( attrId >= 0, "Couldn't open attribute named: " << iAttrName ); AttrCloser attrCloser( attrId ); // Checking code. { hid_t attrFtype = H5Aget_type( attrId ); DtypeCloser dtypeCloser( attrFtype ); hid_t nativeDtype = GetNativeDtype<CharT>(); ABCA_ASSERT( H5Tget_class( attrFtype ) == H5Tget_class( nativeDtype ) && H5Tget_sign( attrFtype ) == H5Tget_sign( nativeDtype ), "Invalid datatype for stringT" ); } hid_t attrSpace = H5Aget_space( attrId ); ABCA_ASSERT( attrSpace >= 0, "Couldn't get dataspace for attribute: " << iAttrName ); DspaceCloser dspaceCloser( attrSpace ); hssize_t numPoints = H5Sget_simple_extent_npoints( attrSpace ); ABCA_ASSERT( numPoints > 0, "Degenerate string dimensions in ReadStringsT" ); // Create temporary char storage buffer. std::vector<CharT> charStorage( ( size_t )( 1 + numPoints ), ( CharT )0 ); // Read into it. herr_t status = H5Aread( attrId, GetNativeDtype<CharT>(), ( void * )&charStorage.front() ); ABCA_ASSERT( status >= 0, "Couldn't read from attribute: " << iAttrName ); // Extract 'em. ExtractStrings( oStrings, ( const CharT * )&charStorage.front(), 1 + numPoints, iNumStrings ); }
//-***************************************************************************** void ReadTimeSamples( hid_t iParent, std::vector < AbcA::TimeSamplingPtr > & oTimeSamples ) { oTimeSamples.clear(); // add the intrinsic default sampling AbcA::TimeSamplingPtr ts( new AbcA::TimeSampling() ); oTimeSamples.push_back( ts ); uint32_t i = 1; AbcA::TimeSamplingType tst; std::string tstname = "1"; // keep trying to read till we can't find anymore while ( ReadTimeSamplingType( iParent, tstname, tst ) ) { // try to open the time samples attribute std::string timeName = tstname + ".time"; hid_t aid = H5Aopen( iParent, timeName.c_str(), H5P_DEFAULT ); ABCA_ASSERT( aid >= 0, "Couldn't open time samples named: " << timeName ); AttrCloser attrCloser( aid ); // figure out how big it is hid_t sid = H5Aget_space( aid ); ABCA_ASSERT( sid >= 0, "Couldn't get dataspace for time samples: " << timeName ); DspaceCloser dspaceCloser( sid ); hssize_t numPoints = H5Sget_simple_extent_npoints( sid ); ABCA_ASSERT( numPoints > 0, "No time samples data: " << timeName ); std::vector < chrono_t > times(numPoints); // do the read herr_t status = H5Aread( aid, H5T_NATIVE_DOUBLE, &(times.front()) ); ABCA_ASSERT( status >= 0, "Can't read time samples: " << timeName ); // create the TimeSampling and add it to our vector ts.reset( new AbcA::TimeSampling(tst, times) ); oTimeSamples.push_back( ts ); // increment to try and read the next one i++; std::stringstream strm; strm << i; tstname = strm.str(); } }
//-***************************************************************************** void WriteDataToAttr( hid_t iParent, hid_t iDspace, const std::string &iAttrName, hid_t iFileType, hid_t iNativeType, const void *iData ) { hid_t attrId = H5Acreate2( iParent, iAttrName.c_str(), iFileType, iDspace, H5P_DEFAULT, H5P_DEFAULT ); AttrCloser attrCloser( attrId ); herr_t status = H5Awrite( attrId, iNativeType, iData ); ABCA_ASSERT( status >= 0, "Couldn't write attribute: " << iAttrName ); }
void ReadStringT<std::string,char>( hid_t iParent, const std::string &iAttrName, std::string &oString ) { ABCA_ASSERT( iParent >= 0, "Invalid parent in ReadStringT" ); // Open the attribute. hid_t attrId = H5Aopen( iParent, iAttrName.c_str(), H5P_DEFAULT ); ABCA_ASSERT( attrId >= 0, "Couldn't open attribute named: " << iAttrName ); AttrCloser attrCloser( attrId ); // Checking code. hid_t attrFtype = H5Aget_type( attrId ); DtypeCloser dtypeCloser( attrFtype ); ssize_t numChars = H5Tget_size( attrFtype ); ABCA_ASSERT( numChars >= 0, "ReadStringT() H5Aget_size() failed" ); // Read and check space { hid_t attrSpace = H5Aget_space( attrId ); ABCA_ASSERT( attrSpace >= 0, "Couldn't get dataspace for attribute: " << iAttrName ); DspaceCloser dspaceCloser( attrSpace ); H5S_class_t attrSpaceClass = H5Sget_simple_extent_type( attrSpace ); ABCA_ASSERT( attrSpaceClass == H5S_SCALAR, "Tried to read non-scalar attribute: " << iAttrName << " as scalar" ); } // Create temporary char storage buffer. std::vector<char> charStorage( ( size_t )( 1 + numChars ), ( char )0 ); // Read into it. herr_t status = H5Aread( attrId, attrFtype, ( void * )&charStorage.front() ); ABCA_ASSERT( status >= 0, "Couldn't read from attribute: " << iAttrName ); // Return it. oString = ( const char * )&charStorage.front(); }
//-***************************************************************************** ArImpl::ArImpl( const std::string &iFileName, AbcA::ReadArraySampleCachePtr iCache, const bool iCacheHierarchy ) : m_fileName( iFileName ) , m_file( -1 ) , m_readArraySampleCache( iCache ) { // OPEN THE FILE! htri_t exi = H5Fis_hdf5( m_fileName.c_str() ); ABCA_ASSERT( exi == 1, "Nonexistent or not an Alembic file: " << m_fileName ); m_file = H5Fopen( m_fileName.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT ); ABCA_ASSERT( m_file >= 0, "Could not open file: " << m_fileName ); // get the version using HDF5 native calls int version = -INT_MAX; if (H5Aexists(m_file, "abc_version")) { size_t numRead = 0; ReadSmallArray(m_file, "abc_version", H5T_STD_I32LE, H5T_NATIVE_INT32, 1, numRead, &version); } ABCA_ASSERT(version >= -8 && version <= ALEMBIC_HDF5_FILE_VERSION, "Unsupported file version detected: " << version); // if it isn't there, it's pre 1.0 int fileVersion = 9999; if (H5Aexists( m_file, "abc_release_version" )) { size_t numRead = 0; ReadSmallArray( m_file, "abc_release_version", H5T_STD_I32LE, H5T_NATIVE_INT32, 1, numRead, &fileVersion ); } m_archiveVersion = fileVersion; HDF5HierarchyReader reader( m_file, m_H5H, iCacheHierarchy ); H5Node node = m_H5H.createNode( m_file ); H5Node abcRoot = OpenGroup( node, "ABC" ); AbcA::MetaData metaData; ReadMetaData( abcRoot, ".prop.meta", metaData ); m_header.reset( new AbcA::ObjectHeader( "ABC", "/", metaData ) ); m_data.reset( new OrData( m_header, node, m_archiveVersion ) ); CloseObject( abcRoot ); ReadTimeSamples( m_file, m_timeSamples ); if ( H5Aexists( m_file, "abc_max_samples" ) ) { hid_t aid = H5Aopen( m_file, "abc_max_samples", H5P_DEFAULT ); if ( aid < 0 ) { return; } AttrCloser attrCloser( aid ); // figure out how big it is hid_t sid = H5Aget_space( aid ); if ( sid < 0 ) { return; } DspaceCloser dspaceCloser( sid ); hssize_t numPoints = H5Sget_simple_extent_npoints( sid ); if ( numPoints < 1 ) { return; } m_maxSamples.resize( numPoints ); // do the read H5Aread( aid, H5T_NATIVE_LLONG, &( m_maxSamples.front() ) ); } }