CMS 3D CMS Logo

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