MOAB: Mesh Oriented datABase  (version 5.2.1)
ReadHDF5VarLen.hpp
Go to the documentation of this file.
00001 /** \file   ReadHDF5VarLen.hpp
00002  *  \author Jason Kraftcheck
00003  *  \date   2010-09-04
00004  */
00005 
00006 #ifndef moab_READ_HDF5_VAR_LEN_HPP
00007 #define moab_READ_HDF5_VAR_LEN_HPP
00008 
00009 #include "moab/MOABConfig.h"
00010 #ifdef MOAB_HAVE_MPI
00011 #include "moab_mpi.h"
00012 #endif
00013 #include "DebugOutput.hpp"
00014 #include "moab/Range.hpp"
00015 #include "H5Ipublic.h"
00016 
00017 namespace moab
00018 {
00019 
00020 class ReadHDF5Dataset;
00021 
00022 /**\brief Read variable-length data from 1-D array dataset
00023  *
00024  * Utility class for reading variable-length data from an HDF5 dataset.
00025  * Used for reading set contents, set parents, set children,
00026  * polygon and polyhedron connectivity, and variable-length tag
00027  * data.
00028  *
00029  * This is an abstract class.  The pure virtual \c store_data method
00030  * must be implemented to create a concrete instance.
00031  */
00032 class ReadHDF5VarLen
00033 {
00034   protected:
00035     DebugOutput& dbgOut;
00036 
00037   private:
00038     void* const dataBuffer;
00039     const size_t bufferSize;
00040 
00041     /**\brief Test if passed file_id is value pointed to by ranged_iter,
00042      *        and if so, incremenet ranged_iter
00043      */
00044     static bool is_ranged( EntityHandle file_id, Range::const_iterator& ranged_iter, Range::const_iterator ranged_end );
00045 
00046   protected:
00047     /**\brief Store data list for a single entity
00048      *
00049      * The is the pure virtual method that must be provided.
00050      * It is responsible for storing the data read for a single
00051      * entity.
00052      *
00053      * This function will always be called in the order of the
00054      * file_ids in the range passed to the \c read method.
00055      *
00056      *\param file_id  The file ID for the entity
00057      *\param data     A pointer to the data for the entity
00058      *\param num_data Number of values for the entity
00059      *\param ranged   For set contents, true if in ranged format.
00060      */
00061     virtual ErrorCode store_data( EntityHandle file_id, void* data, long num_data, bool ranged ) = 0;
00062 
00063   public:
00064     /**\brief Constructor
00065      *\param buffer      A temporary buffer to use during read
00066      *\param buffer_size Size of \c buffer, in bytes.
00067      */
00068     ReadHDF5VarLen( DebugOutput& debug_output, void* buffer, size_t buffer_size )
00069         : dbgOut( debug_output ), dataBuffer( buffer ), bufferSize( buffer_size )
00070     {
00071     }
00072 
00073     virtual ~ReadHDF5VarLen() {}
00074 
00075     /**\brief Do actual read of data set
00076      *\param data_set         The data set to read.
00077      *\param file_ids         The file ids of the entities to read.
00078      *\param start_file_id    The file id corresponding to the first row of the dataset
00079      *\param data_type        The desired, in-memory data type for values
00080      *\param vals_per_ent     The number of values for each entity
00081      *\param ranged_file_ids  Those file ids for which the 'ranged'
00082      *                        argument to \c storedata should be passed
00083      *                        as \c true.
00084      */
00085     ErrorCode read_data( ReadHDF5Dataset& data_set, const Range& offsets, EntityHandle start_offset, hid_t data_type,
00086                          const Range& file_ids, const std::vector< unsigned >& vals_per_ent,
00087                          const Range& ranged_file_ids );
00088 
00089     /**\brief Read set description table or offset vector for
00090      *        var-len tags or old-format poly(gon|hedra) connectivity.
00091      *\param data_set         The data set to read.
00092      *\param file_ids         The file ids of the entities to read.
00093      *\param start_file_id    The file id corresponding to the first row of the dataset
00094      *\param num_columns      The number of columns of offsets in the dataset
00095      *\param indices          Array of length \c num_columns contaning the
00096      *                        indices of the columns to read.
00097      *\param nudge            Amount by which to offset values in
00098      *                        \c offset_out to avoid putting zeros in
00099      *                        Range.  Must be greater than 0.  Probably 1.
00100      *\param offsets_out      An array of length \c num_columns which will
00101      *                        be populated with the resulting list of offsets
00102      *                        into the contents list calculated from reading
00103      *                        the offsets from the passed data set.
00104      *\param counts_out       An array of length \c num_columns of std::vectors,
00105      *                        where each vector will be filled with one value
00106      *                        per file ID indicating the length of the data for
00107      *                        the corresponding file ID.
00108      *\param ranged_file_ids  If non-null, the last column of the table will
00109      *                        be read and tested for the ranged bit.  For
00110      *                        all file_ids for which the range bit is set,
00111      *                        the file ID will be added to this list.
00112      */
00113     /*
00114        ErrorCode read_offsets( ReadHDF5Dataset& data_set,
00115                                const Range& file_ids,
00116                                EntityHandle start_file_id,
00117                                unsigned num_columns,
00118                                const unsigned indices[],
00119                                EntityHandle nudge,
00120                                Range offsets_out[],
00121                                std::vector<unsigned> counts_out[],
00122                                Range* ranged_file_ids = 0 );
00123    */
00124     ErrorCode read_offsets( ReadHDF5Dataset& data_set, const Range& file_ids, EntityHandle start_file_id,
00125                             EntityHandle nudge, Range& offsets_out, std::vector< unsigned >& counts_out );
00126 
00127     ErrorCode read( ReadHDF5Dataset& offset_data, ReadHDF5Dataset& value_data, const Range& file_ids,
00128                     EntityHandle start_file_id, hid_t data_type, const Range* ranged = 0 )
00129     {
00130         ErrorCode rval;
00131         const EntityHandle nudge = 1;
00132         Range offsets;
00133         std::vector< unsigned > counts;
00134         rval = read_offsets( offset_data, file_ids, start_file_id, nudge, offsets, counts );
00135         if( MB_SUCCESS != rval ) return rval;
00136         Range empty;
00137         rval = read_data( value_data, offsets, nudge, data_type, file_ids, counts, ranged ? *ranged : empty );
00138         return rval;
00139     }
00140 };
00141 
00142 }  // namespace moab
00143 
00144 #endif  // moab_READ_HDF5_VAR_LEN_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines