CMS 3D CMS Logo

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