CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
HcalDbPoolOCCI Class Reference

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 (HcalGains *fObject, const std::string &fTag, unsigned long fRun)
 
bool getObject (HcalElectronicsMap *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
 

Detailed Description

Gather conditions data from online DB.

Author
Fedor Ratnikov

Definition at line 33 of file HcalDbPoolOCCI.h.

Constructor & Destructor Documentation

HcalDbPoolOCCI::HcalDbPoolOCCI ( const std::string &  fDb)

Definition at line 39 of file HcalDbPoolOCCI.cc.

References dtNoiseDBValidation_cfg::cerr, query::host, mConnect, mEnvironment, mStatement, AlCaHLTBitMon_QueryRunRegistry::string, and hcal_dqm_sourceclient-file_cfg::user.

40  : mConnect (0)
41 {
42  mEnvironment = oracle::occi::Environment::createEnvironment (oracle::occi::Environment::OBJECT);
43  // decode connect string
44  size_t ipass = fDb.find ('/');
45  size_t ihost = fDb.find ('@');
46 
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;
50  }
51  else {
52  std::string user (fDb, 0, ipass);
53  std::string pass (fDb, ipass+1, ihost-ipass-1);
54  std::string host (fDb, ihost+1);
55  // if (debug) std::cout << "HcalDbPoolOCCI::HcalDbPoolOCCI-> Connecting " << user << '/' << pass << '@' << host << std::endl;
56  try {
57  mConnect = mEnvironment->createConnection(user, pass, host);
58  mStatement = mConnect->createStatement ();
59  }
60  catch (oracle::occi::SQLException& sqlExcp) {
61  std::cerr << "HcalDbPoolOCCI::HcalDbPoolOCCI exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl;
62  }
63  }
64 }
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
oracle::occi::Connection * mConnect
oracle::occi::Environment * mEnvironment
string host
Definition: query.py:114
oracle::occi::Statement * mStatement
HcalDbPoolOCCI::~HcalDbPoolOCCI ( )

Definition at line 66 of file HcalDbPoolOCCI.cc.

References mConnect, mEnvironment, and mStatement.

66  {
67  delete mStatement;
68  mEnvironment->terminateConnection (mConnect);
69  oracle::occi::Environment::terminateEnvironment (mEnvironment);
70 }
oracle::occi::Connection * mConnect
oracle::occi::Environment * mEnvironment
oracle::occi::Statement * mStatement

Member Function Documentation

std::string HcalDbPoolOCCI::getDataToken ( const std::string &  fIov,
unsigned long  fRun 
)
private

Definition at line 112 of file HcalDbPoolOCCI.cc.

References dtNoiseDBValidation_cfg::cerr, gather_cfg::cout, debug, mStatement, query::result, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by getObjectGeneric().

112  {
113  std::string result = "";
114  long iovId = getObjectId (fIov);
115  if (iovId >= 0) {
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);
118  try {
119  if (debug) std::cout << "executing query: \n" << sql_query << std::endl;
120  mStatement->setPrefetchRowCount (100);
121  mStatement->setSQL (std::string (sql_query));
122  oracle::occi::ResultSet* rset = mStatement->executeQuery ();
123  while (rset->next ()) {
124  unsigned long runMax = rset->getUInt (1);
125  std::string token = rset->getString (2);
126  if (fRun <= runMax) {
127  result = token;
128  break;
129  }
130  }
131  delete rset;
132  }
133  catch (oracle::occi::SQLException& sqlExcp) {
134  std::cerr << "HcalDbPoolOCCI::getDataToken exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl;
135  }
136  }
137  return result;
138 }
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
tuple result
Definition: query.py:137
#define debug
Definition: HDRShower.cc:19
oracle::occi::Statement * mStatement
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
tuple cout
Definition: gather_cfg.py:121
std::string HcalDbPoolOCCI::getMetadataToken ( const std::string &  fTag)
private

Definition at line 88 of file HcalDbPoolOCCI.cc.

References dtNoiseDBValidation_cfg::cerr, gather_cfg::cout, debug, mStatement, mergeVDriftHistosByStation::name, query::result, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by getObjectGeneric().

