ROOTANA
Loading...
Searching...
No Matches
mvodb.cxx
Go to the documentation of this file.
1/********************************************************************\
2
3 Name: mvodb.cxx
4 Created by: K.Olchanski
5
6 Contents: common functions of MVOdb ODB interface
7
8\********************************************************************/
9
10#include <stdio.h> // sprintf(), fprintf()
11
12#include "mvodb.h"
13
15{
16 // empty
17}
18
19static std::string toString(int value)
20{
21 char buf[256];
22 snprintf(buf, sizeof(buf), "%d", value);
23 return buf;
24}
25
27{
28 SetOk(this);
29}
30
31void SetOk(MVOdbError* error)
32{
33 if (error) {
34 error->fError = false;
35 error->fErrorString = "";
36 error->fPath = "";
37 error->fStatus = 0;
38 }
39}
40
41void SetMidasStatus(MVOdbError* error, bool print, const std::string& path, const char* midas_func_name, int status)
42{
43 if (error) {
44 error->fStatus = status;
45 error->fPath = path;
46 if (status == 1) {
47 error->fError = false;
48 error->fErrorString = "";
49 } else {
50 error->fError = true;
51 error->fErrorString = "";
52 error->fErrorString += "MIDAS ";
53 error->fErrorString += midas_func_name;
54 error->fErrorString += "()";
55 error->fErrorString += " at ODB path \"";
56 error->fErrorString += path;
57 error->fErrorString += "\" returned status ";
58 error->fErrorString += toString(status);
59 if (print) {
60 fprintf(stderr, "MVOdb: %s\n", error->fErrorString.c_str());
61 }
62 }
63 } else {
64 if (print) {
65 fprintf(stderr, "MVOdb: Error: MIDAS %s() at ODB path \"%s\" returned status %d\n", midas_func_name, path.c_str(), status);
66 }
67 }
68}
69
70void SetError(MVOdbError* error, bool print, const std::string& path, const std::string& message)
71{
72 if (error) {
73 error->fStatus = 0;
74 error->fPath = path;
75 error->fError = true;
76 error->fErrorString = "";
77 error->fErrorString += message;
78 error->fErrorString += " at ODB path \"";
79 error->fErrorString += path;
80 error->fErrorString += "\"";
81 if (print) {
82 fprintf(stderr, "MVOdb::SetError: %s\n", error->fErrorString.c_str());
83 }
84 } else {
85 if (print) {
86 fprintf(stderr, "MVOdb::SetError: Error: %s at ODB path \"%s\"\n", message.c_str(), path.c_str());
87 }
88 }
89}
90
91MVOdb* MakeFileDumpOdb(const char* buf, int bufsize, MVOdbError* error)
92{
93 //printf("MakeFileDumpOdb: odb dump size %d, first char \'%c\'\n", bufsize, buf[0]);
94 if (buf[0] == '[') {
95 // ODB format
96 char str[256];
97 snprintf(str, sizeof(str), "MakeFileDumpOdb: old ODB dump format is not supported, sorry");
98 SetError(error, false, "buffer", str);
99 return MakeNullOdb();
100 } else if (buf[0] == '<') {
101 // XML format
102 return MakeXmlBufferOdb(buf, bufsize, error);
103 } else if (buf[0] == '{') {
104 // JSON format
105 return MakeJsonBufferOdb(buf, bufsize, error);
106 } else {
107 // unknown format
108 char str[256];
109 snprintf(str, sizeof(str), "MakeFileDumpOdb: unknown ODB dump format, first char is \'%c\' (%d), dump size %d",
110 buf[0], buf[0], bufsize);
111 SetError(error, false, "buffer", str);
112 return MakeNullOdb();
113 }
114}
115
116/* emacs
117 * Local Variables:
118 * tab-width: 8
119 * c-basic-offset: 3
120 * indent-tabs-mode: nil
121 * End:
122 */
std::string fPath
Definition mvodb.h:192
int fStatus
Definition mvodb.h:193
MVOdbError()
Definition mvodb.cxx:26
bool fError
Definition mvodb.h:190
std::string fErrorString
Definition mvodb.h:191
Definition mvodb.h:21
virtual ~MVOdb()=0
Definition mvodb.cxx:14
MVOdb * MakeJsonBufferOdb(const char *buf, int bufsize, MVOdbError *error=NULL)
Definition mjsonodb.cxx:574
MVOdb * MakeXmlBufferOdb(const char *buf, int bufsize, MVOdbError *error=NULL)
Definition mxmlodb.cxx:720
MVOdb * MakeNullOdb()
Definition nullodb.cxx:129
void SetOk(MVOdbError *error)
Definition mvodb.cxx:31
void SetMidasStatus(MVOdbError *error, bool print, const std::string &path, const char *midas_func_name, int status)
Definition mvodb.cxx:41
MVOdb * MakeFileDumpOdb(const char *buf, int bufsize, MVOdbError *error)
Access ODB from a midas file dump. FOrmat could be .xml, .json or .odb.
Definition mvodb.cxx:91
void SetError(MVOdbError *error, bool print, const std::string &path, const std::string &message)
Definition mvodb.cxx:70
void SetOk(MVOdbError *error)
Definition mvodb.cxx:31
static std::string toString(int value)
Definition mvodb.cxx:19