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

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 91 of file test_meta.cxx.

92 {
93
94 std::cout << "Success reading info for record #" << ser << std::endl;
95
96 std::cout << "Data format = " << dataFmt << std::endl;
97 std::cout << "Format version = " << fmtVersion << std::endl;
98 std::cout << "Data ident = " << dataIdent << std::endl;
99}

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 101 of file test_meta.cxx.

102 {
104 unsigned int ser;
105
106 std::cout << std::endl;
107 std::cout << "lookup called with input " << std::endl;
108 std::cout << " calibType = " << ctype << std::endl;
109 std::cout << " timestamp = " << ts.getString() << std::endl;
110 std::cout << " levelMask = " << levelMask << std::endl;
111 std::cout << " instrument = " << inst << std::endl;
112
113 Metadata meta( "*", "*", "calib_test" );
114 Metadata::eRet ret = meta.findBest( &ser, ctype, ts, levelMask, inst );
115
116 if ( ret != Metadata::RETOk )
117 { std::cout << "findBest failed with status" << (int)ret << std::endl; }
118 else if ( !ser ) { std::cout << "Query succeeded; no rows found." << std::endl; }
119 else
120 {
121 std::string fmtVersion;
122 std::string dataFmt;
123 std::string dataIdent;
124
125 ret = meta.getReadInfo( ser, dataFmt, fmtVersion, dataIdent );
126
127 if ( ret == Metadata::RETOk ) { gotIt( ser, dataFmt, fmtVersion, dataIdent ); }
128
129 else
130 {
131 std::cout << "Failed reading info for record #" << ser;
132 std::cout << " with code " << (int)ret << std::endl;
133 }
134 }
135
136 return ret;
137}
double meta
std::string getString() const
Return string representation of time, not including nanoseconds;.
Definition Timestamp.cxx:87
void gotIt(unsigned int ser, const std::string &dataFmt, const std::string &fmtVersion, const std::string &dataIdent)
Definition test_meta.cxx:91

Referenced by main().

◆ main()

int main ( int ,
char **  )

Definition at line 25 of file test_meta.cxx.

25 {
28
29 // just for exercise..
30 // compatibility();
31
32 Timestamp t_ok( "2001-11-10 08:00" );
33 Timestamp t_none( "2000-09-08 10:00" );
34 Timestamp t_late( "2010-12-19" );
35
36 Metadata::eRet ret =
37 lookup( "TKR_DeadChan", t_ok, Metadata::LEVELDev | Metadata::LEVELTest, "BTEM" );
38
39 ret = soonest( "TKR_DeadChan", t_none, t_late, Metadata::LEVELDev | Metadata::LEVELTest,
40 "BTEM" );
41
42 ret = soonest( "TKR_DeadChan", t_none, t_late, Metadata::LEVELDev | Metadata::LEVELTest,
43 "BTEM", "invisible" );
44
45 ret = lookup( "TKR_DeadChan", t_ok, Metadata::LEVELProd | Metadata::LEVELDev, "BTEM" );
46
47 ret = lookup( "ACD_Eff", t_ok, Metadata::LEVELProd | Metadata::LEVELDev, "BTEM" );
48 ret = lookup( "TKR_HotChan", t_none, Metadata::LEVELDev, "BTEM" );
49
50 // Try to insert a record
51 /*
52 ret = meta.openRecord(Metadata::INSTEm, Metadata::CTYPE_TKRHotChan,
53 Metadata::FMTXml, "1.0",
54 "$CALIBUTILROOT/xml/test/testHot-2002-05-02.xml",
55 Metadata::CMPLOk);
56 if (ret) {
57 std::cerr << "openRecord failed with return value " << (int) ret
58 << std::endl;
59 return ret;
60 }
61 ret =
62 meta.addInputDesc("This is the standard invented hot strips file");
63 if (ret) {
64 std::cerr << "Bad return from addInputDesc: " << (int) ret << std::endl;
65 return ret;
66 }
67 ret = meta.addNotes("Fake record, added from test_meta");
68 if (ret) {
69 std::cerr << "Bad return from addNotes: " << (int) ret << std::endl;
70 return ret;
71 }
72 ret = meta.addValidInterval(Timestamp(2000, 8, 2), Timestamp());
73 if (ret) {
74 std::cerr << "Bad return from addValidInterval: " << (int) ret
75 << std::endl;
76 return ret;
77 }
78 unsigned int newSerial;
79 ret = meta.insertRecord(&newSerial);
80 if (ret) {
81 std::cerr << "Bad return from insertRecord: " << (int) ret << std::endl;
82 }
83 else {
84 std::cout << "Successfully inserted new record, serial number "
85 << newSerial << std::endl;
86 }
87 */
88 return ( ret );
89}
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"))

◆ 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 139 of file test_meta.cxx.

143 {
145 unsigned int ser;
146
147 std::cout << std::endl;
148 std::cout << "soonest called with input " << std::endl;
149 std::cout << " calibType = " << ctype << std::endl;
150 std::cout << " update_start = " << update_start.getString() << std::endl;
151 std::cout << " update_end = " << update_end.getString() << std::endl;
152 std::cout << " levelMask = " << levelMask << std::endl;
153 std::cout << " instrument = " << inst << std::endl;
154 std::cout << " flavor = " << flavor << std::endl;
155
156 Metadata meta( "*", "*", "calib_test" );
157 Metadata::eRet ret =
158 meta.findSoonAfter( &ser, ctype, &update_start, &update_end, levelMask, inst, flavor );
159
160 if ( ret != Metadata::RETOk )
161 { std::cout << "findSoonAfter failed with status" << (int)ret << std::endl; }
162 else if ( !ser ) { std::cout << "Query succeeded; no rows found." << std::endl; }
163 else
164 {
165 std::string fmtVersion;
166 std::string dataFmt;
167 std::string dataIdent;
168
169 ret = meta.getReadInfo( ser, dataFmt, fmtVersion, dataIdent );
170
171 if ( ret == Metadata::RETOk ) { gotIt( ser, dataFmt, fmtVersion, dataIdent ); }
172
173 else
174 {
175 std::cout << "Failed reading info for record #" << ser;
176 std::cout << " with code " << (int)ret << std::endl;
177 }
178 }
179
180 return ret;
181}

Referenced by main().