CMS 3D CMS Logo

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