CMS 3D CMS Logo

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