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