00001 #include "RunTimesFactory.h"
00002
00003 class RunTimesPg : public RunTimes
00004 {
00005 public:
00006 RunTimesPg() {}
00007 virtual ~RunTimesPg() {};
00008
00009 protected:
00010 virtual bool Init();
00011 };
00012
00013 namespace
00014 {
00015 RunTimes* creator()
00016 {
00017 return new RunTimesPg;
00018 }
00019
00020 const std::string name = "Pg";
00021 const bool registered =
00022 RunTimesFactory::instance().registerCreator(name,
00023 creator,
00024 "RunTimes");
00025 }
00026
00027 #include <sstream>
00028
00029 #include "odbc++/connection.h"
00030 #include <odbc++/drivermanager.h>
00031 #include <odbc++/resultset.h>
00032
00033
00034 bool
00035 RunTimesPg::Init()
00036 {
00037 std::cout << "This method needs fixing - it uses the wrong DB" << std::endl;
00038 std::cout << "Tell L.Aphecetche to fix it" << std::endl;
00039 exit(1);
00040
00041 odbc::Connection* con = odbc::DriverManager::getConnection
00042 ("Phenix","phnxrc","phnxdb1.phenix.bnl.gov");
00043
00044 if (!con)
00045 {
00046 std::cerr << "RunTimesPg::Init : could not get connection to postgre Phenix database" << std::endl;
00047 return false;
00048 }
00049
00050 odbc::Statement* stmt = con->createStatement();
00051
00052 std::ostringstream cmd;
00053
00054 cmd << "select runnumber,brunixtime,erunixtime from run where runnumber>="
00055 << fMinRunNumber;
00056
00057 odbc::ResultSet* rs = stmt->executeQuery(cmd.str().c_str());
00058
00059 while ( ( rs->next() ) )
00060 {
00061 PHTimeStamp begin(rs->getInt("brunixtime"));
00062 PHTimeStamp end(rs->getInt("erunixtime"));
00063 int runnumber = rs->getInt("runnumber");
00064 fTimes[runnumber] = new RunLite(runnumber,begin,end);
00065 }
00066
00067 delete rs;
00068 delete con;
00069 odbc::DriverManager::shutdown();
00070
00071 return true;
00072 }