BOSS 7.0.1
BESIII Offline Software System
Loading...
Searching...
No Matches
test_meta.cxx
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/calibUtil/src/test/test_meta.cxx,v 1.1.1.1 2005/10/17 06:12:26 maqm Exp $
2/** @file test_meta.cxx
3 Sample program to exercise calibration metadata database services
4*/
5
6#include <string>
7#include <iostream>
8#include "calibUtil/Metadata.h"
9
10void gotIt(unsigned int ser, const std::string& dataFmt,
11 const std::string& fmtVersion, const std::string& dataIdent);
12
13calibUtil::Metadata::eRet lookup(const std::string& ctype,
14 const facilities::Timestamp& ts,
15 unsigned int levelMask,
16 const std::string& inst);
17
18calibUtil::Metadata::eRet soonest(const std::string& ctype,
19 const facilities::Timestamp& update_start,
20 const facilities::Timestamp& update_end,
21 unsigned int levelMask,
22 const std::string& inst,
23 const std::string& flavor
24 = std::string("VANILLA"));
25
27
28int main(int, char**) {
31
32 // just for exercise..
33 // compatibility();
34
35 Timestamp t_ok("2001-11-10 08:00");
36 Timestamp t_none("2000-09-08 10:00");
37 Timestamp t_late("2010-12-19");
38
39 Metadata::eRet ret = lookup("TKR_DeadChan", t_ok,
40 Metadata::LEVELDev | Metadata::LEVELTest,
41 "BTEM");
42
43 ret = soonest("TKR_DeadChan", t_none, t_late,
44 Metadata::LEVELDev | Metadata::LEVELTest,
45 "BTEM");
46
47 ret = soonest("TKR_DeadChan", t_none, t_late,
48 Metadata::LEVELDev | Metadata::LEVELTest,
49 "BTEM", "invisible");
50
51 ret = lookup("TKR_DeadChan", t_ok,
52 Metadata::LEVELProd | Metadata::LEVELDev, "BTEM");
53
54 ret = lookup("ACD_Eff", t_ok,
55 Metadata::LEVELProd | Metadata::LEVELDev,
56 "BTEM");
57 ret = lookup("TKR_HotChan", t_none, Metadata::LEVELDev,
58 "BTEM");
59
60 // Try to insert a record
61 /*
62 ret = meta.openRecord(Metadata::INSTEm, Metadata::CTYPE_TKRHotChan,
63 Metadata::FMTXml, "1.0",
64 "$CALIBUTILROOT/xml/test/testHot-2002-05-02.xml",
65 Metadata::CMPLOk);
66 if (ret) {
67 std::cerr << "openRecord failed with return value " << (int) ret
68 << std::endl;
69 return ret;
70 }
71 ret =
72 meta.addInputDesc("This is the standard invented hot strips file");
73 if (ret) {
74 std::cerr << "Bad return from addInputDesc: " << (int) ret << std::endl;
75 return ret;
76 }
77 ret = meta.addNotes("Fake record, added from test_meta");
78 if (ret) {
79 std::cerr << "Bad return from addNotes: " << (int) ret << std::endl;
80 return ret;
81 }
82 ret = meta.addValidInterval(Timestamp(2000, 8, 2), Timestamp());
83 if (ret) {
84 std::cerr << "Bad return from addValidInterval: " << (int) ret
85 << std::endl;
86 return ret;
87 }
88 unsigned int newSerial;
89 ret = meta.insertRecord(&newSerial);
90 if (ret) {
91 std::cerr << "Bad return from insertRecord: " << (int) ret << std::endl;
92 }
93 else {
94 std::cout << "Successfully inserted new record, serial number "
95 << newSerial << std::endl;
96 }
97 */
98 return(ret);
99
100}
101
102
103void gotIt(unsigned int ser, const std::string& dataFmt,
104 const std::string& fmtVersion, const std::string& dataIdent) {
105
106 std::cout << "Success reading info for record #" << ser << std::endl;
107
108 std::cout << "Data format = " << dataFmt << std::endl;
109 std::cout << "Format version = " << fmtVersion << std::endl;
110 std::cout << "Data ident = " << dataIdent << std::endl;
111}
112
113calibUtil::Metadata::eRet lookup(const std::string& ctype,
114 const facilities::Timestamp& ts,
115 unsigned int levelMask,
116 const std::string& inst) {
118 unsigned int ser;
119
120 std::cout << std::endl;
121 std::cout << "lookup called with input " << std::endl;
122 std::cout << " calibType = " << ctype <<std::endl;
123 std::cout << " timestamp = " << ts.getString() << std::endl;
124 std::cout << " levelMask = " << levelMask << std::endl;
125 std::cout << " instrument = " << inst << std::endl;
126
127 Metadata meta("*", "*", "calib_test");
128 Metadata::eRet ret = meta.findBest(&ser, ctype, ts, levelMask, inst);
129
130 if (ret != Metadata::RETOk) {
131 std::cout << "findBest failed with status" << (int) ret << std::endl;
132 }
133 else if (!ser) {
134 std::cout << "Query succeeded; no rows found." << std::endl;
135 }
136 else {
137 std::string fmtVersion;
138 std::string dataFmt;
139 std::string dataIdent;
140
141 ret = meta.getReadInfo(ser, dataFmt, fmtVersion, dataIdent);
142
143 if (ret == Metadata::RETOk) {
144 gotIt(ser, dataFmt, fmtVersion, dataIdent);
145 }
146
147 else {
148 std::cout << "Failed reading info for record #" << ser;
149 std::cout << " with code " << (int) ret << std::endl;
150 }
151 }
152
153 return ret;
154}
155
156calibUtil::Metadata::eRet soonest(const std::string& ctype,
157 const facilities::Timestamp& update_start,
158 const facilities::Timestamp& update_end,
159 unsigned int levelMask,
160 const std::string& inst,
161 const std::string& flavor) {
163 unsigned int ser;
164
165
166 std::cout << std::endl;
167 std::cout << "soonest called with input " << std::endl;
168 std::cout << " calibType = " << ctype <<std::endl;
169 std::cout << " update_start = " << update_start.getString() << std::endl;
170 std::cout << " update_end = " << update_end.getString() << std::endl;
171 std::cout << " levelMask = " << levelMask << std::endl;
172 std::cout << " instrument = " << inst << std::endl;
173 std::cout << " flavor = " << flavor << std::endl;
174
175 Metadata meta("*", "*", "calib_test");
176 Metadata::eRet ret = meta.findSoonAfter(&ser, ctype, &update_start,
177 &update_end, levelMask, inst, flavor);
178
179 if (ret != Metadata::RETOk) {
180 std::cout << "findSoonAfter failed with status" << (int) ret << std::endl;
181 }
182 else if (!ser) {
183 std::cout << "Query succeeded; no rows found." << std::endl;
184 }
185 else {
186 std::string fmtVersion;
187 std::string dataFmt;
188 std::string dataIdent;
189
190 ret = meta.getReadInfo(ser, dataFmt, fmtVersion, dataIdent);
191
192 if (ret == Metadata::RETOk) {
193 gotIt(ser, dataFmt, fmtVersion, dataIdent);
194 }
195
196 else {
197 std::cout << "Failed reading info for record #" << ser;
198 std::cout << " with code " << (int) ret << std::endl;
199 }
200 }
201
202 return ret;
203}
std::string getString() const
Return string representation of time, not including nanoseconds;.
Definition: Timestamp.cxx:92
int main()
Definition: test_IFile.cxx:11
void gotIt(unsigned int ser, const std::string &dataFmt, const std::string &fmtVersion, const std::string &dataIdent)
Definition: test_meta.cxx:103
calibUtil::Metadata::eRet lookup(const std::string &ctype, const facilities::Timestamp &ts, unsigned int levelMask, const std::string &inst)
Definition: test_meta.cxx:113
void compatibility()
calibUtil::Metadata::eRet soonest(const std::string &ctype, const facilities::Timestamp &update_start, const facilities::Timestamp &update_end, unsigned int levelMask, const std::string &inst, const std::string &flavor=std::string("VANILLA"))
Definition: test_meta.cxx:156