moab
ReadHDF5Dataset.hpp
Go to the documentation of this file.
00001 
00006 #ifndef moab_READ_HDF5DATASET_HPP
00007 #define moab_READ_HDF5DATASET_HPP
00008 
00009 #ifdef USE_MPI
00010 # include <moab_mpi.h>
00011 #endif
00012 
00013 #include <stdlib.h> // for size_t
00014 #include <H5Ipublic.h>
00015 #include <H5Spublic.h>
00016 
00017 #include "moab/Range.hpp"
00018 #include <vector>
00019 
00020 namespace moab {
00021 
00036 class ReadHDF5Dataset 
00037 {
00038 public:
00039 
00040 #ifdef USE_MPI
00041   typedef MPI_Comm Comm;
00042 #else
00043   typedef int Comm;
00044 #endif
00045 
00046   class Exception { public: int line_no; Exception(int l) : line_no(l) {} };
00047   
00066   ReadHDF5Dataset( const char* debug_desc,
00067                    hid_t data_set_handle,
00068                    bool parallel,
00069                    const Comm* communicator = 0,
00070                    bool close_data_set_on_destruct = true );
00071   
00072   ReadHDF5Dataset( const char* debug_desc,
00073                    bool parallel,
00074                    const Comm* communicator = 0 );
00075   void init( hid_t data_set_handle, bool close_data_set_on_destruct = true );
00076   
00077   bool will_close_data_set() const { return closeDataSet; }
00078   void close_data_set_on_destruct( bool val ) { closeDataSet = val; }
00079   
00080   ~ReadHDF5Dataset();
00081   
00082   
00093   void set_file_ids( const Range& file_ids, 
00094                      EntityHandle start_id,
00095                      hsize_t row_cout,
00096                      hid_t data_type );
00097   
00104   void set_all_file_ids( hsize_t row_count, hid_t data_type );
00105   
00110   bool done() const { return (currOffset == rangeEnd) && (readCount == 0); }
00111   
00119   void read( void* buffer, size_t& rows_read );
00120   
00123   Range::const_iterator next_file_id() const { return currOffset; }
00124   
00133   void null_read();
00134   
00135   unsigned columns() const;
00136   void set_column( unsigned c );
00137   
00138   unsigned long get_read_count() const { return readCount; }
00139   const char* get_debug_desc() const { return mpeDesc.c_str(); }
00140 
00141   static void set_hyperslab_selection_limit( size_t val )
00142     { hyperslabSelectionLimit = val; }
00143   static void default_hyperslab_selection_limit();
00144 
00146   static void append_hyperslabs() { hyperslabSelectOp = H5S_SELECT_APPEND; }
00148   static void or_hyperslabs() { hyperslabSelectOp = H5S_SELECT_OR; }
00149 private:
00150 
00151   Range::const_iterator next_end( Range::const_iterator iter );
00152 
00153   Range internalRange; 
00154 
00155   bool closeDataSet; 
00156   hsize_t dataSetOffset[64], dataSetCount[64];
00157   hid_t dataSet;       
00158   hid_t dataSpace;     
00159   hid_t dataType;      
00160   hid_t fileType;      
00161   hid_t ioProp;        
00162   int dataSpaceRank;   
00163   hsize_t rowsInTable; 
00164   bool doConversion;   
00165   bool nativeParallel; 
00166   
00167   hsize_t readCount;  
00168   hsize_t bufferSize; 
00169   const Comm* mpiComm;
00170   
00171   Range::const_iterator currOffset, rangeEnd;
00172   EntityHandle startID;
00173   
00174   static bool haveMPEEvents;
00175   static std::pair<int,int> mpeReadEvent;
00176   static std::pair<int,int> mpeReduceEvent;
00177   std::string mpeDesc;
00178   
00179   static size_t hyperslabSelectionLimit;
00180   static H5S_seloper_t hyperslabSelectOp;
00181 }; 
00182 
00183 
00184 
00185 } // namespace moab
00186 
00187 #endif // moab_READ_HDF5DATASET_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines