Gather conditions data from online DB. More...
#include <HcalDbPoolOCCI.h>
Public Member Functions | |
bool | getObject (HcalPedestals *fObject, const std::string &fTag, unsigned long fRun) |
bool | getObject (HcalElectronicsMap *fObject, const std::string &fTag, unsigned long fRun) |
bool | getObject (HcalGains *fObject, const std::string &fTag, unsigned long fRun) |
HcalDbPoolOCCI (const std::string &fDb) | |
~HcalDbPoolOCCI () | |
Private Member Functions | |
std::string | getDataToken (const std::string &fIov, unsigned long fRun) |
std::string | getMetadataToken (const std::string &fTag) |
template<class T , class S > | |
bool | getObjectGeneric (T *fObject, S *fCondObject, const std::string &fTag, unsigned long fRun) |
Private Attributes | |
oracle::occi::Connection * | mConnect |
oracle::occi::Environment * | mEnvironment |
oracle::occi::Statement * | mStatement |
Gather conditions data from online DB.
Definition at line 33 of file HcalDbPoolOCCI.h.
HcalDbPoolOCCI::HcalDbPoolOCCI | ( | const std::string & | fDb | ) |
Definition at line 39 of file HcalDbPoolOCCI.cc.
References benchmark_cfg::cerr, query::host, mConnect, mEnvironment, mStatement, and hcal_dqm_sourceclient-file_cfg::user.
: mConnect (0) { mEnvironment = oracle::occi::Environment::createEnvironment (oracle::occi::Environment::OBJECT); // decode connect string size_t ipass = fDb.find ('/'); size_t ihost = fDb.find ('@'); if (ipass == std::string::npos || ihost == std::string::npos) { std::cerr << "HcalDbPoolOCCI::HcalDbPoolOCCI-> Error in connection string format: " << fDb << " Expect user/password@db" << std::endl; } else { std::string user (fDb, 0, ipass); std::string pass (fDb, ipass+1, ihost-ipass-1); std::string host (fDb, ihost+1); // if (debug) std::cout << "HcalDbPoolOCCI::HcalDbPoolOCCI-> Connecting " << user << '/' << pass << '@' << host << std::endl; try { mConnect = mEnvironment->createConnection(user, pass, host); mStatement = mConnect->createStatement (); } catch (oracle::occi::SQLException& sqlExcp) { std::cerr << "HcalDbPoolOCCI::HcalDbPoolOCCI exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl; } } }
HcalDbPoolOCCI::~HcalDbPoolOCCI | ( | ) |
Definition at line 66 of file HcalDbPoolOCCI.cc.
References mConnect, mEnvironment, and mStatement.
{ delete mStatement; mEnvironment->terminateConnection (mConnect); oracle::occi::Environment::terminateEnvironment (mEnvironment); }
std::string HcalDbPoolOCCI::getDataToken | ( | const std::string & | fIov, |
unsigned long | fRun | ||
) | [private] |
Definition at line 112 of file HcalDbPoolOCCI.cc.
References benchmark_cfg::cerr, gather_cfg::cout, debug, mStatement, and query::result.
Referenced by getObjectGeneric().
{ std::string result = ""; long iovId = getObjectId (fIov); if (iovId >= 0) { char sql_query [1024]; sprintf (sql_query, "select IOV_IOV_UNSIGNED_LONG, IOV_IOV_STRING from COND__IOV_IOV where ID_ID = %ld ORDER BY IOV_IOV_UNSIGNED_LONG DESC", iovId); try { if (debug) std::cout << "executing query: \n" << sql_query << std::endl; mStatement->setPrefetchRowCount (100); mStatement->setSQL (std::string (sql_query)); oracle::occi::ResultSet* rset = mStatement->executeQuery (); while (rset->next ()) { unsigned long runMax = rset->getUInt (1); std::string token = rset->getString (2); if (fRun <= runMax) { result = token; break; } } delete rset; } catch (oracle::occi::SQLException& sqlExcp) { std::cerr << "HcalDbPoolOCCI::getDataToken exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl; } } return result; }
std::string HcalDbPoolOCCI::getMetadataToken | ( | const std::string & | fTag | ) | [private] |
Definition at line 88 of file HcalDbPoolOCCI.cc.
References benchmark_cfg::cerr, gather_cfg::cout, debug, mStatement, mergeVDriftHistosByStation::name, and query::result.
Referenced by getObjectGeneric().
{ std::string result = ""; std::string sql_query = "select * from metadata"; try { if (debug) std::cout << "executing query: \n" << sql_query << std::endl; mStatement->setPrefetchRowCount (100); mStatement->setSQL (sql_query); oracle::occi::ResultSet* rset = mStatement->executeQuery (); while (rset->next ()) { std::string name = rset->getString (1); std::string token = rset->getString (2); if (name == fTag) { result = token; break; } } delete rset; } catch (oracle::occi::SQLException& sqlExcp) { std::cerr << "HcalDbPoolOCCI::getMetadataToken exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl; } return result; }
bool HcalDbPoolOCCI::getObject | ( | HcalPedestals * | fObject, |
const std::string & | fTag, | ||
unsigned long | fRun | ||
) |
Definition at line 72 of file HcalDbPoolOCCI.cc.
References getObjectGeneric().
{ HcalPedestal* myped(0); return getObjectGeneric (fObject, myped, fTag, fRun); }
bool HcalDbPoolOCCI::getObject | ( | HcalGains * | fObject, |
const std::string & | fTag, | ||
unsigned long | fRun | ||
) |
Definition at line 77 of file HcalDbPoolOCCI.cc.
References getObjectGeneric().
{ HcalGain* mygain(0); return getObjectGeneric (fObject, mygain, fTag, fRun); }
bool HcalDbPoolOCCI::getObject | ( | HcalElectronicsMap * | fObject, |
const std::string & | fTag, | ||
unsigned long | fRun | ||
) |
Definition at line 82 of file HcalDbPoolOCCI.cc.
{ return false; }
bool HcalDbPoolOCCI::getObjectGeneric | ( | T * | fObject, |
S * | fCondObject, | ||
const std::string & | fTag, | ||
unsigned long | fRun | ||
) | [private] |
Definition at line 141 of file HcalDbPoolOCCI.cc.
References benchmark_cfg::cerr, gather_cfg::cout, debug, getDataToken(), getMetadataToken(), i, mStatement, mergeVDriftHistosByStation::name, and makeHLTPrescaleTable::values.
Referenced by getObject().
{ std::string mdToken = getMetadataToken (fTag); if (debug) std::cout << "HcalDbPoolOCCI::getObjectGeneric-> tag/token: " << fTag << '/' << mdToken << std::endl; if (mdToken.empty ()) return false; std::string objToken = getDataToken (mdToken, fRun); if (debug) std::cout << "HcalDbPoolOCCI::getObjectGeneric-> Run/token: " << fRun << '/' << objToken << std::endl; if (objToken.empty ()) return false; long id = getObjectId (objToken); if (id >= 0) { char sql_query [1024]; const char* name = getTable (fObject); sprintf (sql_query, "select MITEMS_%s_MID, MITEMS_%s_MVALUE1, MITEMS_%s_MVALUE2, MITEMS_%s_MVALUE3, MITEMS_%s_MVALUE4 from %sS_MITEMS where ID_ID = %ld ORDER BY MITEMS_%s_MID", name, name, name, name, name, name, id, name); try { if (debug) std::cout << "executing query: \n" << sql_query << std::endl; mStatement->setPrefetchRowCount (100); mStatement->setSQL (sql_query); oracle::occi::ResultSet* rset = mStatement->executeQuery (); while (rset->next ()) { unsigned long hcalId = rset->getUInt (1); float values [4]; for (int i = 0; i < 4; i++) values [i] = rset->getFloat (i+2); fCondObject = new S(DetId (hcalId), values[0], values[1], values[2], values[3]); fObject->addValues (*fCondObject); delete fCondObject; // if (debug) std::cout << "new entry: " << hcalId << '/' << values [0] << '/' << values [1] << '/' // << values [2] << '/' << values [3] << std::endl; } delete rset; return true; } catch (oracle::occi::SQLException& sqlExcp) { std::cerr << "HcalDbPoolOCCI::getObjectn exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl; } } return false; }
oracle::occi::Connection* HcalDbPoolOCCI::mConnect [private] |
Definition at line 43 of file HcalDbPoolOCCI.h.
Referenced by HcalDbPoolOCCI(), and ~HcalDbPoolOCCI().
oracle::occi::Environment* HcalDbPoolOCCI::mEnvironment [private] |
Definition at line 42 of file HcalDbPoolOCCI.h.
Referenced by HcalDbPoolOCCI(), and ~HcalDbPoolOCCI().
oracle::occi::Statement* HcalDbPoolOCCI::mStatement [private] |
Definition at line 44 of file HcalDbPoolOCCI.h.
Referenced by getDataToken(), getMetadataToken(), getObjectGeneric(), HcalDbPoolOCCI(), and ~HcalDbPoolOCCI().