VAPoR  0.1
VDFIOBase.h
Go to the documentation of this file.
1 //
2 // $Id$
3 //
4 
5 
6 #ifndef _VDFIOBase_h_
7 #define _VDFIOBase_h_
8 
9 #include <cstdio>
10 #include <vapor/MyBase.h>
11 #include <vapor/MetadataVDC.h>
12 #include <vapor/CFuncs.h>
13 
14 namespace VAPoR {
15 
16 
17 //
26 //
27 class VDF_API VDFIOBase : public MetadataVDC {
28 
29 public:
30 
38  //
39  VDFIOBase(
40  const MetadataVDC &metadata
41  );
42 
50  //
51  VDFIOBase(
52  const string &metafile
53  );
54 
55  virtual ~VDFIOBase();
56 
62  double GetReadTimer() const { return(_read_timer_acc); };
63 
69  double GetSeekTimer() const { return(_seek_timer_acc); };
70  void SeekTimerReset() {_seek_timer_acc = 0;};
71  void SeekTimerStart() {_seek_timer = VetsUtil::GetTime();};
72  void SeekTimerStop() {_seek_timer_acc += (VetsUtil::GetTime() - _seek_timer);};
73 
79  double GetWriteTimer() const { return(_write_timer_acc); };
80 
86  double GetXFormTimer() const { return(_xform_timer_acc); };
87 
88  virtual int OpenVariableRead(
89  size_t timestep, const char *varname, int reflevel=0, int lod=0
90  ) {_varname = varname; return(0); };
91 
92  virtual int BlockReadRegion(
93  const size_t bmin[3], const size_t bmax[3], float *region, bool unblock=true
94  ) = 0;
95 
96  virtual int ReadRegion(
97  const size_t min[3], const size_t max[3], float *region
98  ) = 0;
99 
100  virtual int ReadRegion(float *region) = 0;
101 
102  virtual int ReadSlice(float *slice) = 0;
103 
104  virtual int OpenVariableWrite(
105  size_t timestep, const char *varname, int reflevel=0, int lod=0
106  ) {_varname = varname; return(0); };
107 
108  virtual int BlockWriteRegion(
109  const float *region, const size_t bmin[3], const size_t bmax[3],
110  bool block=true
111  ) = 0;
112 
113  virtual int WriteRegion(
114  const float *region, const size_t min[3], const size_t max[3]
115  ) = 0;
116 
117  virtual int WriteRegion(const float *region) = 0;
118 
119  virtual int WriteSlice(const float *slice) = 0;
120 
121  virtual int CloseVariable() {_varname.clear(); return(0);};
122 
123  virtual const float *GetDataRange() const = 0;
124 
125 protected:
126 
127  //
128  // A Bit Mask class for supporting missing data
129  //
130  class BitMask {
131  public:
132  //
133  // nbits is the number of elements to be stored in the mask
134  //
135  BitMask();
136  BitMask(size_t nbits);
137  BitMask(const BitMask &bm); // copy constructor
138  ~BitMask();
139 
140  //
141  // Resize the bit mask to accomodate 'nbit' items. All previous data
142  // is lost
143  //
144  void resize(size_t nbits);
145 
146  //
147  // returns the size, in bytes, of internal storage needed to support
148  // a bit map of 'nbits' elements
149  //
150  static size_t getSize(size_t nbits) {return ((nbits+7) >> 3);}
151 
152  void clear();
153 
154  //
155  // returns the current size of the bit mask
156  //
157  size_t size() const {return (_nbits); };
158 
159  //
160  // Set or unset the value of the bit mask at location 'idx', where
161  // 0 < idx < nbits-1
162  //
163  void setBit(size_t idx, bool value);
164 
165  //
166  // Get the value of the bit mask at location 'idx', where
167  // 0 < idx < nbits-1
168  //
169  bool getBit(size_t idx) const;
170 
171  //
172  // Return pointer to the internal storage for a bit mask. The length
173  // of the array returned is getSize(nbits) bytes
174  //
175  unsigned char *getStorage() const;
176  BitMask &operator=(const BitMask &bm);
177 
178  private:
179  unsigned char *_bitmask; // storage for bitmask
180  size_t _bitmask_sz; // size of _bitmask buffer in bytes
181  size_t _nbits;
182 
183  void _BitMask(size_t nbits);
184  };
185 
186  void _ReadTimerReset() {_read_timer_acc = 0;};
187  void _ReadTimerStart() {_read_timer = VetsUtil::GetTime();};
188  void _ReadTimerStop() {_read_timer_acc += (VetsUtil::GetTime() - _read_timer);};
189 
190  void _WriteTimerReset() {_write_timer_acc = 0;};
191  void _WriteTimerStart() {_write_timer = VetsUtil::GetTime();};
192  void _WriteTimerStop() {_write_timer_acc += (VetsUtil::GetTime() - _write_timer);};
193 
194  void _XFormTimerReset() {_xform_timer_acc = 0;};
195  void _XFormTimerStart() {_xform_timer = VetsUtil::GetTime();};
196  void _XFormTimerStop() {_xform_timer_acc += (VetsUtil::GetTime() - _xform_timer);};
197 
198  //
199  // The Mask* methods are used to support missing data. If no missing
200  // data are present the methods below are no-ops. The missing value
201  // is determined by MetadataVDC::GetMissingValue()
202  //
203 
204  // Open a mask file in the VDC for writing.
205  //
206  int _MaskOpenWrite(size_t timestep, string varname, int reflevel);
207  int _MaskOpenRead(size_t timestep, string varname, int reflevel);
208  int _MaskClose();
209  int _MaskWrite(
210  const float *srcblk, const size_t bmin_p[3], const size_t bmax_p[3],
211  bool block
212  );
213  int _MaskRead(const size_t bmin_p[3], const size_t bmax_p[3]);
214 
215  //
216  // Removes missing values from a data block and replaces them with the
217  // block's average value. If all of elements of 'blk' are missing values,
218  // 'valid_data' will be set to false, otherwise it will be true
219  //
220  void _MaskRemove(float *blk, bool &valid_data) const;
221 
222  //
223  // Using a BitMask read by _MaskRead(), restore the missing values
224  // previously removed with _MaskRemove()
225  //
226  void _MaskReplace(size_t bx, size_t by, size_t bz, float *blk) const;
227 
228 
229  static void _UnpackCoord(
230  VarType_T vtype, const size_t src[3], size_t dst[3], size_t fill
231  );
232 
233  static void _PackCoord(
234  VarType_T vtype, const size_t src[3], size_t dst[3], size_t fill
235  );
236 
237  static void _FillPackedCoord(
238  VarType_T vtype, const size_t src[3], size_t dst[3], size_t fill
239  );
240 
241 
242 private:
243 
244  double _read_timer_acc;
245  double _write_timer_acc;
246  double _seek_timer_acc;
247  double _xform_timer_acc;
248 
249  double _read_timer;
250  double _write_timer;
251  double _seek_timer;
252  double _xform_timer;
253 
254  //
255  // state info to handle data sets with missing data values
256  //
257  int _ncid_mask;
258  int _varid_mask;
259  VarType_T _vtype_mask;
260  float _mv_mask;
261  size_t _bs_p_mask[3];
262  size_t _bdim_p_mask[3];
263  int _reflevel_mask;
264  int _reflevel_file_mask;
265  string _ncpath_mask;
266  string _ncpath_mask_tmp;
267  bool _open_write_mask;
268  vector <BitMask> _bitmasks;
269  string _varname; // currently opened variable;
270 
271  int _VDFIOBase();
272 
273  int _mask_open(
274  size_t timestep, string varname, int reflevel, size_t &bitmasksz
275  );
276  void _downsample(const BitMask &bm0, BitMask &bm1, int l0, int l1) const;
277 
278 };
279 
280 }
281 
282 #endif //
void _ReadTimerStart()
Definition: VDFIOBase.h:187
#define VDF_API
Definition: common.h:61
COMMON_API double GetTime()
double GetReadTimer() const
Definition: VDFIOBase.h:62
void _XFormTimerStart()
Definition: VDFIOBase.h:195
void _WriteTimerStart()
Definition: VDFIOBase.h:191
void _WriteTimerReset()
Definition: VDFIOBase.h:190
void SeekTimerStart()
Definition: VDFIOBase.h:71
void _XFormTimerReset()
Definition: VDFIOBase.h:194
void _ReadTimerStop()
Definition: VDFIOBase.h:188
A class for managing data set metadata.
Definition: MetadataVDC.h:92
void SeekTimerReset()
Definition: VDFIOBase.h:70
double GetWriteTimer() const
Definition: VDFIOBase.h:79
virtual int OpenVariableRead(size_t timestep, const char *varname, int reflevel=0, int lod=0)
Definition: VDFIOBase.h:88
double GetSeekTimer() const
Definition: VDFIOBase.h:69
static size_t getSize(size_t nbits)
Definition: VDFIOBase.h:150
virtual int CloseVariable()
Definition: VDFIOBase.h:121
void _XFormTimerStop()
Definition: VDFIOBase.h:196
void _ReadTimerReset()
Definition: VDFIOBase.h:186
void SeekTimerStop()
Definition: VDFIOBase.h:72
void _WriteTimerStop()
Definition: VDFIOBase.h:192
Abstract base class for performing data IO to a VDC.
Definition: VDFIOBase.h:27
size_t size() const
Definition: VDFIOBase.h:157
virtual int OpenVariableWrite(size_t timestep, const char *varname, int reflevel=0, int lod=0)
Definition: VDFIOBase.h:104
double GetXFormTimer() const
Definition: VDFIOBase.h:86