ROOTANA
Loading...
Searching...
No Matches
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
18class MVOdbError;
19
20class MVOdb
21{
22public:
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 virtual void RU64(const char* varname, uint64_t *value, bool create = false, MVOdbError* error = NULL) = 0; // TID_QWORD
71
72 //
73 // read or create odb arrays
74 //
75 // all RxA() read functions do this:
76 //
77 // if array varname exists, it's contents is read into the "value" vector, size of "value" vector is same as the odb array size.
78 // if odb read fails (wrong data type, etc), value is left unchanged (but see db_get_value)
79 // if varname does not exist and create is false, value is returned unchanged
80 // if create is true, a new array is created and filled with data from the "value" vector.
81 // if "create_size" is non-zero, the newly created array size is resized to "create_size"
82 //
83 // std::vector<int> a;
84 // odb->RIA("a", &a);
85 // odb->RIA("a", &a, true);
86 // odb->RIA("a", &a, true, 10);
87 //
88 // in addition, the RxA functions provide a way to ensure that arrays in odb have the correct (expected) size:
89 //
90 // if "value" is NULL, and "create" is true, and "create_size" is not zero,
91 // if array varname exists, it's size is changed to "create_size"
92 // if array varname does not exist, it is created with size "create_size":
93 //
94 // odb->RxA(varname, NULL, true, array_size); // create new array with size "array_size"
95 //
96
97 virtual void RBA(const char* varname, std::vector<bool> *value, bool create = false, int create_size = 0, MVOdbError* error = NULL) = 0;
98 virtual void RIA(const char* varname, std::vector<int> *value, bool create = false, int create_size = 0, MVOdbError* error = NULL) = 0;
99 virtual void RDA(const char* varname, std::vector<double> *value, bool create = false, int create_size = 0, MVOdbError* error = NULL) = 0;
100 virtual void RFA(const char* varname, std::vector<float> *value, bool create = false, int create_size = 0, MVOdbError* error = NULL) = 0;
101 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;
102 virtual void RU16A(const char* varname, std::vector<uint16_t> *value, bool create = false, int create_size = 0, MVOdbError* error = NULL) = 0;
103 virtual void RU32A(const char* varname, std::vector<uint32_t> *value, bool create = false, int create_size = 0, MVOdbError* error = NULL) = 0;
104 virtual void RU64A(const char* varname, std::vector<uint64_t> *value, bool create = false, int create_size = 0, MVOdbError* error = NULL) = 0;
105
106 //
107 // read odb array elements
108 //
109 // all RxAI() read functions do this:
110 //
111 // if varname exists, it's value read from odb and returned
112 // if odb read fails (index out of range, wrong data type, etc), value is left unchanged (but see db_get_value)
113 // if varname does not exist, value is returned unchanged
114 //
115 // the RxAI() cannot create arrays, use RxA(varname, NULL, true, array_size) to ensure that arrays exist and have the correct (expected) size.
116 //
117 // instead of looping over all array elements, use RxA(varname, &v) to read the whole array at once.
118 //
119
120 virtual void RBAI(const char* varname, int index, bool *value, MVOdbError* error = NULL) = 0; // TID_BOOL
121 virtual void RIAI(const char* varname, int index, int *value, MVOdbError* error = NULL) = 0; // TID_INT
122 virtual void RDAI(const char* varname, int index, double *value, MVOdbError* error = NULL) = 0; // TID_DOUBLE
123 virtual void RFAI(const char* varname, int index, float *value, MVOdbError* error = NULL) = 0; // TID_FLOAT
124 virtual void RSAI(const char* varname, int index, std::string *value, MVOdbError* error = NULL) = 0; // TID_STRING
125 virtual void RU16AI(const char* varname, int index, uint16_t *value, MVOdbError* error = NULL) = 0; // TID_WORD
126 virtual void RU32AI(const char* varname, int index, uint32_t *value, MVOdbError* error = NULL) = 0; // TID_DWORD
127 virtual void RU64AI(const char* varname, int index, uint64_t *value, MVOdbError* error = NULL) = 0; // TID_QWORD
128
129 // create and write individual variables
130
131 virtual void WB(const char* varname, bool v, MVOdbError* error = NULL) = 0;
132 virtual void WI(const char* varname, int v, MVOdbError* error = NULL) = 0;
133 virtual void WD(const char* varname, double v, MVOdbError* error = NULL) = 0;
134 virtual void WF(const char* varname, float v, MVOdbError* error = NULL) = 0;
135 virtual void WS(const char* varname, const char* v, int string_length = 0, MVOdbError* error = NULL) = 0;
136 virtual void WU16(const char* varname, uint16_t v, MVOdbError* error = NULL) = 0;
137 virtual void WU32(const char* varname, uint32_t v, MVOdbError* error = NULL) = 0;
138 virtual void WU64(const char* varname, uint64_t v, MVOdbError* error = NULL) = 0;
139
140 // create and write whole arrays
141 //
142 // the WSA() function for writing string arrays requires the string_length argument
143 // because ODB string arrays have fixed element length and it must be specified
144 // at array creation (write) time. If string_length is zero, length of longest array
145 // element will be used.
146 //
147
148 virtual void WBA(const char* varname, const std::vector<bool>& v, MVOdbError* error = NULL) = 0;
149 virtual void WIA(const char* varname, const std::vector<int>& v, MVOdbError* error = NULL) = 0;
150 virtual void WDA(const char* varname, const std::vector<double>& v, MVOdbError* error = NULL) = 0;
151 virtual void WFA(const char* varname, const std::vector<float>& v, MVOdbError* error = NULL) = 0;
152 virtual void WSA(const char* varname, const std::vector<std::string>& v, int string_length, MVOdbError* error = NULL) = 0;
153 virtual void WU16A(const char* varname, const std::vector<uint16_t>& v, MVOdbError* error = NULL) = 0;
154 virtual void WU32A(const char* varname, const std::vector<uint32_t>& v, MVOdbError* error = NULL) = 0;
155 virtual void WU64A(const char* varname, const std::vector<uint64_t>& v, MVOdbError* error = NULL) = 0;
156
157 // write array elements
158 //
159 // writing beyound the end of an existing array will grow the array
160 //
161
162 virtual void WBAI(const char* varname, int index, bool v, MVOdbError* error = NULL) = 0;
163 virtual void WIAI(const char* varname, int index, int v, MVOdbError* error = NULL) = 0;
164 virtual void WDAI(const char* varname, int index, double v, MVOdbError* error = NULL) = 0;
165 virtual void WFAI(const char* varname, int index, float v, MVOdbError* error = NULL) = 0;
166 virtual void WSAI(const char* varname, int index, const char* v, MVOdbError* error = NULL) = 0;
167 virtual void WU16AI(const char* varname, int index, uint16_t v, MVOdbError* error = NULL) = 0;
168 virtual void WU32AI(const char* varname, int index, uint32_t v, MVOdbError* error = NULL) = 0;
169 virtual void WU64AI(const char* varname, int index, uint64_t v, MVOdbError* error = NULL) = 0;
170
171 // delete odb entries from the current directory
172
173 virtual void Delete(const char* odbname, MVOdbError* error = NULL) = 0;
174
175 // report errors to stderr or not
176 virtual void SetPrintError(bool v) = 0;
177 virtual bool GetPrintError() const = 0;
178};
179
181MVOdb* MakeMidasOdb(int hDB, MVOdbError* error = NULL);
182
183MVOdb* MakeXmlFileOdb(const char* filename, MVOdbError* error = NULL);
184MVOdb* MakeXmlBufferOdb(const char* buf, int bufsize, MVOdbError* error = NULL);
185
186MVOdb* MakeJsonFileOdb(const char* filename, MVOdbError* error = NULL);
187MVOdb* MakeJsonBufferOdb(const char* buf, int bufsize, MVOdbError* error = NULL);
188//MVOdb* MakeJsonRpcOdb(???);
189
190/// Access ODB from a midas file dump. FOrmat could be .xml, .json or .odb
191MVOdb* MakeFileDumpOdb(const char* buf, int bufsize, MVOdbError* error = NULL);
192
194{
195 public:
196 bool fError; // true if there is an error, false if no error
197 std::string fErrorString; // error text suitable for printing an error message
198 std::string fPath; // odb path corresponding to the error
199 int fStatus; // MIDAS ODB status numerical value
200
201 public:
202 MVOdbError();
203};
204
205void SetOk(MVOdbError* error);
206void SetError(MVOdbError* error, bool print, const std::string& path, const std::string& message);
207void SetMidasStatus(MVOdbError* error, bool print, const std::string& path, const char* midas_func_name, int status);
208
209#endif
210
211/* emacs
212 * Local Variables:
213 * tab-width: 8
214 * c-basic-offset: 3
215 * indent-tabs-mode: nil
216 * End:
217 */
std::string fPath
Definition mvodb.h:198
int fStatus
Definition mvodb.h:199
MVOdbError()
Definition mvodb.cxx:28
bool fError
Definition mvodb.h:196
std::string fErrorString
Definition mvodb.h:197
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 WU64A(const char *varname, const std::vector< uint64_t > &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 MVOdb * Chdir(const char *subdirname, bool create=false, MVOdbError *error=NULL)=0
virtual bool GetPrintError() const =0
virtual void WF(const char *varname, float v, MVOdbError *error=NULL)=0
virtual void RU64A(const char *varname, std::vector< uint64_t > *value, bool create=false, int create_size=0, MVOdbError *error=NULL)=0
virtual void WFA(const char *varname, const std::vector< float > &v, MVOdbError *error=NULL)=0
virtual ~MVOdb()=0
Definition mvodb.cxx:16
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 RU64AI(const char *varname, int index, uint64_t *value, MVOdbError *error=NULL)=0
virtual void WU32(const char *varname, uint32_t v, MVOdbError *error=NULL)=0
virtual void WU64(const char *varname, uint64_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 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 void ReadKeyLastWritten(const char *varname, int *last_written, MVOdbError *error=NULL)=0
virtual void WU64AI(const char *varname, int index, uint64_t v, MVOdbError *error=NULL)=0
virtual void RU64(const char *varname, uint64_t *value, bool create=false, 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:43
MVOdb * MakeJsonBufferOdb(const char *buf, int bufsize, MVOdbError *error=NULL)
Definition mjsonodb.cxx:698
MVOdb * MakeMidasOdb(int hDB, MVOdbError *error=NULL)
Definition midasodb.cxx:969
MVOdb * MakeXmlBufferOdb(const char *buf, int bufsize, MVOdbError *error=NULL)
Definition mxmlodb.cxx:751
void SetError(MVOdbError *error, bool print, const std::string &path, const std::string &message)
Definition mvodb.cxx:72
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:93
MVOdb * MakeNullOdb()
Definition nullodb.cxx:137
void SetOk(MVOdbError *error)
Definition mvodb.cxx:33
MVOdb * MakeXmlFileOdb(const char *filename, MVOdbError *error=NULL)
Definition mxmlodb.cxx:720
MVOdb * MakeJsonFileOdb(const char *filename, MVOdbError *error=NULL)
Definition mjsonodb.cxx:660