17 long getObjectId (
const std::string& fToken) {
18 size_t ipos = fToken.find (
"OID=");
19 if (ipos != std::string::npos) {
20 ipos = fToken.find (
'-', ipos);
21 if (ipos != std::string::npos) {
22 size_t ipos2 = fToken.find (
']', ipos);
23 if (ipos2 != std::string::npos) {
24 while (fToken [++ipos] !=
'0');
25 std::string
id (fToken, ipos, ipos2-ipos);
27 unsigned long result = strtoul (
id.c_str (), &endptr, 16);
28 if (endptr && !*endptr)
return long (result);
35 const char* getTable (
const HcalPedestals* fObject) {
return "HCALPEDESTAL";}
36 const char* getTable (
const HcalGains* fObject) {
return "HCALGAIN";}
42 mEnvironment = oracle::occi::Environment::createEnvironment (oracle::occi::Environment::OBJECT);
44 size_t ipass = fDb.find (
'/');
45 size_t ihost = fDb.find (
'@');
47 if (ipass == std::string::npos || ihost == std::string::npos) {
48 std::cerr <<
"HcalDbPoolOCCI::HcalDbPoolOCCI-> Error in connection string format: " << fDb
49 <<
" Expect user/password@db" << std::endl;
52 std::string
user (fDb, 0, ipass);
53 std::string pass (fDb, ipass+1, ihost-ipass-1);
54 std::string
host (fDb, ihost+1);
61 std::cerr <<
"HcalDbPoolOCCI::HcalDbPoolOCCI exception-> " << sqlExcp.getErrorCode () <<
": " << sqlExcp.what () << std::endl;
69 oracle::occi::Environment::terminateEnvironment (
mEnvironment);
90 std::string sql_query =
"select * from metadata";
92 if (
debug)
std::cout <<
"executing query: \n" << sql_query << std::endl;
96 while (rset->next ()) {
97 std::string
name = rset->getString (1);
98 std::string token = rset->getString (2);
107 std::cerr <<
"HcalDbPoolOCCI::getMetadataToken exception-> " << sqlExcp.getErrorCode () <<
": " << sqlExcp.what () << std::endl;
114 long iovId = getObjectId (fIov);
116 char sql_query [1024];
117 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);
119 if (
debug)
std::cout <<
"executing query: \n" << sql_query << std::endl;
123 while (rset->next ()) {
124 unsigned long runMax = rset->getUInt (1);
125 std::string token = rset->getString (2);
126 if (fRun <= runMax) {
134 std::cerr <<
"HcalDbPoolOCCI::getDataToken exception-> " << sqlExcp.getErrorCode () <<
": " << sqlExcp.what () << std::endl;
140 template <
class T,
class S>
143 if (
debug)
std::cout <<
"HcalDbPoolOCCI::getObjectGeneric-> tag/token: " << fTag <<
'/' << mdToken << std::endl;
144 if (mdToken.empty ())
return false;
146 if (
debug)
std::cout <<
"HcalDbPoolOCCI::getObjectGeneric-> Run/token: " << fRun <<
'/' << objToken << std::endl;
147 if (objToken.empty ())
return false;
148 long id = getObjectId (objToken);
150 char sql_query [1024];
151 const char*
name = getTable (fObject);
152 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",
153 name, name, name, name, name, name,
id, name);
155 if (
debug)
std::cout <<
"executing query: \n" << sql_query << std::endl;
159 while (rset->next ()) {
160 unsigned long hcalId = rset->getUInt (1);
162 for (
int i = 0;
i < 4;
i++) values [
i] = rset->getFloat (
i+2);
164 fCondObject =
new S(
DetId (hcalId), values[0], values[1], values[2], values[3]);
165 fObject->addValues (*fCondObject);
174 std::cerr <<
"HcalDbPoolOCCI::getObjectn exception-> " << sqlExcp.getErrorCode () <<
": " << sqlExcp.what () << std::endl;
std::string getDataToken(const std::string &fIov, unsigned long fRun)
bool getObject(HcalPedestals *fObject, const std::string &fTag, unsigned long fRun)
oracle::occi::SQLException SQLException
oracle::occi::Connection * mConnect
bool getObjectGeneric(T *fObject, S *fCondObject, const std::string &fTag, unsigned long fRun)
oracle::occi::Environment * mEnvironment
std::string getMetadataToken(const std::string &fTag)
oracle::occi::Statement * mStatement
oracle::occi::ResultSet ResultSet
HcalDbPoolOCCI(const std::string &fDb)