CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RunFEConfigDat.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 
17  m_config = 0;
18 }
19 
21 
23  this->checkConnection();
24 
25  try {
26  m_writeStmt = m_conn->createStatement();
27  m_writeStmt->setSQL(
28  "INSERT INTO run_FEConfig_dat (iov_id, logic_id, "
29  "Config_id ) "
30  "VALUES (:iov_id, :logic_id, "
31  ":Config_id ) ");
32  } catch (SQLException& e) {
33  throw(std::runtime_error("RunFEConfigDat::prepareWrite(): " + e.getMessage()));
34  }
35 }
36 
37 void RunFEConfigDat::writeDB(const EcalLogicID* ecid, const RunFEConfigDat* 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("RunFEConfigDat::writeDB: IOV not in DB"));
44  }
45 
46  int logicID = ecid->getLogicID();
47  if (!logicID) {
48  throw(std::runtime_error("RunFEConfigDat::writeDB: Bad EcalLogicID"));
49  }
50 
51  try {
52  m_writeStmt->setInt(1, iovID);
53  m_writeStmt->setInt(2, logicID);
54  m_writeStmt->setInt(3, item->getConfigId());
55 
56  m_writeStmt->executeUpdate();
57  } catch (SQLException& e) {
58  throw(std::runtime_error("RunFEConfigDat::writeDB(): " + e.getMessage()));
59  }
60 }
61 
62 void RunFEConfigDat::fetchData(map<EcalLogicID, RunFEConfigDat>* 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("RunFEConfigDat::writeDB: IOV not in DB"));
70  return;
71  }
72 
73  try {
74  // createReadStatement();
75  // m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
76  Statement* stmt = m_conn->createStatement();
77  stmt->setSQL(
78  "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
79  "d.Config_id "
80  "FROM channelview cv JOIN run_FEConfig_dat d "
81  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
82  "WHERE d.iov_id = :iov_id");
83  stmt->setInt(1, iovID);
84  // m_readStmt->setInt(1, iovID);
85  // ResultSet* rset = m_readStmt->executeQuery();
86  ResultSet* rset = stmt->executeQuery();
87 
88  std::pair<EcalLogicID, RunFEConfigDat> p;
90  while (rset->next()) {
91  p.first = EcalLogicID(rset->getString(1), // name
92  rset->getInt(2), // logic_id
93  rset->getInt(3), // id1
94  rset->getInt(4), // id2
95  rset->getInt(5), // id3
96  rset->getString(6)); // maps_to
97 
98  dat.setConfigId(rset->getInt(7));
99 
100  p.second = dat;
101  fillMap->insert(p);
102  }
103  // terminateReadStatement();
104  m_conn->terminateStatement(stmt);
105  } catch (SQLException& e) {
106  throw(std::runtime_error("RunFEConfigDat::fetchData(): " + e.getMessage()));
107  }
108 }
void prepareWrite() noexcept(false) override
void setConfigId(int x)
void writeDB(const EcalLogicID *ecid, const RunFEConfigDat *item, RunIOV *iov) noexcept(false)
static std::vector< std::string > checklist dat
void fetchData(std::map< EcalLogicID, RunFEConfigDat > *fillMap, RunIOV *iov) noexcept(false)
Definition: RunIOV.h:13
~RunFEConfigDat() override