#include <CondTools/Hcal/interface/HcalDbPoolOCCI.h>
Public Member Functions | |
bool | getObject (HcalElectronicsMap *fObject, const std::string &fTag, unsigned long fRun) |
bool | getObject (HcalGains *fObject, const std::string &fTag, unsigned long fRun) |
bool | getObject (HcalPedestals *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 |
Definition at line 33 of file HcalDbPoolOCCI.h.
HcalDbPoolOCCI::HcalDbPoolOCCI | ( | const std::string & | fDb | ) |
Definition at line 38 of file HcalDbPoolOCCI.cc.
References TestMuL1L2Filter_cff::cerr, lat::endl(), cmsBenchmark::host, mConnect, mEnvironment, mStatement, and cmsBenchmark::user.
00039 : mConnect (0) 00040 { 00041 mEnvironment = oracle::occi::Environment::createEnvironment (oracle::occi::Environment::OBJECT); 00042 // decode connect string 00043 unsigned ipass = fDb.find ('/'); 00044 unsigned ihost = fDb.find ('@'); 00045 00046 if (ipass == std::string::npos || ihost == std::string::npos) { 00047 std::cerr << "HcalDbPoolOCCI::HcalDbPoolOCCI-> Error in connection string format: " << fDb 00048 << " Expect user/password@db" << std::endl; 00049 } 00050 else { 00051 std::string user (fDb, 0, ipass); 00052 std::string pass (fDb, ipass+1, ihost-ipass-1); 00053 std::string host (fDb, ihost+1); 00054 // if (debug) std::cout << "HcalDbPoolOCCI::HcalDbPoolOCCI-> Connecting " << user << '/' << pass << '@' << host << std::endl; 00055 try { 00056 mConnect = mEnvironment->createConnection(user, pass, host); 00057 mStatement = mConnect->createStatement (); 00058 } 00059 catch (oracle::occi::SQLException& sqlExcp) { 00060 std::cerr << "HcalDbPoolOCCI::HcalDbPoolOCCI exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl; 00061 } 00062 } 00063 }
HcalDbPoolOCCI::~HcalDbPoolOCCI | ( | ) |
Definition at line 65 of file HcalDbPoolOCCI.cc.
References mConnect, mEnvironment, and mStatement.
00065 { 00066 delete mStatement; 00067 mEnvironment->terminateConnection (mConnect); 00068 oracle::occi::Environment::terminateEnvironment (mEnvironment); 00069 }
std::string HcalDbPoolOCCI::getDataToken | ( | const std::string & | fIov, | |
unsigned long | fRun | |||
) | [private] |
Definition at line 111 of file HcalDbPoolOCCI.cc.
References TestMuL1L2Filter_cff::cerr, GenMuonPlsPt100GeV_cfg::cout, debug, lat::endl(), getObjectId(), mStatement, and HLT_VtxMuL3::result.
Referenced by getObjectGeneric().
00111 { 00112 std::string result = ""; 00113 long iovId = getObjectId (fIov); 00114 if (iovId >= 0) { 00115 char sql_query [1024]; 00116 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); 00117 try { 00118 if (debug) std::cout << "executing query: \n" << sql_query << std::endl; 00119 mStatement->setPrefetchRowCount (100); 00120 mStatement->setSQL (std::string (sql_query)); 00121 oracle::occi::ResultSet* rset = mStatement->executeQuery (); 00122 while (rset->next ()) { 00123 unsigned long runMax = rset->getUInt (1); 00124 std::string token = rset->getString (2); 00125 if (fRun <= runMax) { 00126 result = token; 00127 break; 00128 } 00129 } 00130 delete rset; 00131 } 00132 catch (oracle::occi::SQLException& sqlExcp) { 00133 std::cerr << "HcalDbPoolOCCI::getDataToken exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl; 00134 } 00135 } 00136 return result; 00137 }
std::string HcalDbPoolOCCI::getMetadataToken | ( | const std::string & | fTag | ) | [private] |
Definition at line 87 of file HcalDbPoolOCCI.cc.
References TestMuL1L2Filter_cff::cerr, GenMuonPlsPt100GeV_cfg::cout, debug, lat::endl(), mStatement, name, and HLT_VtxMuL3::result.
Referenced by getObjectGeneric().
00087 { 00088 std::string result = ""; 00089 std::string sql_query = "select * from metadata"; 00090 try { 00091 if (debug) std::cout << "executing query: \n" << sql_query << std::endl; 00092 mStatement->setPrefetchRowCount (100); 00093 mStatement->setSQL (sql_query); 00094 oracle::occi::ResultSet* rset = mStatement->executeQuery (); 00095 while (rset->next ()) { 00096 std::string name = rset->getString (1); 00097 std::string token = rset->getString (2); 00098 if (name == fTag) { 00099 result = token; 00100 break; 00101 } 00102 } 00103 delete rset; 00104 } 00105 catch (oracle::occi::SQLException& sqlExcp) { 00106 std::cerr << "HcalDbPoolOCCI::getMetadataToken exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl; 00107 } 00108 return result; 00109 }
bool HcalDbPoolOCCI::getObject | ( | HcalElectronicsMap * | fObject, | |
const std::string & | fTag, | |||
unsigned long | fRun | |||
) |
bool HcalDbPoolOCCI::getObject | ( | HcalGains * | fObject, | |
const std::string & | fTag, | |||
unsigned long | fRun | |||
) |
Definition at line 76 of file HcalDbPoolOCCI.cc.
References getObjectGeneric().
00076 { 00077 HcalGain* mygain; 00078 return getObjectGeneric (fObject, mygain, fTag, fRun); 00079 }
bool HcalDbPoolOCCI::getObject | ( | HcalPedestals * | fObject, | |
const std::string & | fTag, | |||
unsigned long | fRun | |||
) |
Definition at line 71 of file HcalDbPoolOCCI.cc.
References getObjectGeneric().
00071 { 00072 HcalPedestal* myped; 00073 return getObjectGeneric (fObject, myped, fTag, fRun); 00074 }
bool HcalDbPoolOCCI::getObjectGeneric | ( | T * | fObject, | |
S * | fCondObject, | |||
const std::string & | fTag, | |||
unsigned long | fRun | |||
) | [inline, private] |
Definition at line 140 of file HcalDbPoolOCCI.cc.
References TestMuL1L2Filter_cff::cerr, GenMuonPlsPt100GeV_cfg::cout, debug, lat::endl(), getDataToken(), getMetadataToken(), getObjectId(), getTable(), i, mStatement, name, and values.
Referenced by getObject().
00140 { 00141 std::string mdToken = getMetadataToken (fTag); 00142 if (debug) std::cout << "HcalDbPoolOCCI::getObjectGeneric-> tag/token: " << fTag << '/' << mdToken << std::endl; 00143 if (mdToken.empty ()) return false; 00144 std::string objToken = getDataToken (mdToken, fRun); 00145 if (debug) std::cout << "HcalDbPoolOCCI::getObjectGeneric-> Run/token: " << fRun << '/' << objToken << std::endl; 00146 if (objToken.empty ()) return false; 00147 long id = getObjectId (objToken); 00148 if (id >= 0) { 00149 char sql_query [1024]; 00150 const char* name = getTable (fObject); 00151 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", 00152 name, name, name, name, name, name, id, name); 00153 try { 00154 if (debug) std::cout << "executing query: \n" << sql_query << std::endl; 00155 mStatement->setPrefetchRowCount (100); 00156 mStatement->setSQL (sql_query); 00157 oracle::occi::ResultSet* rset = mStatement->executeQuery (); 00158 while (rset->next ()) { 00159 unsigned long hcalId = rset->getUInt (1); 00160 float values [4]; 00161 for (int i = 0; i < 4; i++) values [i] = rset->getFloat (i+2); 00162 00163 fCondObject = new S(DetId (hcalId), values[0], values[1], values[2], values[3]); 00164 fObject->addValues (*fCondObject); 00165 delete fCondObject; 00166 // if (debug) std::cout << "new entry: " << hcalId << '/' << values [0] << '/' << values [1] << '/' 00167 // << values [2] << '/' << values [3] << std::endl; 00168 } 00169 delete rset; 00170 return true; 00171 } 00172 catch (oracle::occi::SQLException& sqlExcp) { 00173 std::cerr << "HcalDbPoolOCCI::getObjectn exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl; 00174 } 00175 } 00176 return false; 00177 }
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().