Overture  Version 25
HDF5_DataBase.h
Go to the documentation of this file.
1 #ifndef HDF5_DATABASE_H
2 #define HDF5_DATABASE_H "HDF_DataBase.h"
3 
4 #include "GenericDataBase.h"
5 
6 
7 
8 //--------------------------------------------------------------------------
9 //
10 // HDF_DataBase: This is a class to support access to and from a data-base.
11 // This class knows how to get and put the types
12 // o int, float, double, aString
13 // as well as A++ arrays
14 // o intArray, floatArray, doubleArray
15 // as well as
16 // o "c" arrays of Strings.
17 //
18 // This implementation acts as a front end to the HDF Library from NCSA
19 //
20 //--------------------------------------------------------------------------
21 
22 
23 class DataBaseBuffer;
24 
26 {
27 public:
28  HDF_DataBase();
29  HDF_DataBase(const HDF_DataBase &);
31  virtual GenericDataBase* virtualConstructor() const;
32  ~HDF_DataBase();
35 
36  // open a data-base file
37  int mount(const aString & fileName, const aString & flags = "I");
38  // flush data, close the file
39  int unmount();
40  // flush the data to the file
41  int flush();
42 
43  virtual int getID() const; // get the identifier for this directory
44 
45  // build a directory with the given ID
46  virtual int build(GenericDataBase & db, int id);
47 
48  int isNull() const;
49 
50  // create a sub-directory
51  int create(GenericDataBase & db, const aString & name, const aString & dirClassName );
52  // link a new directory to an existing directory
53  int link(GenericDataBase & db, const HDF_DataBase & parent, const aString & name);
54  // find a sub-directory (crash if not found)
55  int find(GenericDataBase & db, const aString & name, const aString & dirClassName="directory") const;
56  // locate a sub-directory
57  int locate(GenericDataBase & db, const aString & name, const aString & dirClassName="directory") const;
58 
59  // find the names of all objects with a given class-name
60  virtual int find(aString *name, const aString & dirClassName,
61  const int & maxNumber, int & actualNumber) const;
62  // find all sub-directories (and their names) with a given class-name
63  virtual int find(GenericDataBase *db, aString *name, const aString & dirClassName,
64  const int & maxNumber, int & actualNumber) const;
65 
66  virtual int turnOnWarnings();
67  virtual int turnOffWarnings();
68 
69  // put a float/int/double/aString
70  int put( const float & x, const aString & name );
71  int put( const double & x, const aString & name );
72  int put( const int & x, const aString & name );
73  int put( const aString & x, const aString & name );
74 #ifdef OV_BOOL_DEFINED
75  int put( const bool & x, const aString & name );
76 #endif
77 
78  // get a float/int/double/aString
79  int get( float & x, const aString & name ) const;
80  int get( double & x, const aString & name ) const;
81  int get( int & x, const aString & name ) const;
82  int get( aString & x, const aString & name ) const;
83 #ifdef OV_BOOL_DEFINED
84  int get( bool & x, const aString & name ) const;
85 #endif
86 
87  // put a float/int/double A++ array
88  virtual int put( const floatSerialArray & x, const aString & name );
89  virtual int put( const doubleSerialArray & x, const aString & name );
90  virtual int put( const intSerialArray & x, const aString & name );
91 
92  virtual int putDistributed( const floatArray & x, const aString & name );
93  virtual int putDistributed( const doubleArray & x, const aString & name );
94  virtual int putDistributed( const intArray & x, const aString & name );
95 
96  // get a float/int/double A++ array
97  virtual int get( floatSerialArray & x, const aString & name, Index *Iv=NULL ) const;
98  virtual int get( doubleSerialArray & x, const aString & name, Index *Iv=NULL ) const;
99  virtual int get( intSerialArray & x, const aString & name, Index *Iv=NULL ) const;
100 
101  virtual int getDistributed( floatArray & x, const aString & name ) const;
102  virtual int getDistributed( doubleArray & x, const aString & name ) const;
103  virtual int getDistributed( intArray & x, const aString & name ) const;
104 
105  // put/get a "c" array of float/int/double/Strings
106  int put( const int x[],const aString & name, const int number );
107  int put( const float x[],const aString & name, const int number );
108  int put( const double x[],const aString & name, const int number );
109  int put( const aString x[],const aString & name, const int number );
110 
111  int get( int x[], const aString & name, const int number ) const;
112  int get( float x[], const aString & name, const int number ) const;
113  int get( double x[], const aString & name, const int number ) const;
114  int get( aString x[], const aString & name, const int number ) const;
115 
116  // output statistics on the file such as number of vgroups, vdatas
117  void printStatistics() const;
118 
119  virtual void setMode(const InputOutputMode & mode=normalMode);
120 
121  int putSM( const floatArray & x, const aString & name );
122  int getSM( floatArray & x, const aString & name );
123 
124 
125 static int debug;
126 
127 
128 protected:
129 
131  {
135  } accessMode;
136 
137 
138  // close the directory, flush data
139  int close();
140  void reference( const HDF_DataBase & db );
141  void destroy();
142 
143  bool bufferWasCreatedInThisDirectory; // indicates when stream buffers were really opened
144 
145  void closeStream() const; // close the stream buffers, if they are open (not really const!)
146 
147  int closeLocalFile(int p, AcessModeEnum accessMode ) const;
148 
149  int getFileGroup(int p, AcessModeEnum accessMode ) const;
150 
151  aString getSerialArrayName( const aString & fullGroupPath, const aString & name, const int p ) const;
152 
153  aString getSerialFileName( const int p, AcessModeEnum accessMode ) const ;
154 
156 
157  int fileID; // file identifier
158  aString fileName; // name of the file
159  aString fullGroupPath; // full path from root directory to current file name
160  int processorForWriting; // only one processor writes scalars to the file.
161 
163  mutable HDF_DataBase **serialDataBase; // a separate data-base file for local arrays (multipleFileIO option)
164 };
165 
166 #endif