CMS 3D CMS Logo

CaliHVScanRatioDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
4 
8 
9 using namespace std;
10 using namespace oracle::occi;
11 
13 {
14  m_env = NULL;
15  m_conn = NULL;
16  m_writeStmt = NULL;
17 
18  m_hvratio = 0;
19  m_hvratioRMS = 0;
20  m_taskStatus = false;
21 }
22 
23 
24 
26 {
27 }
28 
29 
30 
33 {
34  this->checkConnection();
35 
36  try {
37  m_writeStmt = m_conn->createStatement();
38  m_writeStmt->setSQL("INSERT INTO cali_hv_scan_ratio_dat (iov_id, logic_id, "
39  "hvratio, hvratio_rms, task_status) "
40  "VALUES (:iov_id, :logic_id, "
41  ":3, :4, :5)");
42  } catch (SQLException &e) {
43  throw(std::runtime_error("CaliHVScanRatioDat::prepareWrite(): "+e.getMessage()));
44  }
45 }
46 
47 
48 
50  noexcept(false)
51 {
52  this->checkConnection();
53  this->checkPrepare();
54 
55  int iovID = iov->fetchID();
56  if (!iovID) { throw(std::runtime_error("CaliHVScanRatioDat::writeDB: IOV not in DB")); }
57 
58  int logicID = ecid->getLogicID();
59  if (!logicID) { throw(std::runtime_error("CaliHVScanRatioDat::writeDB: Bad EcalLogicID")); }
60 
61  try {
62  m_writeStmt->setInt(1, iovID);
63  m_writeStmt->setInt(2, logicID);
64 
65  m_writeStmt->setFloat(3, item->getHVRatio() );
66  m_writeStmt->setFloat(4, item->getHVRatioRMS() );
67  m_writeStmt->setInt(5, item->getTaskStatus() );
68 
69  m_writeStmt->executeUpdate();
70  } catch (SQLException &e) {
71  throw(std::runtime_error("CaliHVScanRatioDat::writeDB(): "+e.getMessage()));
72  }
73 }
74 
75 
76 
77 void CaliHVScanRatioDat::fetchData(std::map< EcalLogicID, CaliHVScanRatioDat >* fillMap, CaliIOV* iov)
78  noexcept(false)
79 {
80  this->checkConnection();
81  fillMap->clear();
82 
83  iov->setConnection(m_env, m_conn);
84  int iovID = iov->fetchID();
85  if (!iovID) {
86  // throw(std::runtime_error("CaliHVScanRatioDat::writeDB: IOV not in DB"));
87  return;
88  }
89 
90  try {
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.hvratio, d.hvratio_rms, d.task_status "
94  "FROM channelview cv JOIN cali_hv_scan_ratio_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  ResultSet* rset = stmt->executeQuery();
99 
100  std::pair< EcalLogicID, CaliHVScanRatioDat > p;
101  CaliHVScanRatioDat dat;
102  while(rset->next()) {
103  p.first = EcalLogicID( rset->getString(1), // name
104  rset->getInt(2), // logic_id
105  rset->getInt(3), // id1
106  rset->getInt(4), // id2
107  rset->getInt(5), // id3
108  rset->getString(6)); // maps_to
109 
110  dat.setHVRatio( rset->getFloat(7) );
111  dat.setHVRatioRMS( rset->getFloat(8) );
112  dat.setTaskStatus( rset->getInt(9) );
113 
114  p.second = dat;
115  fillMap->insert(p);
116  }
117  } catch (SQLException &e) {
118  throw(std::runtime_error("CaliHVScanRatioDat::fetchData(): "+e.getMessage()));
119  }
120 }
void setTaskStatus(bool s)
#define noexcept
#define NULL
Definition: scimark2.h:8
void setHVRatio(float c)
void prepareWrite() noexcept(false)
void fetchData(std::map< EcalLogicID, CaliHVScanRatioDat > *fillVec, CaliIOV *iov) noexcept(false)
void setHVRatioRMS(float c)
void writeDB(const EcalLogicID *ecid, const CaliHVScanRatioDat *item, CaliIOV *iov) noexcept(false)