Overture  Version 25
GenericDataBase.h
Go to the documentation of this file.
1 #ifndef GENERICDATABASE_H
2 #define GENERICDATABASE_H "GenericDataBase.h"
3 
4 #include "OvertureDefine.h"
5 
6 // *wdh* for pgi
7 #ifdef __PGI
8  #include "math.h"
9  inline double abs(double x){ return fabs(x); }
10  #include <cmath>
11 #endif
12 
13 
14 #if !defined(OV_BOOL_DEFINED) && !defined(USE_PPP)
15  typedef int bool; // this will be the new standard for Boolean
16 #endif
17 
18 #ifdef OV_EXCEPTIONS_NOT_SUPPORTED
19  #define throw exit(1); cout <<
20 #endif
21 
22 #include "A++.h"
23 #include "aString.H"
24 
26 
27 //--------------------------------------------------------------------------
28 //
29 // GenericDataBase:
30 // This is a base class to support access to and from a data-base.
31 // This class knows how to get and put the types
32 // o int, float, double, aString
33 // as well as A++ arrays
34 // o intArray, floatArray, doubleArray
35 // as well as
36 // o "c" arrays of Strings.
37 //
38 //--------------------------------------------------------------------------
39 
41 {
42 public:
43  aString className; // this should be the name of the derived class
44  // check this to be safe before casting to the derived class
45  aString OvertureVersion; // holds version number used when file was created
46 
48  {
49  normalMode=0, // normal mode
50  streamInputMode, // stream mode (objects are input/output as a stream, no directories, no names)
52  noStreamMode, // do not use stream mode
53  bufferMode // only used internally
54  };
55 
57  {
58  independentIO, // use H5FD_MPIO_INDEPENDENT for mpi IO
59  collectiveIO, // use H5FD_MPIO_COLLECTIVE for mpi IO
60  multipleFileIO // use multiple files with serial IO
61  };
62 
63 public:
66  virtual ~GenericDataBase();
67  virtual GenericDataBase* virtualConstructor() const;
68  virtual GenericDataBase & operator=(const GenericDataBase & );
69 
70  // open a data-base file
71  virtual int mount(const aString & fileName, const aString & flags);
72  // flush data, close the file
73  virtual int unmount();
74  // flush the data to the file
75  virtual int flush();
76 
77  virtual int isNull() const;
78 
79  virtual int turnOnWarnings();
80  virtual int turnOffWarnings();
81 
82  // create a sub-directory
83  virtual int create( GenericDataBase & db, const aString & name, const aString & dirClassName );
84  // find a sub-directory (crash if not found)
85  virtual int find(GenericDataBase & db, const aString & name, const aString & dirClassName ) const;
86 
87  // locate a sub-directory
88  virtual int locate(GenericDataBase & db, const aString & name, const aString & dirClassName ) const;
89 
90  // find the names of all objects with a given className
91  virtual int find(aString *name, const aString & dirClassName,
92  const int & maxNumber, int & actualNumber) const;
93  // find all sub-directories (and their names) with a given dirClassName
94  virtual int find(GenericDataBase *db, aString *name, const aString & dirClassName,
95  const int & maxNumber, int & actualNumber) const;
96 
97  ReferenceCountingList* getList() const; // holds a list of reference counted objects that are in the data base
98  virtual int getID() const; // get the identifier for this directory
99 
100  // build a directory with the given ID
101  virtual int build(GenericDataBase & db, int id);
102 
103  // remove a directory
104  // virtual int destroy(const aString & name, const aString & flags);
105 
106  // put a float/int/double/aString
107  virtual int put( const float & x, const aString & name );
108  virtual int put( const double & x, const aString & name );
109  virtual int put( const int & x, const aString & name );
110  virtual int put( const aString & x, const aString & name );
111 #ifdef OV_BOOL_DEFINED
112  virtual int put( const bool & x, const aString & name );
113 #endif
114 
115  // get a float/int/double/aString
116  virtual int get( float & x, const aString & name ) const;
117  virtual int get( double & x, const aString & name ) const;
118  virtual int get( int & x, const aString & name ) const;
119  virtual int get( aString & x, const aString & name ) const;
120 #ifdef OV_BOOL_DEFINED
121  virtual int get( bool & x, const aString & name ) const;
122 #endif
123 
124  // put a float/int/double A++ array
125  virtual int put( const floatSerialArray & x, const aString & name );
126  virtual int put( const doubleSerialArray & x, const aString & name );
127  virtual int put( const intSerialArray & x, const aString & name );
128 
129  virtual int putDistributed( const floatArray & x, const aString & name );
130  virtual int putDistributed( const doubleArray & x, const aString & name );
131  virtual int putDistributed( const intArray & x, const aString & name );
132 
133  // get a float/int/double A++ array
134  virtual int get( floatSerialArray & x, const aString & name, Index *Iv=NULL ) const;
135  virtual int get( doubleSerialArray & x, const aString & name, Index *Iv=NULL ) const;
136  virtual int get( intSerialArray & x, const aString & name, Index *Iv=NULL ) const;
137 
138  virtual int getDistributed( floatArray & x, const aString & name ) const;
139  virtual int getDistributed( doubleArray & x, const aString & name ) const;
140  virtual int getDistributed( intArray & x, const aString & name ) const;
141 
142 
143  // put/get a "c" array of float/int/double/Strings
144  virtual int put( const int x[],const aString & name, const int number );
145  virtual int put( const float x[],const aString & name, const int number );
146  virtual int put( const double x[],const aString & name, const int number );
147  virtual int put( const aString x[],const aString & name, const int number );
148 
149  virtual int get( int x[], const aString & name, const int number ) const;
150  virtual int get( float x[], const aString & name, const int number ) const;
151  virtual int get( double x[], const aString & name, const int number ) const;
152  virtual int get( aString x[], const aString & name, const int number ) const;
153 
154  virtual void setMode(const InputOutputMode & mode=normalMode);
155  virtual InputOutputMode getMode() const;
156 
157  // set the parallel write and read modes.
160 
161  // get the parallel write and read modes.
164 
165 
166  // return the number of additional local files that are written for distributed data
168  // return the number of additional local files that are read for distributed data
170 
171  static int setMaximumNumberOfFilesForWriting( int maxNumberOfFiles );
172 
173  // output statistics on the file
174  virtual void printStatistics() const;
175 
176  protected:
179  ReferenceCountingList *referenceCountingList; // holds a list of reference counted objects that are in the data base
181 
182  int numberOfLocalFilesForWriting, numberOfLocalFilesForReading; // number of local files for parallel IO
184 
186 
187 };
188 
189 
190 #endif