88  {
89  std::string result = "";
90  std::string sql_query = "select * from metadata";
91  try {
92  if (debug) std::cout << "executing query: \n" << sql_query << std::endl;
93  mStatement->setPrefetchRowCount (100);
94  mStatement->setSQL (sql_query);
95  oracle::occi::ResultSet* rset = mStatement->executeQuery ();
96  while (rset->next ()) {
97  std::string name = rset->getString (1);
98  std::string token = rset->getString (2);
99  if (name == fTag) {
100  result = token;
101  break;
102  }
103  }
104  delete rset;
105  }
106  catch (oracle::occi::SQLException& sqlExcp) {
107  std::cerr << "HcalDbPoolOCCI::getMetadataToken exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl;
108  }
109  return result;
110 }
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
tuple result
Definition: query.py:137
#define debug
Definition: HDRShower.cc:19
oracle::occi::Statement * mStatement
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
tuple cout
Definition: gather_cfg.py:121
bool HcalDbPoolOCCI::getObject ( HcalPedestals fObject,
const std::string &  fTag,
unsigned long  fRun 
)

Definition at line 72 of file HcalDbPoolOCCI.cc.

References getObjectGeneric().

72  {
73  HcalPedestal* myped(0);
74  return getObjectGeneric (fObject, myped, fTag, fRun);
75 }
bool getObjectGeneric(T *fObject, S *fCondObject, const std::string &fTag, unsigned long fRun)
bool HcalDbPoolOCCI::getObject ( HcalGains fObject,
const std::string &  fTag,
unsigned long  fRun 
)

Definition at line 77 of file HcalDbPoolOCCI.cc.

References getObjectGeneric().

77  {
78  HcalGain* mygain(0);
79  return getObjectGeneric (fObject, mygain, fTag, fRun);
80 }
bool getObjectGeneric(T *fObject, S *fCondObject, const std::string &fTag, unsigned long fRun)
bool HcalDbPoolOCCI::getObject ( HcalElectronicsMap fObject,
const std::string &  fTag,
unsigned long  fRun 
)

Definition at line 82 of file HcalDbPoolOCCI.cc.

82  {
83  return false;
84 }
template<class T , class S >
bool HcalDbPoolOCCI::getObjectGeneric ( T fObject,
S *  fCondObject,
const std::string &  fTag,
unsigned long  fRun 
)
private

Definition at line 141 of file HcalDbPoolOCCI.cc.

References dtNoiseDBValidation_cfg::cerr, gather_cfg::cout, debug, getDataToken(), getMetadataToken(), i, mStatement, mergeVDriftHistosByStation::name, AlCaHLTBitMon_QueryRunRegistry::string, and makeHLTPrescaleTable::values.

Referenced by getObject().

141  {
142  std::string mdToken = getMetadataToken (fTag);
143  if (debug) std::cout << "HcalDbPoolOCCI::getObjectGeneric-> tag/token: " << fTag << '/' << mdToken << std::endl;
144  if (mdToken.empty ()) return false;
145  std::string objToken = getDataToken (mdToken, fRun);
146  if (debug) std::cout << "HcalDbPoolOCCI::getObjectGeneric-> Run/token: " << fRun << '/' << objToken << std::endl;
147  if (objToken.empty ()) return false;
148  long id = getObjectId (objToken);
149  if (id >= 0) {
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);
154  try {
155  if (debug) std::cout << "executing query: \n" << sql_query << std::endl;
156  mStatement->setPrefetchRowCount (100);
157  mStatement->setSQL (sql_query);
158  oracle::occi::ResultSet* rset = mStatement->executeQuery ();
159  while (rset->next ()) {
160  unsigned long hcalId = rset->getUInt (1);
161  float values [4];
162  for (int i = 0; i < 4; i++) values [i] = rset->getFloat (i+2);
163 
164  fCondObject = new S(DetId (hcalId), values[0], values[1], values[2], values[3]);
165  fObject->addValues (*fCondObject);
166  delete fCondObject;
167  // if (debug) std::cout << "new entry: " << hcalId << '/' << values [0] << '/' << values [1] << '/'
168  // << values [2] << '/' << values [3] << std::endl;
169  }
170  delete rset;
171  return true;
172  }
173  catch (oracle::occi::SQLException& sqlExcp) {
174  std::cerr << "HcalDbPoolOCCI::getObjectn exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl;
175  }
176  }
177  return false;
178 }
int i
Definition: DBlmapReader.cc:9
std::string getDataToken(const std::string &fIov, unsigned long fRun)
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
std::string getMetadataToken(const std::string &fTag)
Definition: DetId.h:18
#define debug
Definition: HDRShower.cc:19
oracle::occi::Statement * mStatement
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
tuple cout
Definition: gather_cfg.py:121

Member Data Documentation

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