/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Calibration/calibUtil/calibUtil-00-00-43/src/test/test_meta.cxx

Go to the documentation of this file.
00001 // $Header: /bes/bes/BossCvs/Calibration/calibUtil/src/test/test_meta.cxx,v 1.1.1.1 2005/10/17 06:12:26 maqm Exp $
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   // just for exercise..
00033   //  compatibility();
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   // Try to insert a record
00061   /*
00062   ret = meta.openRecord(Metadata::INSTEm, Metadata::CTYPE_TKRHotChan,
00063                    Metadata::FMTXml, "1.0",
00064                    "$CALIBUTILROOT/xml/test/testHot-2002-05-02.xml",
00065                    Metadata::CMPLOk);
00066   if (ret) {
00067     std::cerr << "openRecord failed with return value " << (int) ret 
00068               << std::endl;
00069     return ret;
00070   }
00071   ret = 
00072     meta.addInputDesc("This is the standard invented hot strips file");
00073   if (ret) {
00074     std::cerr << "Bad return from addInputDesc: " << (int) ret << std::endl;
00075     return ret;
00076   }
00077   ret = meta.addNotes("Fake record, added from test_meta");
00078   if (ret) {
00079     std::cerr << "Bad return from addNotes: " << (int) ret << std::endl;
00080     return ret;
00081   }
00082   ret = meta.addValidInterval(Timestamp(2000, 8, 2), Timestamp());
00083   if (ret) {
00084     std::cerr << "Bad return from addValidInterval: " << (int) ret 
00085               << std::endl;
00086     return ret;
00087   }
00088   unsigned int newSerial;
00089   ret = meta.insertRecord(&newSerial);
00090   if (ret) {
00091     std::cerr << "Bad return from insertRecord: " << (int) ret << std::endl;
00092   }
00093   else {
00094     std::cout << "Successfully inserted new record, serial number " 
00095               << newSerial << std::endl;
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 }

Generated on Tue Nov 29 22:57:55 2016 for BOSS_7.0.2 by  doxygen 1.4.7