CMS 3D CMS Logo

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