CMS 3D CMS Logo

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