Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
ReadHDF5VarLen.hpp
Go to the documentation of this file.
1 /** \file ReadHDF5VarLen.hpp
2  * \author Jason Kraftcheck
3  * \date 2010-09-04
4  */
5 
6 #ifndef moab_READ_HDF5_VAR_LEN_HPP
7 #define moab_READ_HDF5_VAR_LEN_HPP
8 
9 #include "moab/MOABConfig.h"
10 #ifdef MOAB_HAVE_MPI
11 #include "moab_mpi.h"
12 #endif
13 #include "DebugOutput.hpp"
14 #include "moab/Range.hpp"
15 #include "H5Ipublic.h"
16 
17 namespace moab
18 {
19 
20 class ReadHDF5Dataset;
21 
22 /**\brief Read variable-length data from 1-D array dataset
23  *
24  * Utility class for reading variable-length data from an HDF5 dataset.
25  * Used for reading set contents, set parents, set children,
26  * polygon and polyhedron connectivity, and variable-length tag
27  * data.
28  *
29  * This is an abstract class. The pure virtual \c store_data method
30  * must be implemented to create a concrete instance.
31  */
33 {
34  protected:
36 
37  private:
38  void* const dataBuffer;
39  const size_t bufferSize;
40 
41  /**\brief Test if passed file_id is value pointed to by ranged_iter,
42  * and if so, incremenet ranged_iter
43  */
44  static bool is_ranged( EntityHandle file_id, Range::const_iterator& ranged_iter, Range::const_iterator ranged_end );
45 
46  protected:
47  /**\brief Store data list for a single entity
48  *
49  * The is the pure virtual method that must be provided.
50  * It is responsible for storing the data read for a single
51  * entity.
52  *
53  * This function will always be called in the order of the
54  * file_ids in the range passed to the \c read method.
55  *
56  *\param file_id The file ID for the entity
57  *\param data A pointer to the data for the entity
58  *\param num_data Number of values for the entity
59  *\param ranged For set contents, true if in ranged format.
60  */
61  virtual ErrorCode store_data( EntityHandle file_id, void* data, long num_data, bool ranged ) = 0;
62 
63  public:
64  /**\brief Constructor
65  *\param buffer A temporary buffer to use during read
66  *\param buffer_size Size of \c buffer, in bytes.
67  */
68  ReadHDF5VarLen( DebugOutput& debug_output, void* buffer, size_t buffer_size )
69  : dbgOut( debug_output ), dataBuffer( buffer ), bufferSize( buffer_size )
70  {
71  }
72 
73  virtual ~ReadHDF5VarLen() {}
74 
75  /**\brief Do actual read of data set
76  *\param data_set The data set to read.
77  *\param file_ids The file ids of the entities to read.
78  *\param start_file_id The file id corresponding to the first row of the dataset
79  *\param data_type The desired, in-memory data type for values
80  *\param vals_per_ent The number of values for each entity
81  *\param ranged_file_ids Those file ids for which the 'ranged'
82  * argument to \c storedata should be passed
83  * as \c true.
84  */
86  const Range& offsets,
87  EntityHandle start_offset,
88  hid_t data_type,
89  const Range& file_ids,
90  const std::vector< unsigned >& vals_per_ent,
91  const Range& ranged_file_ids );
92 
93  /**\brief Read set description table or offset vector for
94  * var-len tags or old-format poly(gon|hedra) connectivity.
95  *\param data_set The data set to read.
96  *\param file_ids The file ids of the entities to read.
97  *\param start_file_id The file id corresponding to the first row of the dataset
98  *\param num_columns The number of columns of offsets in the dataset
99  *\param indices Array of length \c num_columns contaning the
100  * indices of the columns to read.
101  *\param nudge Amount by which to offset values in
102  * \c offset_out to avoid putting zeros in
103  * Range. Must be greater than 0. Probably 1.
104  *\param offsets_out An array of length \c num_columns which will
105  * be populated with the resulting list of offsets
106  * into the contents list calculated from reading
107  * the offsets from the passed data set.
108  *\param counts_out An array of length \c num_columns of std::vectors,
109  * where each vector will be filled with one value
110  * per file ID indicating the length of the data for
111  * the corresponding file ID.
112  *\param ranged_file_ids If non-null, the last column of the table will
113  * be read and tested for the ranged bit. For
114  * all file_ids for which the range bit is set,
115  * the file ID will be added to this list.
116  */
117  /*
118  ErrorCode read_offsets( ReadHDF5Dataset& data_set,
119  const Range& file_ids,
120  EntityHandle start_file_id,
121  unsigned num_columns,
122  const unsigned indices[],
123  EntityHandle nudge,
124  Range offsets_out[],
125  std::vector<unsigned> counts_out[],
126  Range* ranged_file_ids = 0 );
127  */
129  const Range& file_ids,
130  EntityHandle start_file_id,
131  EntityHandle nudge,
132  Range& offsets_out,
133  std::vector< unsigned >& counts_out );
134 
136  ReadHDF5Dataset& value_data,
137  const Range& file_ids,
138  EntityHandle start_file_id,
139  hid_t data_type,
140  const Range* ranged = 0 )
141  {
142  ErrorCode rval;
143  const EntityHandle nudge = 1;
144  Range offsets;
145  std::vector< unsigned > counts;
146  rval = read_offsets( offset_data, file_ids, start_file_id, nudge, offsets, counts );
147  if( MB_SUCCESS != rval ) return rval;
148  Range empty;
149  rval = read_data( value_data, offsets, nudge, data_type, file_ids, counts, ranged ? *ranged : empty );
150  return rval;
151  }
152 };
153 
154 } // namespace moab
155 
156 #endif // moab_READ_HDF5_VAR_LEN_HPP