CMS 3D CMS Logo

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