BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
test_meta.cxx File Reference
#include <string>
#include <iostream>
#include "calibUtil/Metadata.h"

Go to the source code of this file.

Functions

void gotIt (unsigned int ser, const std::string &dataFmt, const std::string &fmtVersion, const std::string &dataIdent)
 
calibUtil::Metadata::eRet lookup (const std::string &ctype, const facilities::Timestamp &ts, unsigned int levelMask, const std::string &inst)
 
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"))
 
void compatibility ()
 
int main (int, char **)
 

Detailed Description

Sample program to add record(s) to the MySQL database. For now user only gets to specify instrument type location of file validity start and end times

Ultimately need something more flexible and easier to use.

Sample program to exercise calibration metadata database services

Definition in file test_meta.cxx.

Function Documentation

◆ compatibility()

void compatibility ( )

◆ gotIt()

void gotIt ( unsigned int  ser,
const std::string &  dataFmt,
const std::string &  fmtVersion,
const std::string &  dataIdent 
)

Definition at line 103 of file test_meta.cxx.

104 {
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}

Referenced by lookup(), and soonest().

◆ lookup()

calibUtil::Metadata::eRet lookup ( const std::string &  ctype,
const facilities::Timestamp ts,
unsigned int  levelMask,
const std::string &  inst 
)

Definition at line 113 of file test_meta.cxx.

116 {
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}
double meta
std::string getString() const
Return string representation of time, not including nanoseconds;.
Definition: Timestamp.cxx:92
void gotIt(unsigned int ser, const std::string &dataFmt, const std::string &fmtVersion, const std::string &dataIdent)
Definition: test_meta.cxx:103

Referenced by main().

◆ main()

int main ( int  ,
char **   
)

Definition at line 28 of file test_meta.cxx.

28 {
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}
calibUtil::Metadata::eRet lookup(const std::string &ctype, const facilities::Timestamp &ts, unsigned int levelMask, const std::string &inst)
Definition: test_meta.cxx:113
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

◆ soonest()

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 at line 156 of file test_meta.cxx.

161 {
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}

Referenced by main().