ROOTANA
Loading...
Searching...
No Matches
mjsonodb.cxx
Go to the documentation of this file.
1//
2// ALPHA ROOT analyzer
3//
4// Access to ODB stored in JSON odb save file or ODB JSON dump in MIDAS data file.
5//
6// Name: mjsonodb.cxx
7// Author: K.Olchanski, 28-May-2019
8//
9
10#undef NDEBUG // midas required assert() to be always enabled
11
12#include <stdio.h>
13#include <assert.h>
14#include <stdlib.h>
15#include <string.h> // memset()
16#include <errno.h> // errno
17
18#include "mvodb.h"
19#include "mjson.h"
20
21static std::string toString(int i)
22{
23 char buf[256];
24 snprintf(buf, sizeof(buf), "%d", i);
25 return buf;
26}
27
28/// Access to ODB saved in JSON format inside midas .mid files
29
30class JsonOdb : public MVOdb
31{
32public:
33 const MJsonNode* fRoot; // root of JSON document, NULL if we are a subdirectory
34 const MJsonNode* fDir; // current ODB directory
35 std::string fPath; // path to correct ODB directory
37
38public:
39 JsonOdb(MJsonNode* root, const MJsonNode* dir, MVOdbError* error) // ctor
40 {
41 fPrintError = false;
42 fRoot = root;
43 fDir = dir;
44 fPath = "";
45 SetOk(error);
46 }
47
48 ~JsonOdb() // dtor
49 {
50 if (fRoot) {
51 delete fRoot;
52 fRoot = NULL;
53 }
54 fDir = NULL;
55 }
56
57public:
58 void SetPrintError(bool v)
59 {
60 fPrintError = true;
61 }
62
63 bool GetPrintError() const
64 {
65 return fPrintError;
66 }
67
68 void SetNotFound(MVOdbError* error, const char* varname)
69 {
70 std::string msg;
71 msg += "Cannot find ";
72 msg += "\"";
73 msg += varname;
74 msg += "\"";
75 SetError(error, fPrintError, fPath, msg);
76 }
77
78 void SetVarError(MVOdbError* error, const char* varname, std::string msg)
79 {
80 std::string path;
81 path += fPath;
82 path += "/";
83 path += varname;
84 SetError(error, fPrintError, path, msg);
85 }
86
87 void SetWrongType(MVOdbError* error, const char* varname, const MJsonNode* node, const char* wanted_type)
88 {
89 std::string path;
90 path += fPath;
91 path += "/";
92 path += varname;
93 std::string msg;
94 msg += "JSON node type mismatch: cannot convert node type ";
95 msg += MJsonNode::TypeToString(node->GetType());
96 msg += " to c++ type ";
97 msg += "\"";
98 msg += wanted_type;
99 msg += "\"";
100 SetError(error, fPrintError, path, msg);
101 }
102
103 bool IsReadOnly() const
104 {
105 return true;
106 }
107
108 template <typename T>
109 bool GetJsonValue(const char* varname, const MJsonNode* node, T* value, MVOdbError *error);
110
111 /// Follow the ODB path through the JSON tree
112 static const MJsonNode* FindPath(const MJsonNode* dir, const char* path, bool return_key = false)
113 {
114 assert(dir);
115
116 while (1) {
117 // skip leading slashes
118 while (*path == '/')
119 path++;
120
121 if (*path == 0)
122 return dir;
123
124 std::string elem;
125
126 // copy the next path element into "elem"-
127 // copy "path" until we hit "/" or end of string
128 while (1) {
129 if (*path==0 || *path=='/')
130 break;
131 elem += *path++;
132 }
133
134 //printf("looking for \"%s\" more \"%s\"\n", elem.c_str(), path);
135
136 MJsonNode* found = NULL;
137
138 const MJsonStringVector* s = dir->GetObjectNames();
139 const MJsonNodeVector* n = dir->GetObjectNodes();
140
141 assert(s);
142 assert(n);
143 assert(s->size() == n->size());
144
145 for (unsigned i=0; i<s->size(); i++) {
146 if (return_key) {
147 if (strcasecmp((elem+"/key").c_str(), (*s)[i].c_str()) == 0) {
148 return (*n)[i];
149 }
150 }
151
152 if (strcasecmp(elem.c_str(), (*s)[i].c_str()) == 0) {
153 if (dir->GetType() == MJSON_OBJECT) {
154 // found the right subdirectory, descend into it
155 found = (*n)[i];
156 break;
157 } else {
158 return (*n)[i];
159 }
160 }
161 }
162
163 if (!found)
164 return NULL;
165 dir = found;
166 }
167 }
168
169 static int GetInt(const MJsonNode* dir, const char* name, int missing_value)
170 {
171 const MJsonNode* n = dir->FindObjectNode(name);
172 if (!n)
173 return missing_value;
174 return (int)n->GetInt();
175 }
176
177 MVOdb* Chdir(const char* subdir, bool create, MVOdbError* error)
178 {
179 const MJsonNode* node = FindPath(fDir, subdir);
180 if (!node) {
181 SetNotFound(error, subdir);
182 if (create) {
183 return MakeNullOdb();
184 } else {
185 return NULL;
186 }
187 }
188
189 if (node->GetType() != MJSON_OBJECT) {
190 std::string msg;
191 msg += "\"";
192 msg += subdir;
193 msg += "\"";
194 msg += " JSON node is ";
195 msg += "\"";
196 msg += MJsonNode::TypeToString(node->GetType());
197 msg += "\"";
198 msg += " instead of subdirectory";
199 SetError(error, fPrintError, fPath, msg);
200 if (create)
201 return MakeNullOdb();
202 else
203 return NULL;
204 }
205
206 //printf("Found subdir [%s]\n", subdir);
207 //DumpTree(node);
208
209 JsonOdb* x = new JsonOdb(NULL, node, error);
210 x->fPath = fPath + "/" + subdir;
211
212 SetOk(error);
213 return x;
214 }
215
216 void ReadKey(const char* varname, int *tid, int *num_values, int *total_size, int *item_size, MVOdbError* error)
217 {
218 const MJsonNode* node = FindPath(fDir, varname, true);
219 if (!node) {
220 SetNotFound(error, varname);
221 return;
222 }
223
224 //node->Dump();
225
226 if (node->GetType() != MJSON_OBJECT) {
227 SetNotFound(error, varname);
228 return;
229 }
230
231 if (tid) *tid = GetInt(node, "type", 0);
232 if (num_values) *num_values = GetInt(node, "num_values", 1);
233 if (total_size) *total_size = 0;
234 if (item_size) *item_size = GetInt(node, "item_size", 0);
235
236 SetOk(error);
237 }
238
239 void ReadKeyLastWritten(const char* varname, int *last_written, MVOdbError* error)
240 {
241 const MJsonNode* node = FindPath(fDir, varname, true);
242 if (!node) {
243 SetNotFound(error, varname);
244 return;
245 }
246
247 if (node->GetType() != MJSON_OBJECT) {
248 SetNotFound(error, varname);
249 return;
250 }
251
252 if (last_written) *last_written = GetInt(node, "last_written", 0);
253
254 SetOk(error);
255 }
256
257 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)
258 {
259 // FIXME: not implemented
260
262 const MJsonNodeVector* nv = fDir->GetObjectNodes();
263
264 assert(sv);
265 assert(nv);
266 assert(sv->size() == nv->size());
267
268 for (size_t i=0; i<nv->size(); i++) {
269 const char* s = (*sv)[i].c_str();
270 const MJsonNode* n = (*nv)[i];
271
272 //printf("name [%s]\n", s);
273
274 size_t len = strlen(s);
275
276 if (len <= 4) // cannot be "xxx/key"
277 continue;
278
279 // name ends with "/key"
280
281 if (s[len-4] != '/')
282 continue;
283 if (s[len-3] != 'k')
284 continue;
285 if (s[len-2] != 'e')
286 continue;
287 if (s[len-1] != 'y')
288 continue;
289
290 //n->Dump();
291
292 if (tid)
293 tid->push_back(GetInt(n, "type", 0));
294 if (num_values)
295 num_values->push_back(GetInt(n, "num_values", 1));
296 if (total_size)
297 total_size->push_back(0);
298 if (item_size)
299 item_size->push_back(GetInt(n, "item_size", 0));
300 if (varname)
301 varname->push_back((*sv)[i].substr(0, len-4));
302 }
303
304
305 SetOk(error);
306 }
307
308 void RB(const char* varname, bool *value, bool create, MVOdbError* error)
309 {
310 RBAI(varname, 0, value, error);
311 };
312
313 void RI(const char* varname, int *value, bool create, MVOdbError* error)
314 {
315 RIAI(varname, 0, value, error);
316 };
317
318 void RD(const char* varname, double *value, bool create, MVOdbError* error)
319 {
320 RDAI(varname, 0, value, error);
321 };
322
323 void RF(const char* varname, float *value, bool create, MVOdbError* error)
324 {
325 RFAI(varname, 0, value, error);
326 };
327
328 void RS(const char* varname, std::string *value, bool create, int create_string_length, MVOdbError* error)
329 {
330 RSAI(varname, 0, value, error);
331 };
332
333 void RU16(const char* varname, uint16_t *value, bool create, MVOdbError* error)
334 {
335 RU16AI(varname, 0, value, error);
336 };
337
338 void RU32(const char* varname, uint32_t *value, bool create, MVOdbError* error)
339 {
340 RU32AI(varname, 0, value, error);
341 };
342
343 void RU64(const char* varname, uint64_t *value, bool create, MVOdbError* error)
344 {
345 RU64AI(varname, 0, value, error);
346 };
347
348 template <typename T>
349 void RXA(const char* varname, std::vector<T> *value, MVOdbError* error)
350 {
351 if (!value) {
352 SetOk(error);
353 return;
354 }
355
356 const MJsonNode* node = FindPath(fDir, varname);
357 if (!node) {
358 SetNotFound(error, varname);
359 return;
360 }
361
362 //DumpTree(node);
363
364 if (node->GetType() == MJSON_OBJECT) {
365 SetVarError(error, varname, "JSON node is a subdirectory");
366 return;
367 } else if (node->GetType() == MJSON_ARRAY) {
368
369 const MJsonNodeVector* a = node->GetArray();
370
371 int num_values = a->size();
372
373 value->clear();
374
375 for (int i=0; i<num_values; i++) {
376 const MJsonNode* elem = (*a)[i];
377 T v;
378 bool ok = GetJsonValue<T>(varname, elem, &v, error);
379 if (!ok)
380 break;
381 value->push_back(v);
382 }
383 } else {
384 T v;
385 bool ok = GetJsonValue<T>(varname, node, &v, error);
386 if (!ok)
387 return;
388 value->clear();
389 value->push_back(v);
390 }
391 };
392
393 void RBA(const char* varname, std::vector<bool> *value, bool create, int create_size, MVOdbError* error)
394 {
395 RXA(varname, value, error);
396 }
397
398 void RIA(const char* varname, std::vector<int> *value, bool create, int create_size, MVOdbError* error)
399 {
400 RXA(varname, value, error);
401 }
402
403 void RDA(const char* varname, std::vector<double> *value, bool create, int create_size, MVOdbError* error)
404 {
405 RXA(varname, value, error);
406 }
407
408 void RFA(const char* varname, std::vector<float> *value, bool create, int create_size, MVOdbError* error)
409 {
410 RXA(varname, value, error);
411 }
412
413 void RSA(const char* varname, std::vector<std::string> *value, bool create, int create_size, int create_string_length, MVOdbError* error)
414 {
415 RXA(varname, value, error);
416 }
417
418 void RU16A(const char* varname, std::vector<uint16_t> *value, bool create, int create_size, MVOdbError* error)
419 {
420 RXA(varname, value, error);
421 }
422
423 void RU32A(const char* varname, std::vector<uint32_t> *value, bool create, int create_size, MVOdbError* error)
424 {
425 RXA(varname, value, error);
426 }
427
428 void RU64A(const char* varname, std::vector<uint64_t> *value, bool create, int create_size, MVOdbError* error)
429 {
430 RXA(varname, value, error);
431 }
432
433 template <typename T>
434 void RXAI(const char* varname, int index, T* value, MVOdbError* error)
435 {
436 if (!value) {
437 SetOk(error);
438 return;
439 }
440
441 const MJsonNode* node = FindPath(fDir, varname);
442 if (!node) {
443 SetNotFound(error, varname);
444 return;
445 }
446
447 //printf("varname [%s] index %d, found node %p:\n", varname, index, node);
448 //node->Dump();
449
450 if (node->GetType() == MJSON_OBJECT) {
451 SetVarError(error, varname, "JSON node is a subdirectory");
452 return;
453 } else if (node->GetType() == MJSON_ARRAY) {
454 //DumpTree(node);
455
456 const MJsonNodeVector* a = node->GetArray();
457
458 int num_values = a->size();
459
460 if (index < 0) {
461 std::string msg;
462 msg += "bad index ";
463 msg += toString(index);
464 msg += " for array of size ";
465 msg += toString(num_values);
466 SetVarError(error, varname, msg);
467 return;
468 }
469
470 if (index >= num_values) {
471 std::string msg;
472 msg += "bad index ";
473 msg += toString(index);
474 msg += " for array of size ";
475 msg += toString(num_values);
476 SetVarError(error, varname, msg);
477 return;
478 }
479
480 MJsonNode* elem = (*a)[index];
481
482 GetJsonValue<T>(varname, elem, value, error);
483 return;
484 } else {
485 if (index != 0) {
486 std::string msg;
487 msg += "non-zero index ";
488 msg += toString(index);
489 msg += " for non-array";
490 SetVarError(error, varname, msg);
491 return;
492 }
493
494 GetJsonValue<T>(varname, node, value, error);
495 return;
496 }
497 }
498
499 void RBAI(const char* varname, int index, bool *value, MVOdbError* error)
500 {
501 RXAI(varname, index, value, error);
502 }
503
504 void RIAI(const char* varname, int index, int *value, MVOdbError* error)
505 {
506 RXAI(varname, index, value, error);
507 }
508
509 void RDAI(const char* varname, int index, double *value, MVOdbError* error)
510 {
511 RXAI(varname, index, value, error);
512 }
513
514 void RFAI(const char* varname, int index, float *value, MVOdbError* error)
515 {
516 RXAI(varname, index, value, error);
517 }
518
519 void RSAI(const char* varname, int index, std::string *value, MVOdbError* error)
520 {
521 RXAI(varname, index, value, error);
522 }
523
524 void RU16AI(const char* varname, int index, uint16_t *value, MVOdbError* error)
525 {
526 RXAI(varname, index, value, error);
527 }
528
529 void RU32AI(const char* varname, int index, uint32_t *value, MVOdbError* error)
530 {
531 RXAI(varname, index, value, error);
532 }
533
534 void RU64AI(const char* varname, int index, uint64_t *value, MVOdbError* error)
535 {
536 RXAI(varname, index, value, error);
537 }
538
539 // write functions do nothing
540
541 void WB(const char* varname, bool v, MVOdbError* error) { SetOk(error); };
542 void WI(const char* varname, int v, MVOdbError* error) { SetOk(error); };
543 void WD(const char* varname, double v, MVOdbError* error) { SetOk(error); };
544 void WF(const char* varname, float v, MVOdbError* error) { SetOk(error); };
545 void WS(const char* varname, const char* v, int string_length, MVOdbError* error) { SetOk(error); };
546 void WU16(const char* varname, uint16_t v, MVOdbError* error) { SetOk(error); };
547 void WU32(const char* varname, uint32_t v, MVOdbError* error) { SetOk(error); };
548 void WU64(const char* varname, uint64_t v, MVOdbError* error) { SetOk(error); };
549
550 void WBA(const char* varname, const std::vector<bool>& v, MVOdbError* error) { SetOk(error); };
551 void WIA(const char* varname, const std::vector<int>& v, MVOdbError* error) { SetOk(error); };
552 void WDA(const char* varname, const std::vector<double>& v, MVOdbError* error) { SetOk(error); };
553 void WFA(const char* varname, const std::vector<float>& v, MVOdbError* error) { SetOk(error); };
554 void WSA(const char* varname, const std::vector<std::string>& data, int odb_string_length, MVOdbError* error) { SetOk(error); };
555 void WU16A(const char* varname, const std::vector<uint16_t>& v, MVOdbError* error) { SetOk(error); };
556 void WU32A(const char* varname, const std::vector<uint32_t>& v, MVOdbError* error) { SetOk(error); };
557 void WU64A(const char* varname, const std::vector<uint64_t>& v, MVOdbError* error) { SetOk(error); };
558
559 void WBAI(const char* varname, int index, bool v, MVOdbError* error) { SetOk(error); };
560 void WIAI(const char* varname, int index, int v, MVOdbError* error) { SetOk(error); };
561 void WDAI(const char* varname, int index, double v, MVOdbError* error) { SetOk(error); };
562 void WFAI(const char* varname, int index, float v, MVOdbError* error) { SetOk(error); };
563 void WSAI(const char* varname, int index, const char* v, MVOdbError* error) { SetOk(error); };
564 void WU16AI(const char* varname, int index, uint16_t v, MVOdbError* error) { SetOk(error); };
565 void WU32AI(const char* varname, int index, uint32_t v, MVOdbError* error) { SetOk(error); };
566 void WU64AI(const char* varname, int index, uint64_t v, MVOdbError* error) { SetOk(error); };
567
568 // delete function does nothing
569
570 void Delete(const char* odbname, MVOdbError* error) { SetOk(error); };
571};
572
573template<>
574bool JsonOdb::GetJsonValue<int>(const char* varname, const MJsonNode* node, int* value, MVOdbError* error)
575{
576 switch (node->GetType()) {
577 case MJSON_INT: *value = node->GetInt(); SetOk(error); return true;
578 default: SetWrongType(error, varname, node, "int"); return false;
579 }
580}
581
582template<>
583bool JsonOdb::GetJsonValue<double>(const char* varname, const MJsonNode* node, double* value, MVOdbError* error)
584{
585 switch (node->GetType()) {
586 case MJSON_INT: *value = (double)node->GetInt(); SetOk(error); return true;
587 case MJSON_NUMBER: *value = node->GetDouble(); SetOk(error); return true;
588 default: SetWrongType(error, varname, node, "double"); return false;
589 }
590}
591
592template<>
593bool JsonOdb::GetJsonValue<float>(const char* varname, const MJsonNode* node, float* value, MVOdbError* error)
594{
595 switch (node->GetType()) {
596 case MJSON_INT: *value = (float)node->GetInt(); SetOk(error); return true;
597 case MJSON_NUMBER: *value = node->GetDouble(); SetOk(error); return true;
598 default: SetWrongType(error, varname, node, "float"); return false;
599 }
600}
601
602template<>
603bool JsonOdb::GetJsonValue<bool>(const char* varname, const MJsonNode* node, bool* value, MVOdbError* error)
604{
605 switch (node->GetType()) {
606 //case MJSON_INT: *value = node->GetInt(); SetOk(error); return true;
607 //case MJSON_NUMBER: *value = node->GetDouble(); SetOk(error); return true;
608 case MJSON_BOOL: *value = node->GetBool(); SetOk(error); return true;
609 default: SetWrongType(error, varname, node, "bool"); return false;
610 }
611}
612
613template<>
614bool JsonOdb::GetJsonValue<uint16_t>(const char* varname, const MJsonNode* node, uint16_t* value, MVOdbError* error)
615{
616 switch (node->GetType()) {
617 case MJSON_INT: *value = (0xFFFF & node->GetInt()); SetOk(error); return true;
618 case MJSON_STRING: *value = (0xFFFF & strtoul(node->GetString().c_str(), NULL, 0)); SetOk(error); return true;
619 default: SetWrongType(error, varname, node, "uint16_t"); return false;
620 }
621}
622
623template<>
624bool JsonOdb::GetJsonValue<uint32_t>(const char* varname, const MJsonNode* node, uint32_t* value, MVOdbError* error)
625{
626 switch (node->GetType()) {
627 case MJSON_INT: *value = node->GetInt(); SetOk(error); return true;
628 case MJSON_STRING: *value = strtoul(node->GetString().c_str(), NULL, 0); SetOk(error); return true;
629 default: SetWrongType(error, varname, node, "uint32_t"); return false;
630 }
631}
632
633template<>
634bool JsonOdb::GetJsonValue<uint64_t>(const char* varname, const MJsonNode* node, uint64_t* value, MVOdbError* error)
635{
636 switch (node->GetType()) {
637 case MJSON_INT: *value = node->GetInt(); SetOk(error); return true;
638 case MJSON_STRING:
639 if (sizeof(uint64_t) == sizeof(long))
640 *value = strtoul(node->GetString().c_str(), NULL, 0);
641 else if (sizeof(uint64_t) == sizeof(long long))
642 *value = strtoull(node->GetString().c_str(), NULL, 0);
643 else
644 abort();
645 SetOk(error);
646 return true;
647 default: SetWrongType(error, varname, node, "uint64_t"); return false;
648 }
649}
650
651template<>
652bool JsonOdb::GetJsonValue<std::string>(const char* varname, const MJsonNode* node, std::string* value, MVOdbError* error)
653{
654 switch (node->GetType()) {
655 case MJSON_STRING: *value = node->GetString(); SetOk(error); return true;
656 default: SetWrongType(error, varname, node, "std::string"); return false;
657 }
658}
659
660MVOdb* MakeJsonFileOdb(const char* filename, MVOdbError* error)
661{
662 std::string data;
663
664 {
665 FILE *fp = fopen(filename, "r");
666 if (!fp) {
667 std::string msg;
668 msg += "Cannot open file ";
669 msg += "\"";
670 msg += filename;
671 msg += "\"";
672 msg += " fopen() errno: ";
673 msg += toString(errno);
674 msg += " (";
675 msg += strerror(errno);
676 msg += ")";
677 SetError(error, true, filename, msg);
678 return MakeNullOdb();
679 }
680
681 while (1) {
682 char buf[1024*1024];
683 const char* s = fgets(buf, sizeof(buf), fp);
684 if (!s)
685 break;
686 data += s;
687 }
688
689 fclose(fp);
690 fp = NULL;
691 }
692
693 MJsonNode* root = MJsonNode::Parse(data.c_str());
694 //root->Dump();
695 return new JsonOdb(root, root, error);
696}
697
698MVOdb* MakeJsonBufferOdb(const char* buf, int bufsize, MVOdbError* error)
699{
700 MJsonNode* root = MJsonNode::Parse(buf);
701 //root->Dump();
702 return new JsonOdb(root, root, error);
703 //return MakeNullOdb();
704}
705
706/* emacs
707 * Local Variables:
708 * tab-width: 8
709 * c-basic-offset: 3
710 * indent-tabs-mode: nil
711 * End:
712 */
Access to ODB saved in JSON format inside midas .mid files.
Definition mjsonodb.cxx:31
void WU32AI(const char *varname, int index, uint32_t v, MVOdbError *error)
Definition mjsonodb.cxx:565
void WU64(const char *varname, uint64_t v, MVOdbError *error)
Definition mjsonodb.cxx:548
void WB(const char *varname, bool v, MVOdbError *error)
Definition mjsonodb.cxx:541
void WF(const char *varname, float v, MVOdbError *error)
Definition mjsonodb.cxx:544
void RDA(const char *varname, std::vector< double > *value, bool create, int create_size, MVOdbError *error)
Definition mjsonodb.cxx:403
static const MJsonNode * FindPath(const MJsonNode *dir, const char *path, bool return_key=false)
Follow the ODB path through the JSON tree.
Definition mjsonodb.cxx:112
bool IsReadOnly() const
Definition mjsonodb.cxx:103
void WU16(const char *varname, uint16_t v, MVOdbError *error)
Definition mjsonodb.cxx:546
void WI(const char *varname, int v, MVOdbError *error)
Definition mjsonodb.cxx:542
std::string fPath
Definition mjsonodb.cxx:35
void WD(const char *varname, double v, MVOdbError *error)
Definition mjsonodb.cxx:543
void RU16AI(const char *varname, int index, uint16_t *value, MVOdbError *error)
Definition mjsonodb.cxx:524
void SetNotFound(MVOdbError *error, const char *varname)
Definition mjsonodb.cxx:68
void WBAI(const char *varname, int index, bool v, MVOdbError *error)
Definition mjsonodb.cxx:559
void WIAI(const char *varname, int index, int v, MVOdbError *error)
Definition mjsonodb.cxx:560
void ReadKeyLastWritten(const char *varname, int *last_written, MVOdbError *error)
Definition mjsonodb.cxx:239
void RU64AI(const char *varname, int index, uint64_t *value, MVOdbError *error)
Definition mjsonodb.cxx:534
void WS(const char *varname, const char *v, int string_length, MVOdbError *error)
Definition mjsonodb.cxx:545
bool fPrintError
Definition mjsonodb.cxx:36
const MJsonNode * fRoot
Definition mjsonodb.cxx:33
void RU16A(const char *varname, std::vector< uint16_t > *value, bool create, int create_size, MVOdbError *error)
Definition mjsonodb.cxx:418
void RSAI(const char *varname, int index, std::string *value, MVOdbError *error)
Definition mjsonodb.cxx:519
void RU64(const char *varname, uint64_t *value, bool create, MVOdbError *error)
Definition mjsonodb.cxx:343
void RBA(const char *varname, std::vector< bool > *value, bool create, int create_size, MVOdbError *error)
Definition mjsonodb.cxx:393
void RXA(const char *varname, std::vector< T > *value, MVOdbError *error)
Definition mjsonodb.cxx:349
void RB(const char *varname, bool *value, bool create, MVOdbError *error)
Definition mjsonodb.cxx:308
void WSA(const char *varname, const std::vector< std::string > &data, int odb_string_length, MVOdbError *error)
Definition mjsonodb.cxx:554
void RFA(const char *varname, std::vector< float > *value, bool create, int create_size, MVOdbError *error)
Definition mjsonodb.cxx:408
void RS(const char *varname, std::string *value, bool create, int create_string_length, MVOdbError *error)
Definition mjsonodb.cxx:328
void WU16A(const char *varname, const std::vector< uint16_t > &v, MVOdbError *error)
Definition mjsonodb.cxx:555
void SetPrintError(bool v)
Definition mjsonodb.cxx:58
void Delete(const char *odbname, MVOdbError *error)
Definition mjsonodb.cxx:570
void RU32A(const char *varname, std::vector< uint32_t > *value, bool create, int create_size, MVOdbError *error)
Definition mjsonodb.cxx:423
void ReadKey(const char *varname, int *tid, int *num_values, int *total_size, int *item_size, MVOdbError *error)
Definition mjsonodb.cxx:216
void RXAI(const char *varname, int index, T *value, MVOdbError *error)
Definition mjsonodb.cxx:434
bool GetPrintError() const
Definition mjsonodb.cxx:63
void WBA(const char *varname, const std::vector< bool > &v, MVOdbError *error)
Definition mjsonodb.cxx:550
void RD(const char *varname, double *value, bool create, MVOdbError *error)
Definition mjsonodb.cxx:318
void WFA(const char *varname, const std::vector< float > &v, MVOdbError *error)
Definition mjsonodb.cxx:553
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)
Definition mjsonodb.cxx:257
MVOdb * Chdir(const char *subdir, bool create, MVOdbError *error)
Definition mjsonodb.cxx:177
static int GetInt(const MJsonNode *dir, const char *name, int missing_value)
Definition mjsonodb.cxx:169
void RU16(const char *varname, uint16_t *value, bool create, MVOdbError *error)
Definition mjsonodb.cxx:333
void RU32(const char *varname, uint32_t *value, bool create, MVOdbError *error)
Definition mjsonodb.cxx:338
void WU64A(const char *varname, const std::vector< uint64_t > &v, MVOdbError *error)
Definition mjsonodb.cxx:557
void WU16AI(const char *varname, int index, uint16_t v, MVOdbError *error)
Definition mjsonodb.cxx:564
void RF(const char *varname, float *value, bool create, MVOdbError *error)
Definition mjsonodb.cxx:323
void WDAI(const char *varname, int index, double v, MVOdbError *error)
Definition mjsonodb.cxx:561
void RIAI(const char *varname, int index, int *value, MVOdbError *error)
Definition mjsonodb.cxx:504
void WDA(const char *varname, const std::vector< double > &v, MVOdbError *error)
Definition mjsonodb.cxx:552
void WU32(const char *varname, uint32_t v, MVOdbError *error)
Definition mjsonodb.cxx:547
JsonOdb(MJsonNode *root, const MJsonNode *dir, MVOdbError *error)
Definition mjsonodb.cxx:39
void RSA(const char *varname, std::vector< std::string > *value, bool create, int create_size, int create_string_length, MVOdbError *error)
Definition mjsonodb.cxx:413
void RU64A(const char *varname, std::vector< uint64_t > *value, bool create, int create_size, MVOdbError *error)
Definition mjsonodb.cxx:428
void RI(const char *varname, int *value, bool create, MVOdbError *error)
Definition mjsonodb.cxx:313
void WU64AI(const char *varname, int index, uint64_t v, MVOdbError *error)
Definition mjsonodb.cxx:566
void WSAI(const char *varname, int index, const char *v, MVOdbError *error)
Definition mjsonodb.cxx:563
void RFAI(const char *varname, int index, float *value, MVOdbError *error)
Definition mjsonodb.cxx:514
void SetVarError(MVOdbError *error, const char *varname, std::string msg)
Definition mjsonodb.cxx:78
void WIA(const char *varname, const std::vector< int > &v, MVOdbError *error)
Definition mjsonodb.cxx:551
void WU32A(const char *varname, const std::vector< uint32_t > &v, MVOdbError *error)
Definition mjsonodb.cxx:556
void RBAI(const char *varname, int index, bool *value, MVOdbError *error)
Definition mjsonodb.cxx:499
void RDAI(const char *varname, int index, double *value, MVOdbError *error)
Definition mjsonodb.cxx:509
void RIA(const char *varname, std::vector< int > *value, bool create, int create_size, MVOdbError *error)
Definition mjsonodb.cxx:398
void WFAI(const char *varname, int index, float v, MVOdbError *error)
Definition mjsonodb.cxx:562
void SetWrongType(MVOdbError *error, const char *varname, const MJsonNode *node, const char *wanted_type)
Definition mjsonodb.cxx:87
bool GetJsonValue(const char *varname, const MJsonNode *node, T *value, MVOdbError *error)
const MJsonNode * fDir
Definition mjsonodb.cxx:34
void RU32AI(const char *varname, int index, uint32_t *value, MVOdbError *error)
Definition mjsonodb.cxx:529
Definition mvodb.h:21
std::string GetString() const
find subnode with given name, NULL if not object, NULL is name not found
Definition mjson.cxx:979
#define MJSON_STRING
Definition mjson.h:23
const MJsonNodeVector * GetArray() const
get node type: MJSON_xxx
Definition mjson.cxx:927
int GetType() const
delete a node from an object
Definition mjson.cxx:922
std::vector< MJsonNode * > MJsonNodeVector
Definition mjson.h:34
std::vector< std::string > MJsonStringVector
Definition mjson.h:33
long long GetInt() const
get string value, "" if not string or value is JSON "null"
Definition mjson.cxx:987
double GetDouble() const
get 64-bit long long value, 0 if not an integer or value is JSON "null"
Definition mjson.cxx:1003
#define MJSON_BOOL
Definition mjson.h:26
const MJsonNodeVector * GetObjectNodes() const
get array of object names, NULL if not object, empty array if value is JSON "null"
Definition mjson.cxx:943
#define MJSON_OBJECT
Definition mjson.h:22
#define MJSON_ARRAY
Definition mjson.h:21
bool GetBool() const
get number or integer value, 0 if not a number or value is JSON "null"
Definition mjson.cxx:1029
const MJsonStringVector * GetObjectNames() const
get array value, NULL if not array, empty array if value is JSON "null"
Definition mjson.cxx:935
const MJsonNode * FindObjectNode(const char *name) const
get array of object subnodes, NULL if not object, empty array if value is JSON "null"
Definition mjson.cxx:951
#define MJSON_INT
Definition mjson.h:24
static MJsonNode * Parse(const char *jsonstring)
Definition mjson.cxx:645
#define MJSON_NUMBER
Definition mjson.h:25
static const char * TypeToString(int type)
get error message from MJSON_ERROR nodes
Definition mjson.cxx:1072
void SetError(MVOdbError *error, bool print, const std::string &path, const std::string &message)
Definition mvodb.cxx:72
MVOdb * MakeNullOdb()
Definition nullodb.cxx:137
void SetOk(MVOdbError *error)
Definition mvodb.cxx:33
MVOdb * MakeJsonFileOdb(const char *filename, MVOdbError *error)
Definition mjsonodb.cxx:660
static std::string toString(int i)
Definition mjsonodb.cxx:21
MVOdb * MakeJsonBufferOdb(const char *buf, int bufsize, MVOdbError *error)
Definition mjsonodb.cxx:698