test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 {
13  m_env = NULL;
14  m_conn = NULL;
15  m_writeStmt = NULL;
16  m_readStmt = NULL;
17 
18  m_config = 0;
19 
20 }
21 
22 
23 
25 {
26 }
27 
28 
29 
31  throw(std::runtime_error)
32 {
33  this->checkConnection();
34 
35  try {
36  m_writeStmt = m_conn->createStatement();
37  m_writeStmt->setSQL("INSERT INTO run_FEConfig_dat (iov_id, logic_id, "
38  "Config_id ) "
39  "VALUES (:iov_id, :logic_id, "
40  ":Config_id ) ");
41  } catch (SQLException &e) {
42  throw(std::runtime_error("RunFEConfigDat::prepareWrite(): "+e.getMessage()));
43  }
44 }
45 
46 
47 
49  throw(std::runtime_error)
50 {
51  this->checkConnection();
52  this->checkPrepare();
53 
54  int iovID = iov->fetchID();
55  if (!iovID) { throw(std::runtime_error("RunFEConfigDat::writeDB: IOV not in DB")); }
56 
57  int logicID = ecid->getLogicID();
58  if (!logicID) { throw(std::runtime_error("RunFEConfigDat::writeDB: Bad EcalLogicID")); }
59 
60  try {
61  m_writeStmt->setInt(1, iovID);
62  m_writeStmt->setInt(2, logicID);
63  m_writeStmt->setInt(3, item->getConfigId());
64 
65 
66  m_writeStmt->executeUpdate();
67  } catch (SQLException &e) {
68  throw(std::runtime_error("RunFEConfigDat::writeDB(): "+e.getMessage()));
69  }
70 }
71 
72 
73 
74 void RunFEConfigDat::fetchData(map< EcalLogicID, RunFEConfigDat >* fillMap, RunIOV* iov)
75  throw(std::runtime_error)
76 {
77  this->checkConnection();
78  fillMap->clear();
79 
80  iov->setConnection(m_env, m_conn);
81  int iovID = iov->fetchID();
82  if (!iovID) {
83  // throw(std::runtime_error("RunFEConfigDat::writeDB: IOV not in DB"));
84  return;
85  }
86 
87  try {
88 
89  // createReadStatement();
90  // m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
91  Statement* stmt = m_conn->createStatement();
92  stmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
93  "d.Config_id "
94  "FROM channelview cv JOIN run_FEConfig_dat d "
95  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
96  "WHERE d.iov_id = :iov_id");
97  stmt->setInt(1, iovID);
98  // m_readStmt->setInt(1, iovID);
99  // ResultSet* rset = m_readStmt->executeQuery();
100  ResultSet* rset = stmt->executeQuery();
101 
102  std::pair< EcalLogicID, RunFEConfigDat > p;
103  RunFEConfigDat dat;
104  while(rset->next()) {
105  p.first = EcalLogicID( rset->getString(1), // name
106  rset->getInt(2), // logic_id
107  rset->getInt(3), // id1
108  rset->getInt(4), // id2
109  rset->getInt(5), // id3
110  rset->getString(6)); // maps_to
111 
112  dat.setConfigId( rset->getInt(7) );
113 
114  p.second = dat;
115  fillMap->insert(p);
116  }
117  // terminateReadStatement();
118  m_conn->terminateStatement(stmt);
119  } catch (SQLException &e) {
120  throw(std::runtime_error("RunFEConfigDat::fetchData(): "+e.getMessage()));
121  }
122 }
123 
void setConfigId(int x)
#define NULL
Definition: scimark2.h:8
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
void writeDB(const EcalLogicID *ecid, const RunFEConfigDat *item, RunIOV *iov)
tuple iov
Definition: o2o.py:307
void fetchData(std::map< EcalLogicID, RunFEConfigDat > *fillMap, RunIOV *iov)
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
Definition: RunIOV.h:13