CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RunCrystalErrorsDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
4 #include <boost/lexical_cast.hpp>
5 
8 
9 using namespace std;
10 using namespace oracle::occi;
11 
13 {
14  m_env = NULL;
15  m_conn = NULL;
16  m_writeStmt = NULL;
17  m_errorBits = 0;
18 }
19 
20 
21 
23 {
24 }
25 
26 
27 
29  throw(std::runtime_error)
30 {
31  this->checkConnection();
32 
33  try {
34  m_writeStmt = m_conn->createStatement();
35  /* Using TO_NUMBER because OCCI does not support 64-bit integers well */
36  m_writeStmt->setSQL("INSERT INTO run_crystal_errors_dat (iov_id, logic_id, "
37  "error_bits) "
38  "VALUES (:iov_id, :logic_id, "
39  "to_number(:error_bits))");
40  } catch (SQLException &e) {
41  throw(std::runtime_error("RunCrystalErrorsDat::prepareWrite(): "+e.getMessage()));
42  }
43 }
44 
45 
46 
48  throw(std::runtime_error)
49 {
50  this->checkConnection();
51  this->checkPrepare();
52 
53  int iovID = iov->fetchID();
54  if (!iovID) { throw(std::runtime_error("RunCrystalErrorsDat::writeDB: IOV not in DB")); }
55 
56  int logicID = ecid->getLogicID();
57  if (!logicID) { throw(std::runtime_error("RunCrystalErrorsDat::writeDB: Bad EcalLogicID")); }
58 
59  try {
60  m_writeStmt->setInt(1, iovID);
61  m_writeStmt->setInt(2, logicID);
62  m_writeStmt->setString(3, ( boost::lexical_cast<std::string>(item->getErrorBits()) ).c_str());
63  m_writeStmt->executeUpdate();
64  } catch (SQLException &e) {
65  throw(std::runtime_error("RunCrystalErrorsDat::writeDB(): "+e.getMessage()));
66  }
67 }
68 
69 
70 
71 void RunCrystalErrorsDat::fetchData(map< EcalLogicID, RunCrystalErrorsDat >* fillMap, RunIOV* iov)
72  throw(std::runtime_error)
73 {
74  this->checkConnection();
75  fillMap->clear();
76 
77  iov->setConnection(m_env, m_conn);
78  int iovID = iov->fetchID();
79  if (!iovID) {
80  // throw(std::runtime_error("RunCrystalErrorsDat::writeDB: IOV not in DB"));
81  return;
82  }
83 
84  try {
85  Statement* stmt = m_conn->createStatement();
86  /* Using TO_CHAR because OCCI does not support 64-bit integers well */
87  stmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
88  "to_char(d.error_bits) "
89  "FROM channelview cv JOIN run_crystal_errors_dat d "
90  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
91  "WHERE d.iov_id = :iov_id");
92  stmt->setInt(1, iovID);
93  ResultSet* rset = stmt->executeQuery();
94 
95  std::pair< EcalLogicID, RunCrystalErrorsDat > p;
97  while(rset->next()) {
98  p.first = EcalLogicID( rset->getString(1), // name
99  rset->getInt(2), // logic_id
100  rset->getInt(3), // id1
101  rset->getInt(4), // id2
102  rset->getInt(5), // id3
103  rset->getString(6)); // maps_to
104 
105  dat.setErrorBits( boost::lexical_cast<uint64_t>(rset->getString(7)) );
106 
107  p.second = dat;
108  fillMap->insert(p);
109  }
110  m_conn->terminateStatement(stmt);
111 
112  } catch (SQLException &e) {
113  throw(std::runtime_error("RunCrystalErrorsDat::fetchData(): "+e.getMessage()));
114  }
115 }
void writeDB(const EcalLogicID *ecid, const RunCrystalErrorsDat *item, RunIOV *iov)
void fetchData(std::map< EcalLogicID, RunCrystalErrorsDat > *fillMap, RunIOV *iov)
#define NULL
Definition: scimark2.h:8
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
tuple iov
Definition: o2o.py:307
void setErrorBits(uint64_t bits)
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
Definition: RunIOV.h:13