BOSS 8.0.0
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
2// 06:12:26 maqm Exp $
3/** @file test_meta.cxx
4 Sample program to exercise calibration metadata database services
5*/
6
7#include "calibUtil/Metadata.h"
8#include <iostream>
9#include <string>
10
11void gotIt( unsigned int ser, const std::string& dataFmt, const std::string& fmtVersion,
12 const std::string& dataIdent );
13
14calibUtil::Metadata::eRet lookup( const std::string& ctype, const facilities::Timestamp& ts,
15 unsigned int levelMask, const std::string& inst );
16
17calibUtil::Metadata::eRet soonest( const std::string& ctype,
18 const facilities::Timestamp& update_start,
19 const facilities::Timestamp& update_end,
20 unsigned int levelMask, const std::string& inst,
21 const std::string& flavor = std::string( "VANILLA" ) );
22
24
25int main( int, char** ) {
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}
90
91void gotIt( unsigned int ser, const std::string& dataFmt, const std::string& fmtVersion,
92 const std::string& dataIdent ) {
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}
100
101calibUtil::Metadata::eRet lookup( const std::string& ctype, const facilities::Timestamp& ts,
102 unsigned int levelMask, const std::string& inst ) {
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}
138
139calibUtil::Metadata::eRet soonest( const std::string& ctype,
140 const facilities::Timestamp& update_start,
141 const facilities::Timestamp& update_end,
142 unsigned int levelMask, const std::string& inst,
143 const std::string& flavor ) {
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}
double meta
std::string getString() const
Return string representation of time, not including nanoseconds;.
Definition Timestamp.cxx:87
int main()
Definition phokhara.cc:42
void gotIt(unsigned int ser, const std::string &dataFmt, const std::string &fmtVersion, const std::string &dataIdent)
Definition test_meta.cxx:91
calibUtil::Metadata::eRet lookup(const std::string &ctype, const facilities::Timestamp &ts, unsigned int levelMask, const std::string &inst)
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"))