CMS 3D CMS Logo

RunH4TablePositionDat.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_table_x = 0;
18  m_table_y = 0;
19  m_numSpills = 0;
20  m_numEvents = 0;
21 }
22 
24 
26  this->checkConnection();
27 
28  try {
29  m_writeStmt = m_conn->createStatement();
30  m_writeStmt->setSQL(
31  "INSERT INTO run_h4_table_position_dat (iov_id, logic_id, "
32  "table_x, table_y, number_of_spills, number_of_events ) "
33  "VALUES (:iov_id, :logic_id, "
34  ":table_x, :table_y, :number_of_spills, :number_of_events)");
35  } catch (SQLException& e) {
36  throw(std::runtime_error("RunH4TablePositionDat::prepareWrite(): " + e.getMessage()));
37  }
38 }
39 
42  RunIOV* iov) noexcept(false) {
43  this->checkConnection();
44  this->checkPrepare();
45 
46  int iovID = iov->fetchID();
47  if (!iovID) {
48  throw(std::runtime_error("RunH4TablePositionDat::writeDB: IOV not in DB"));
49  }
50 
51  int logicID = ecid->getLogicID();
52  if (!logicID) {
53  throw(std::runtime_error("RunH4TablePositionDat::writeDB: Bad EcalLogicID"));
54  }
55 
56  try {
57  m_writeStmt->setInt(1, iovID);
58  m_writeStmt->setInt(2, logicID);
59  m_writeStmt->setInt(3, item->getTableX());
60  m_writeStmt->setInt(4, item->getTableY());
61  m_writeStmt->setInt(5, item->getNumSpills());
62  m_writeStmt->setInt(6, item->getNumEvents());
63 
64  m_writeStmt->executeUpdate();
65  } catch (SQLException& e) {
66  throw(std::runtime_error("RunH4TablePositionDat::writeDB(): " + e.getMessage()));
67  }
68 }
69 
70 void RunH4TablePositionDat::fetchData(map<EcalLogicID, RunH4TablePositionDat>* fillMap, RunIOV* iov) noexcept(false) {
71  this->checkConnection();
72  fillMap->clear();
73 
74  iov->setConnection(m_env, m_conn);
75  int iovID = iov->fetchID();
76  if (!iovID) {
77  // throw(std::runtime_error("RunH4TablePositionDat::writeDB: IOV not in DB"));
78  return;
79  }
80 
81  try {
82  m_readStmt->setSQL(
83  "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
84  "d.table_x, d.table_y, d.number_of_spills, d.number_of_events "
85  "FROM channelview cv JOIN run_h4_table_position_dat d "
86  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
87  "WHERE d.iov_id = :iov_id");
88  m_readStmt->setInt(1, iovID);
89  ResultSet* rset = m_readStmt->executeQuery();
90 
91  std::pair<EcalLogicID, RunH4TablePositionDat> p;
93  while (rset->next()) {
94  p.first = EcalLogicID(rset->getString(1), // name
95  rset->getInt(2), // logic_id
96  rset->getInt(3), // id1
97  rset->getInt(4), // id2
98  rset->getInt(5), // id3
99  rset->getString(6)); // maps_to
100 
101  dat.setTableX(rset->getInt(7));
102  dat.setTableY(rset->getInt(8));
103  dat.setNumSpills(rset->getInt(9));
104  dat.setNumEvents(rset->getInt(10));
105 
106  p.second = dat;
107  fillMap->insert(p);
108  }
109 
110  } catch (SQLException& e) {
111  throw(std::runtime_error("RunH4TablePositionDat::fetchData(): " + e.getMessage()));
112  }
113 }
void writeDB(const EcalLogicID *ecid, const RunH4TablePositionDat *item, RunIOV *iov) noexcept(false)
void fetchData(std::map< EcalLogicID, RunH4TablePositionDat > *fillMap, RunIOV *iov) noexcept(false)
void prepareWrite() noexcept(false) override
Definition: RunIOV.h:13