CMS 3D CMS Logo

RunTPGConfigDat.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 {
13  m_env = nullptr;
14  m_conn = nullptr;
15  m_writeStmt = nullptr;
16  m_readStmt = nullptr;
17 
18  m_config = "";
19  m_version=0;
20 }
21 
22 
23 
25 {
26 }
27 
28 
29 
32 {
33  this->checkConnection();
34 
35  try {
36  m_writeStmt = m_conn->createStatement();
37  m_writeStmt->setSQL("INSERT INTO run_TPGConfig_dat (iov_id, logic_id, "
38  "Config_tag , version ) "
39  "VALUES (:iov_id, :logic_id, "
40  ":Config_tag , :version ) ");
41  } catch (SQLException &e) {
42  throw(std::runtime_error(std::string("RunTPGConfigDat::prepareWrite(): ")+getOraMessage(&e)));
43  }
44 }
45 
46 
47 
48 void RunTPGConfigDat::writeDB(const EcalLogicID* ecid, const RunTPGConfigDat* item, RunIOV* iov)
49  noexcept(false)
50 {
51  this->checkConnection();
52  this->checkPrepare();
53 
54  int iovID = iov->fetchID();
55  if (!iovID) { throw(std::runtime_error("RunTPGConfigDat::writeDB: IOV not in DB")); }
56 
57  int logicID = ecid->getLogicID();
58  if (!logicID) { throw(std::runtime_error("RunTPGConfigDat::writeDB: Bad EcalLogicID")); }
59 
60  try {
61  m_writeStmt->setInt(1, iovID);
62  m_writeStmt->setInt(2, logicID);
63  m_writeStmt->setString(3, item->getConfigTag());
64  m_writeStmt->setInt(4, item->getVersion());
65 
66 
67  m_writeStmt->executeUpdate();
68  } catch (SQLException &e) {
69  throw(std::runtime_error(std::string("RunTPGConfigDat::writeDB(): ")+getOraMessage(&e)));
70  }
71 }
72 
73 
74 
75 void RunTPGConfigDat::fetchData(map< EcalLogicID, RunTPGConfigDat >* fillMap, RunIOV* iov)
76  noexcept(false)
77 {
78  this->checkConnection();
79  fillMap->clear();
80 
81  iov->setConnection(m_env, m_conn);
82  int iovID = iov->fetchID();
83  if (!iovID) {
84  // throw(std::runtime_error("RunTPGConfigDat::writeDB: IOV not in DB"));
85  return;
86  }
87 
88  try {
89 
90  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
91  "d.Config_tag, d.version "
92  "FROM channelview cv JOIN run_TPGConfig_dat d "
93  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
94  "WHERE d.iov_id = :iov_id");
95  m_readStmt->setInt(1, iovID);
96  ResultSet* rset = m_readStmt->executeQuery();
97 
98  std::pair< EcalLogicID, RunTPGConfigDat > p;
99  RunTPGConfigDat dat;
100  while(rset->next()) {
101  p.first = EcalLogicID( getOraString(rset,1), // name
102  rset->getInt(2), // logic_id
103  rset->getInt(3), // id1
104  rset->getInt(4), // id2
105  rset->getInt(5), // id3
106  getOraString(rset,6)); // maps_to
107 
108  dat.setConfigTag( getOraString(rset,7) );
109  dat.setVersion( rset->getInt(8) );
110 
111 
112  p.second = dat;
113  fillMap->insert(p);
114  }
115  } catch (SQLException &e) {
116  throw(std::runtime_error(std::string("RunTPGConfigDat::fetchData(): ")+getOraMessage(&e)));
117  }
118 }
void setConfigTag(std::string x)
#define noexcept
~RunTPGConfigDat() override
void writeDB(const EcalLogicID *ecid, const RunTPGConfigDat *item, RunIOV *iov) noexcept(false)
void prepareWrite() noexcept(false) override
void setVersion(int x)
void fetchData(std::map< EcalLogicID, RunTPGConfigDat > *fillMap, RunIOV *iov) noexcept(false)
Definition: RunIOV.h:13