00001
00006 #include <string>
00007 #include <iostream>
00008 #include "calibUtil/Metadata.h"
00009
00010 void gotIt(unsigned int ser, const std::string& dataFmt,
00011 const std::string& fmtVersion, const std::string& dataIdent);
00012
00013 calibUtil::Metadata::eRet lookup(const std::string& ctype,
00014 const facilities::Timestamp& ts,
00015 unsigned int levelMask,
00016 const std::string& inst);
00017
00018 calibUtil::Metadata::eRet soonest(const std::string& ctype,
00019 const facilities::Timestamp& update_start,
00020 const facilities::Timestamp& update_end,
00021 unsigned int levelMask,
00022 const std::string& inst,
00023 const std::string& flavor
00024 = std::string("VANILLA"));
00025
00026 void compatibility();
00027
00028 int main(int, char**) {
00029 using calibUtil::Metadata;
00030 using facilities::Timestamp;
00031
00032
00033
00034
00035 Timestamp t_ok("2001-11-10 08:00");
00036 Timestamp t_none("2000-09-08 10:00");
00037 Timestamp t_late("2010-12-19");
00038
00039 Metadata::eRet ret = lookup("TKR_DeadChan", t_ok,
00040 Metadata::LEVELDev | Metadata::LEVELTest,
00041 "BTEM");
00042
00043 ret = soonest("TKR_DeadChan", t_none, t_late,
00044 Metadata::LEVELDev | Metadata::LEVELTest,
00045 "BTEM");
00046
00047 ret = soonest("TKR_DeadChan", t_none, t_late,
00048 Metadata::LEVELDev | Metadata::LEVELTest,
00049 "BTEM", "invisible");
00050
00051 ret = lookup("TKR_DeadChan", t_ok,
00052 Metadata::LEVELProd | Metadata::LEVELDev, "BTEM");
00053
00054 ret = lookup("ACD_Eff", t_ok,
00055 Metadata::LEVELProd | Metadata::LEVELDev,
00056 "BTEM");
00057 ret = lookup("TKR_HotChan", t_none, Metadata::LEVELDev,
00058 "BTEM");
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 return(ret);
00099
00100 }
00101
00102
00103 void gotIt(unsigned int ser, const std::string& dataFmt,
00104 const std::string& fmtVersion, const std::string& dataIdent) {
00105
00106 std::cout << "Success reading info for record #" << ser << std::endl;
00107
00108 std::cout << "Data format = " << dataFmt << std::endl;
00109 std::cout << "Format version = " << fmtVersion << std::endl;
00110 std::cout << "Data ident = " << dataIdent << std::endl;
00111 }
00112
00113 calibUtil::Metadata::eRet lookup(const std::string& ctype,
00114 const facilities::Timestamp& ts,
00115 unsigned int levelMask,
00116 const std::string& inst) {
00117 using calibUtil::Metadata;
00118 unsigned int ser;
00119
00120 std::cout << std::endl;
00121 std::cout << "lookup called with input " << std::endl;
00122 std::cout << " calibType = " << ctype <<std::endl;
00123 std::cout << " timestamp = " << ts.getString() << std::endl;
00124 std::cout << " levelMask = " << levelMask << std::endl;
00125 std::cout << " instrument = " << inst << std::endl;
00126
00127 Metadata meta("*", "*", "calib_test");
00128 Metadata::eRet ret = meta.findBest(&ser, ctype, ts, levelMask, inst);
00129
00130 if (ret != Metadata::RETOk) {
00131 std::cout << "findBest failed with status" << (int) ret << std::endl;
00132 }
00133 else if (!ser) {
00134 std::cout << "Query succeeded; no rows found." << std::endl;
00135 }
00136 else {
00137 std::string fmtVersion;
00138 std::string dataFmt;
00139 std::string dataIdent;
00140
00141 ret = meta.getReadInfo(ser, dataFmt, fmtVersion, dataIdent);
00142
00143 if (ret == Metadata::RETOk) {
00144 gotIt(ser, dataFmt, fmtVersion, dataIdent);
00145 }
00146
00147 else {
00148 std::cout << "Failed reading info for record #" << ser;
00149 std::cout << " with code " << (int) ret << std::endl;
00150 }
00151 }
00152
00153 return ret;
00154 }
00155
00156 calibUtil::Metadata::eRet soonest(const std::string& ctype,
00157 const facilities::Timestamp& update_start,
00158 const facilities::Timestamp& update_end,
00159 unsigned int levelMask,
00160 const std::string& inst,
00161 const std::string& flavor) {
00162 using calibUtil::Metadata;
00163 unsigned int ser;
00164
00165
00166 std::cout << std::endl;
00167 std::cout << "soonest called with input " << std::endl;
00168 std::cout << " calibType = " << ctype <<std::endl;
00169 std::cout << " update_start = " << update_start.getString() << std::endl;
00170 std::cout << " update_end = " << update_end.getString() << std::endl;
00171 std::cout << " levelMask = " << levelMask << std::endl;
00172 std::cout << " instrument = " << inst << std::endl;
00173 std::cout << " flavor = " << flavor << std::endl;
00174
00175 Metadata meta("*", "*", "calib_test");
00176 Metadata::eRet ret = meta.findSoonAfter(&ser, ctype, &update_start,
00177 &update_end, levelMask, inst, flavor);
00178
00179 if (ret != Metadata::RETOk) {
00180 std::cout << "findSoonAfter failed with status" << (int) ret << std::endl;
00181 }
00182 else if (!ser) {
00183 std::cout << "Query succeeded; no rows found." << std::endl;
00184 }
00185 else {
00186 std::string fmtVersion;
00187 std::string dataFmt;
00188 std::string dataIdent;
00189
00190 ret = meta.getReadInfo(ser, dataFmt, fmtVersion, dataIdent);
00191
00192 if (ret == Metadata::RETOk) {
00193 gotIt(ser, dataFmt, fmtVersion, dataIdent);
00194 }
00195
00196 else {
00197 std::cout << "Failed reading info for record #" << ser;
00198 std::cout << " with code " << (int) ret << std::endl;
00199 }
00200 }
00201
00202 return ret;
00203 }