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