H5::DataSet CompartmentReportHDF5::_openDataset( const H5::H5File& file, const uint32_t cellID ) { std::stringstream cellName; cellName << "a" << cellID; const std::string datasetName = "/" + cellName.str() + "/" + _reportName + "/" + dataDatasetName; H5::DataSet dataset; H5E_BEGIN_TRY dataset = file.openDataSet( datasetName ); H5E_END_TRY if( !dataset.getId() ) { LBTHROW( std::runtime_error( "ReportReaderHDF5: " "Dataset " + datasetName + " not found " "in file: " + file.getFileName( ))); } if( dataset.getSpace().getSimpleExtentNdims() != 2 ) { LBTHROW( std::runtime_error("Compartment_Report_HDF5_File_Reader: " "Error, not 2 dimensional array on " + datasetName)); } return dataset; }
H5RandomReader::H5RandomReader(const std::string fileName, const std::string groupPath) throw (InvalidFileException) { try { file.openFile(fileName, H5F_ACC_RDONLY);} catch ( H5::FileIException ) { throw InvalidFileException("Cannot acces file");} try { group = file.openGroup(groupPath);} catch ( H5::GroupIException ) { file.close(); throw InvalidFileException("Cannot access group");} /* * extract timeline. This is also necessary to get the nbSteps. */ try { timeline = group.openDataSet("timeline"); nSteps = timeline.getSpace().getSimpleExtentNpoints();} catch ( H5::DataSetIException error ) { //error.printError(); group.close(); file.close(); throw InvalidFileException("Cannot access timeline dataset");} if (logging::info) std::cerr << "Opened group \"" << fileName << groupPath << "\" which has " << nSteps << " steps.\n"; /* * extract objects names in the xpGroup */ std::vector<std::string> names; H5Literate(group.getId(), H5_INDEX_NAME, H5_ITER_INC, NULL, iterInGroup, &names); /* * extract data from object in xpGroup * these data can be of 3 types: matrix, translate or wrench * each data are saved in related map */ for (unsigned int i=0; i<names.size(); i++){ //TODO: skip timeline H5::DataSet dSet = group.openDataSet(names[i]); if (H5Aexists(dSet.getId(), "ArborisViewerType")) { H5::Attribute att = dSet.openAttribute("ArborisViewerType"); std::string type; att.read(att.getDataType(), type); if (type == "matrix"){ H5::DataSpace dSpace = dSet.getSpace(); bool dimension_ok = false; if (dSpace.getSimpleExtentNdims()==3) { hsize_t dims[3]; dSpace.getSimpleExtentDims (dims); if (dims[0] == nSteps && dims[1] == 4 && dims[2] == 4) dimension_ok = true;} if (dimension_ok) matrices[names[i]] = dSet; else { if (logging::warning) std::cerr << "Skipping dataset \"" << names[i] << "\" which has wrong dimensions. I was expecting (" << nSteps << ",4,4).\n"; dSet.close();}} else if (type == "translate"){ H5::DataSpace dSpace = dSet.getSpace(); bool dimension_ok = false; if (dSpace.getSimpleExtentNdims()==2) { hsize_t dims[2]; dSpace.getSimpleExtentDims (dims); if (dims[0] == nSteps && dims[1] == 3) dimension_ok = true;} if (dimension_ok) translates[names[i]] = dSet; else { if (logging::warning) std::cerr << "Skipping dataset \"" << names[i] << "\" which has wrong dimensions. I was expecting (" << nSteps << ",3).\n"; dSet.close();}} else if (type == "wrench") { H5::DataSpace dSpace = dSet.getSpace(); bool dimension_ok = false; if (dSpace.getSimpleExtentNdims()==2) { hsize_t dims[2]; dSpace.getSimpleExtentDims (dims); if (dims[0] == nSteps && dims[1] == 6) dimension_ok = true;} if (dimension_ok) wrenches[names[i]] = dSet; else { if (logging::warning) std::cerr << "Skipping dataset \"" << names[i] << "\" which as wrong dimensions. I was expecting (" << nSteps << ",6).\n"; dSet.close();}} else { if (logging::warning) std::cerr << "Skipping dataset \"" << names[i] << "\" whose ArborisViewerType attribute as unknown value \"" << type << "\".\n"; dSet.close();} att.close(); } else { if (logging::info) std::cerr << "Skipping dataset \"" << names[i] << "\" which has no ArborisViewerType attribute.\n"; dSet.close(); } } };
void ossim_hdf5::printObject( H5::H5File* file, const std::string& objectName, const std::string& prefix, std::ostream& out ) { #if 0 std::cout << "printObject entered..." << "\nobjectName: " << objectName << "\nprefix: " << prefix << std::endl; #endif H5::DataSet dataset = file->openDataSet( objectName ); // Get the class of the datatype that is used by the dataset. H5T_class_t type_class = dataset.getTypeClass(); out << prefix << ".class_type: " << ossim_hdf5::getDatatypeClassType( type_class ) << std::endl; const ossim_uint32 ATTRS_COUNT = dataset.getNumAttrs(); for ( ossim_uint32 aIdx = 0; aIdx < ATTRS_COUNT; ++aIdx ) { H5::Attribute attr = dataset.openAttribute( aIdx ); ossim_hdf5::printAttribute( attr, prefix, out ); attr.close(); } // Extents: std::vector<ossim_uint32> extents; ossim_hdf5::getExtents( &dataset, extents ); for ( ossim_uint32 i = 0; i < extents.size(); ++i ) { ossimString os; std::string exStr = ".extent"; exStr += os.toString(i).string(); out << prefix << exStr << ": " << extents[i] << std::endl; } // ossimScalarType scalar = getScalarType( type_class, dataset.getId() ); ossimScalarType scalar = ossim_hdf5::getScalarType( dataset.getId() ); if ( scalar != OSSIM_SCALAR_UNKNOWN) { out << prefix << "." << ossimKeywordNames::SCALAR_TYPE_KW << ": " << ossimScalarTypeLut::instance()->getEntryString( scalar ) << std::endl; if ( ossim::scalarSizeInBytes( scalar ) > 1 ) { ossimByteOrder byteOrder = ossim_hdf5::getByteOrder( &dataset ); std::string byteOrderString = "little_endian"; if ( byteOrder == OSSIM_BIG_ENDIAN ) { byteOrderString = "big_endian"; } out << prefix << "." <<ossimKeywordNames::BYTE_ORDER_KW << ": " << byteOrderString << std::endl; } } #if 0 // Attributes: int numberOfAttrs = dataset.getNumAttrs(); cout << "numberOfAttrs: " << numberOfAttrs << endl; for ( ossim_int32 attrIdx = 0; attrIdx < numberOfAttrs; ++attrIdx ) { H5::Attribute attribute = dataset.openAttribute( attrIdx ); cout << "attribute.from class: " << attribute.fromClass() << endl; } #endif dataset.close(); } // End: printObject