ROOTANA
mvodb.h
Go to the documentation of this file.
1 /********************************************************************\
2 
3  Name: mvodb.h
4  Created by: K.Olchanski
5 
6  Contents: Virtual ODB interface
7 
8 \********************************************************************/
9 
10 #ifndef INCLUDE_MVODB_H
11 #define INCLUDE_MVODB_H
12 
13 #include <string>
14 #include <vector>
15 //#include <cstdio>
16 #include <stdint.h>
17 
18 class MVOdbError;
19 
20 class MVOdb
21 {
22 public:
23  // destructor
24  virtual ~MVOdb() = 0;
25 
26  // check if this ODB interface allows writing
27  virtual bool IsReadOnly() const = 0;
28 
29  // navigate into subdirectory.
30  //
31  // returns NULL is subdirname does not exist and "create" is false.
32  // returns NULL is subdirname is not a subdirectory and "create" is false
33  // never returns NULL if "create" is true - returns a subdirectory or NullOdb if there was an error
34 
35  virtual MVOdb* Chdir(const char* subdirname, bool create = false, MVOdbError* error = NULL) = 0;
36 
37  // read array information: number of elements and element size (string size for TID_STRING arrays)
38 
39  virtual void ReadKey(const char* varname, int *tid, int *num_values, int *total_size, int *item_size, MVOdbError* error = NULL) = 0;
40 
41  // read last time a key was written
42  virtual void ReadKeyLastWritten( const char* varname, int *last_written, MVOdbError* error = NULL) = 0;
43 
44  // read the contents of current directory
45 
46  virtual void ReadDir(std::vector<std::string>* varname, std::vector<int> *tid, std::vector<int> *num_values, std::vector<int> *total_size, std::vector<int> *item_size, MVOdbError* error = NULL) = 0;
47 
48  //
49  // create and read individual odb variables
50  //
51  // all Rx() read functions do this:
52  //
53  // if varname exists, it's value read from odb and returned
54  // if odb read fails (wrong data type, etc), value is left unchanged (but see db_get_value)
55  // if varname does not exist and create is false, value is returned unchanged
56  // if create is true, varname is created in odb with given value and given string length
57  //
58  // int a = 10; // default value
59  // odb->RI("a", &a); // read from odb, keep default value if does not exist
60  // odb->RI("a", &a, true); // read from odb, create with default value if does not exist
61  //
62 
63  virtual void RB(const char* varname, bool *value, bool create = false, MVOdbError* error = NULL) = 0; // TID_BOOL
64  virtual void RI(const char* varname, int *value, bool create = false, MVOdbError* error = NULL) = 0; // TID_INT
65  virtual void RD(const char* varname, double *value, bool create = false, MVOdbError* error = NULL) = 0; // TID_DOUBLE
66  virtual void RF(const char* varname, float *value, bool create = false, MVOdbError* error = NULL) = 0; // TID_FLOAT
67  virtual void RS(const char* varname, std::string *value, bool create = false, int create_string_length = 0, MVOdbError* error = NULL) = 0; // TID_STRING
68  virtual void RU16(const char* varname, uint16_t *value, bool create = false, MVOdbError* error = NULL) = 0; // TID_WORD
69  virtual void RU32(const char* varname, uint32_t *value, bool create = false, MVOdbError* error = NULL) = 0; // TID_DWORD
70 
71  //
72  // read or create odb arrays
73  //
74  // all RxA() read functions do this:
75  //
76  // if array varname exists, it's contents is read into the "value" vector, size of "value" vector is same as the odb array size.
77  // if odb read fails (wrong data type, etc), value is left unchanged (but see db_get_value)
78  // if varname does not exist and create is false, value is returned unchanged
79  // if create is true, a new array is created and filled with data from the "value" vector.
80  // if "create_size" is non-zero, the newly created array size is resized to "create_size"
81  //
82  // std::vector<int> a;
83  // odb->RIA("a", &a);
84  // odb->RIA("a", &a, true);
85  // odb->RIA("a", &a, true, 10);
86  //
87  // in addition, the RxA functions provide a way to ensure that arrays in odb have the correct (expected) size:
88  //
89  // if "value" is NULL, and "create" is true, and "create_size" is not zero,
90  // if array varname exists, it's size is changed to "create_size"
91  // if array varname does not exist, it is created with size "create_size":
92  //
93  // odb->RxA(varname, NULL, true, array_size); // create new array with size "array_size"
94  //
95 
96  virtual void RBA(const char* varname, std::vector<bool> *value, bool create = false, int create_size = 0, MVOdbError* error = NULL) = 0;
97  virtual void RIA(const char* varname, std::vector<int> *value, bool create = false, int create_size = 0, MVOdbError* error = NULL) = 0;
98  virtual void RDA(const char* varname, std::vector<double> *value, bool create = false, int create_size = 0, MVOdbError* error = NULL) = 0;
99  virtual void RFA(const char* varname, std::vector<float> *value, bool create = false, int create_size = 0, MVOdbError* error = NULL) = 0;
100  virtual void RSA(const char* varname, std::vector<std::string> *value, bool create = false, int create_size = 0, int create_string_length = 0, MVOdbError* error = NULL) = 0;
101  virtual void RU16A(const char* varname, std::vector<uint16_t> *value, bool create = false, int create_size = 0, MVOdbError* error = NULL) = 0;
102  virtual void RU32A(const char* varname, std::vector<uint32_t> *value, bool create = false, int create_size = 0, MVOdbError* error = NULL) = 0;
103 
104  //
105  // read odb array elements
106  //
107  // all RxAI() read functions do this:
108  //
109  // if varname exists, it's value read from odb and returned
110  // if odb read fails (index out of range, wrong data type, etc), value is left unchanged (but see db_get_value)
111  // if varname does not exist, value is returned unchanged
112  //
113  // the RxAI() cannot create arrays, use RxA(varname, NULL, true, array_size) to ensure that arrays exist and have the correct (expected) size.
114  //
115  // instead of looping over all array elements, use RxA(varname, &v) to read the whole array at once.
116  //
117 
118  virtual void RBAI(const char* varname, int index, bool *value, MVOdbError* error = NULL) = 0; // TID_BOOL
119  virtual void RIAI(const char* varname, int index, int *value, MVOdbError* error = NULL) = 0; // TID_INT
120  virtual void RDAI(const char* varname, int index, double *value, MVOdbError* error = NULL) = 0; // TID_DOUBLE
121  virtual void RFAI(const char* varname, int index, float *value, MVOdbError* error = NULL) = 0; // TID_FLOAT
122  virtual void RSAI(const char* varname, int index, std::string *value, MVOdbError* error = NULL) = 0; // TID_STRING
123  virtual void RU16AI(const char* varname, int index, uint16_t *value, MVOdbError* error = NULL) = 0; // TID_WORD
124  virtual void RU32AI(const char* varname, int index, uint32_t *value, MVOdbError* error = NULL) = 0; // TID_DWORD
125 
126  // create and write individual variables
127 
128  virtual void WB(const char* varname, bool v, MVOdbError* error = NULL) = 0;
129  virtual void WI(const char* varname, int v, MVOdbError* error = NULL) = 0;
130  virtual void WD(const char* varname, double v, MVOdbError* error = NULL) = 0;
131  virtual void WF(const char* varname, float v, MVOdbError* error = NULL) = 0;
132  virtual void WS(const char* varname, const char* v, int string_length = 0, MVOdbError* error = NULL) = 0;
133  virtual void WU16(const char* varname, uint16_t v, MVOdbError* error = NULL) = 0;
134  virtual void WU32(const char* varname, uint32_t v, MVOdbError* error = NULL) = 0;
135 
136  // create and write whole arrays
137  //
138  // the WSA() function for writing string arrays requires the string_length argument
139  // because ODB string arrays have fixed element length and it must be specified
140  // at array creation (write) time. If string_length is zero, length of longest array
141  // element will be used.
142  //
143 
144  virtual void WBA(const char* varname, const std::vector<bool>& v, MVOdbError* error = NULL) = 0;
145  virtual void WIA(const char* varname, const std::vector<int>& v, MVOdbError* error = NULL) = 0;
146  virtual void WDA(const char* varname, const std::vector<double>& v, MVOdbError* error = NULL) = 0;
147  virtual void WFA(const char* varname, const std::vector<float>& v, MVOdbError* error = NULL) = 0;
148  virtual void WSA(const char* varname, const std::vector<std::string>& v, int string_length, MVOdbError* error = NULL) = 0;
149  virtual void WU16A(const char* varname, const std::vector<uint16_t>& v, MVOdbError* error = NULL) = 0;
150  virtual void WU32A(const char* varname, const std::vector<uint32_t>& v, MVOdbError* error = NULL) = 0;
151 
152  // write array elements
153  //
154  // writing beyound the end of an existing array will grow the array
155  //
156 
157  virtual void WBAI(const char* varname, int index, bool v, MVOdbError* error = NULL) = 0;
158  virtual void WIAI(const char* varname, int index, int v, MVOdbError* error = NULL) = 0;
159  virtual void WDAI(const char* varname, int index, double v, MVOdbError* error = NULL) = 0;
160  virtual void WFAI(const char* varname, int index, float v, MVOdbError* error = NULL) = 0;
161  virtual void WSAI(const char* varname, int index, const char* v, MVOdbError* error = NULL) = 0;
162  virtual void WU16AI(const char* varname, int index, uint16_t v, MVOdbError* error = NULL) = 0;
163  virtual void WU32AI(const char* varname, int index, uint32_t v, MVOdbError* error = NULL) = 0;
164 
165  // delete odb entries from the current directory
166 
167  virtual void Delete(const char* odbname, MVOdbError* error = NULL) = 0;
168 
169  // report errors to stderr or not
170  virtual void SetPrintError(bool v) = 0;
171  virtual bool GetPrintError() const = 0;
172 };
173 
174 MVOdb* MakeNullOdb();
175 MVOdb* MakeMidasOdb(int hDB, MVOdbError* error = NULL);
176 
177 MVOdb* MakeXmlFileOdb(const char* filename, MVOdbError* error = NULL);
178 MVOdb* MakeXmlBufferOdb(const char* buf, int bufsize, MVOdbError* error = NULL);
179 
180 MVOdb* MakeJsonFileOdb(const char* filename, MVOdbError* error = NULL);
181 MVOdb* MakeJsonBufferOdb(const char* buf, int bufsize, MVOdbError* error = NULL);
182 //MVOdb* MakeJsonRpcOdb(???);
183 
184 /// Access ODB from a midas file dump. FOrmat could be .xml, .json or .odb
185 MVOdb* MakeFileDumpOdb(const char* buf, int bufsize, MVOdbError* error = NULL);
186 
187 class MVOdbError
188 {
189  public:
190  bool fError; // true if there is an error, false if no error
191  std::string fErrorString; // error text suitable for printing an error message
192  std::string fPath; // odb path corresponding to the error
193  int fStatus; // MIDAS ODB status numerical value
194 
195  public:
197 };
198 
199 void SetOk(MVOdbError* error);
200 void SetError(MVOdbError* error, bool print, const std::string& path, const std::string& message);
201 void SetMidasStatus(MVOdbError* error, bool print, const std::string& path, const char* midas_func_name, int status);
202 
203 #endif
204 
205 /* emacs
206  * Local Variables:
207  * tab-width: 8
208  * c-basic-offset: 3
209  * indent-tabs-mode: nil
210  * End:
211  */
std::string fPath
Definition: mvodb.h:192
int fStatus
Definition: mvodb.h:193
bool fError
Definition: mvodb.h:190
std::string fErrorString
Definition: mvodb.h:191
Definition: mvodb.h:21
virtual void WI(const char *varname, int v, MVOdbError *error=NULL)=0
virtual void RIA(const char *varname, std::vector< int > *value, bool create=false, int create_size=0, MVOdbError *error=NULL)=0
virtual void ReadKey(const char *varname, int *tid, int *num_values, int *total_size, int *item_size, MVOdbError *error=NULL)=0
virtual void WBA(const char *varname, const std::vector< bool > &v, MVOdbError *error=NULL)=0
virtual void WSAI(const char *varname, int index, const char *v, MVOdbError *error=NULL)=0
virtual void WIAI(const char *varname, int index, int v, MVOdbError *error=NULL)=0
virtual void RFAI(const char *varname, int index, float *value, MVOdbError *error=NULL)=0
virtual void WU16(const char *varname, uint16_t v, MVOdbError *error=NULL)=0
virtual void WFAI(const char *varname, int index, float v, MVOdbError *error=NULL)=0
virtual void RS(const char *varname, std::string *value, bool create=false, int create_string_length=0, MVOdbError *error=NULL)=0
virtual void RU16AI(const char *varname, int index, uint16_t *value, MVOdbError *error=NULL)=0
virtual void WDAI(const char *varname, int index, double v, MVOdbError *error=NULL)=0
virtual void RBAI(const char *varname, int index, bool *value, MVOdbError *error=NULL)=0
virtual bool GetPrintError() const =0
virtual void WF(const char *varname, float v, MVOdbError *error=NULL)=0
virtual void WFA(const char *varname, const std::vector< float > &v, MVOdbError *error=NULL)=0
virtual void RU32(const char *varname, uint32_t *value, bool create=false, MVOdbError *error=NULL)=0
virtual void WSA(const char *varname, const std::vector< std::string > &v, int string_length, MVOdbError *error=NULL)=0
virtual void WU32(const char *varname, uint32_t v, MVOdbError *error=NULL)=0
virtual void ReadDir(std::vector< std::string > *varname, std::vector< int > *tid, std::vector< int > *num_values, std::vector< int > *total_size, std::vector< int > *item_size, MVOdbError *error=NULL)=0
virtual void RU16(const char *varname, uint16_t *value, bool create=false, MVOdbError *error=NULL)=0
virtual MVOdb * Chdir(const char *subdirname, bool create=false, MVOdbError *error=NULL)=0
virtual void WDA(const char *varname, const std::vector< double > &v, MVOdbError *error=NULL)=0
virtual bool IsReadOnly() const =0
virtual void RBA(const char *varname, std::vector< bool > *value, bool create=false, int create_size=0, MVOdbError *error=NULL)=0
virtual void RU16A(const char *varname, std::vector< uint16_t > *value, bool create=false, int create_size=0, MVOdbError *error=NULL)=0
virtual void RDAI(const char *varname, int index, double *value, MVOdbError *error=NULL)=0
virtual void RSAI(const char *varname, int index, std::string *value, MVOdbError *error=NULL)=0
virtual void SetPrintError(bool v)=0
virtual void WU16AI(const char *varname, int index, uint16_t v, MVOdbError *error=NULL)=0
virtual void WU16A(const char *varname, const std::vector< uint16_t > &v, MVOdbError *error=NULL)=0
virtual void Delete(const char *odbname, MVOdbError *error=NULL)=0
virtual void WIA(const char *varname, const std::vector< int > &v, MVOdbError *error=NULL)=0
virtual void WBAI(const char *varname, int index, bool v, MVOdbError *error=NULL)=0
virtual void RIAI(const char *varname, int index, int *value, MVOdbError *error=NULL)=0
virtual void WD(const char *varname, double v, MVOdbError *error=NULL)=0
virtual void RSA(const char *varname, std::vector< std::string > *value, bool create=false, int create_size=0, int create_string_length=0, MVOdbError *error=NULL)=0
virtual void RI(const char *varname, int *value, bool create=false, MVOdbError *error=NULL)=0
virtual void RB(const char *varname, bool *value, bool create=false, MVOdbError *error=NULL)=0
virtual void RDA(const char *varname, std::vector< double > *value, bool create=false, int create_size=0, MVOdbError *error=NULL)=0
virtual void WS(const char *varname, const char *v, int string_length=0, MVOdbError *error=NULL)=0
virtual void RF(const char *varname, float *value, bool create=false, MVOdbError *error=NULL)=0
virtual void RFA(const char *varname, std::vector< float > *value, bool create=false, int create_size=0, MVOdbError *error=NULL)=0
virtual void RD(const char *varname, double *value, bool create=false, MVOdbError *error=NULL)=0
virtual void WU32A(const char *varname, const std::vector< uint32_t > &v, MVOdbError *error=NULL)=0
virtual ~MVOdb()=0
virtual void ReadKeyLastWritten(const char *varname, int *last_written, MVOdbError *error=NULL)=0
virtual void WU32AI(const char *varname, int index, uint32_t v, MVOdbError *error=NULL)=0
virtual void WB(const char *varname, bool v, MVOdbError *error=NULL)=0
virtual void RU32AI(const char *varname, int index, uint32_t *value, MVOdbError *error=NULL)=0
virtual void RU32A(const char *varname, std::vector< uint32_t > *value, bool create=false, int create_size=0, MVOdbError *error=NULL)=0
void SetMidasStatus(MVOdbError *error, bool print, const std::string &path, const char *midas_func_name, int status)
Definition: mvodb.cxx:41
MVOdb * MakeMidasOdb(int hDB, MVOdbError *error=NULL)
Definition: midasodb.cxx:924
MVOdb * MakeNullOdb()
Definition: nullodb.cxx:129
MVOdb * MakeJsonFileOdb(const char *filename, MVOdbError *error=NULL)
Definition: mjsonodb.cxx:536
MVOdb * MakeFileDumpOdb(const char *buf, int bufsize, MVOdbError *error=NULL)
Access ODB from a midas file dump. FOrmat could be .xml, .json or .odb.
Definition: mvodb.cxx:91
MVOdb * MakeXmlFileOdb(const char *filename, MVOdbError *error=NULL)
Definition: mxmlodb.cxx:689
MVOdb * MakeXmlBufferOdb(const char *buf, int bufsize, MVOdbError *error=NULL)
Definition: mxmlodb.cxx:720
void SetError(MVOdbError *error, bool print, const std::string &path, const std::string &message)
Definition: mvodb.cxx:70
MVOdb * MakeJsonBufferOdb(const char *buf, int bufsize, MVOdbError *error=NULL)
Definition: mjsonodb.cxx:574
void SetOk(MVOdbError *error)
Definition: mvodb.cxx:31