CMS 3D CMS Logo

RunMemTTErrorsDat.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  m_env = nullptr;
14  m_conn = nullptr;
15  m_writeStmt = nullptr;
16  m_readStmt = nullptr;
17 
18  m_errorBits = 0;
19 }
20 
22 
24  this->checkConnection();
25 
26  try {
27  m_writeStmt = m_conn->createStatement();
28  /* Using TO_NUMBER because OCCI does not support 64-bit integers well */
29  m_writeStmt->setSQL(
30  "INSERT INTO run_mem_tt_errors_dat (iov_id, logic_id, "
31  "error_bits) "
32  "VALUES (:iov_id, :logic_id, "
33  "to_number(:error_bits))");
34  } catch (SQLException& e) {
35  throw(std::runtime_error("RunMemTTErrorsDat::prepareWrite(): " + e.getMessage()));
36  }
37 }
38 
39 void RunMemTTErrorsDat::writeDB(const EcalLogicID* ecid, const RunMemTTErrorsDat* item, RunIOV* iov) noexcept(false) {
40  this->checkConnection();
41  this->checkPrepare();
42 
43  int iovID = iov->fetchID();
44  if (!iovID) {
45  throw(std::runtime_error("RunMemTTErrorsDat::writeDB: IOV not in DB"));
46  }
47 
48  int logicID = ecid->getLogicID();
49  if (!logicID) {
50  throw(std::runtime_error("RunMemTTErrorsDat::writeDB: Bad EcalLogicID"));
51  }
52 
53  try {
54  m_writeStmt->setInt(1, iovID);
55  m_writeStmt->setInt(2, logicID);
56  m_writeStmt->setString(3, std::to_string(item->getErrorBits()));
57  m_writeStmt->executeUpdate();
58  } catch (SQLException& e) {
59  throw(std::runtime_error("RunMemTTErrorsDat::writeDB(): " + e.getMessage()));
60  }
61 }
62 
63 void RunMemTTErrorsDat::fetchData(map<EcalLogicID, RunMemTTErrorsDat>* fillMap, RunIOV* iov) noexcept(false) {
64  this->checkConnection();
65  fillMap->clear();
66 
67  iov->setConnection(m_env, m_conn);
68  int iovID = iov->fetchID();
69  if (!iovID) {
70  // throw(std::runtime_error("RunMemTTErrorsDat::writeDB: IOV not in DB"));
71  return;
72  }
73 
74  try {
75  /* Using TO_CHAR because OCCI does not support 64-bit integers well */
76  m_readStmt->setSQL(
77  "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
78  "to_char(d.error_bits) "
79  "FROM channelview cv JOIN run_mem_tt_errors_dat d "
80  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
81  "WHERE d.iov_id = :iov_id");
82  m_readStmt->setInt(1, iovID);
83  ResultSet* rset = m_readStmt->executeQuery();
84 
85  std::pair<EcalLogicID, RunMemTTErrorsDat> p;
87  while (rset->next()) {
88  p.first = EcalLogicID(rset->getString(1), // name
89  rset->getInt(2), // logic_id
90  rset->getInt(3), // id1
91  rset->getInt(4), // id2
92  rset->getInt(5), // id3
93  rset->getString(6)); // maps_to
94 
95  dat.setErrorBits(boost::lexical_cast<uint64_t>(rset->getString(7)));
96 
97  p.second = dat;
98  fillMap->insert(p);
99  }
100 
101  } catch (SQLException& e) {
102  throw(std::runtime_error("RunMemTTErrorsDat::fetchData(): " + e.getMessage()));
103  }
104 }
RunIOV
Definition: RunIOV.h:13
funct::false
false
Definition: Factorize.h:29
RunMemTTErrorsDat.h
RunIOV.h
RunMemTTErrorsDat::writeDB
void writeDB(const EcalLogicID *ecid, const RunMemTTErrorsDat *item, RunIOV *iov) noexcept(false)
Definition: RunMemTTErrorsDat.cc:39
oracle::occi
Definition: ConnectionManager.h:7
RunMemTTErrorsDat::prepareWrite
void prepareWrite() noexcept(false) override
Definition: RunMemTTErrorsDat.cc:23
EcalLogicID
Definition: EcalLogicID.h:7
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
RunMemTTErrorsDat
Definition: RunMemTTErrorsDat.h:12
std
Definition: JetResolutionObject.h:76
Oracle.h
RunMemTTErrorsDat::fetchData
void fetchData(std::map< EcalLogicID, RunMemTTErrorsDat > *fillMap, RunIOV *iov) noexcept(false)
Definition: RunMemTTErrorsDat.cc:63
RunMemTTErrorsDat::setErrorBits
void setErrorBits(uint64_t bits)
Definition: RunMemTTErrorsDat.h:21
RunMemTTErrorsDat::~RunMemTTErrorsDat
~RunMemTTErrorsDat() override
Definition: RunMemTTErrorsDat.cc:21
RunMemTTErrorsDat::RunMemTTErrorsDat
RunMemTTErrorsDat()
Definition: RunMemTTErrorsDat.cc:12
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37