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  m_env = nullptr;
14  m_conn = nullptr;
15  m_writeStmt = nullptr;
16 
17  m_hvratio = 0;
18  m_hvratioRMS = 0;
19  m_taskStatus = false;
20 }
21 
23 
25  this->checkConnection();
26 
27  try {
28  m_writeStmt = m_conn->createStatement();
29  m_writeStmt->setSQL(
30  "INSERT INTO cali_hv_scan_ratio_dat (iov_id, logic_id, "
31  "hvratio, hvratio_rms, task_status) "
32  "VALUES (:iov_id, :logic_id, "
33  ":3, :4, :5)");
34  } catch (SQLException& e) {
35  throw(std::runtime_error("CaliHVScanRatioDat::prepareWrite(): " + e.getMessage()));
36  }
37 }
38 
40  const CaliHVScanRatioDat* item,
41  CaliIOV* iov) noexcept(false) {
42  this->checkConnection();
43  this->checkPrepare();
44 
45  int iovID = iov->fetchID();
46  if (!iovID) {
47  throw(std::runtime_error("CaliHVScanRatioDat::writeDB: IOV not in DB"));
48  }
49 
50  int logicID = ecid->getLogicID();
51  if (!logicID) {
52  throw(std::runtime_error("CaliHVScanRatioDat::writeDB: Bad EcalLogicID"));
53  }
54 
55  try {
56  m_writeStmt->setInt(1, iovID);
57  m_writeStmt->setInt(2, logicID);
58 
59  m_writeStmt->setFloat(3, item->getHVRatio());
60  m_writeStmt->setFloat(4, item->getHVRatioRMS());
61  m_writeStmt->setInt(5, item->getTaskStatus());
62 
63  m_writeStmt->executeUpdate();
64  } catch (SQLException& e) {
65  throw(std::runtime_error("CaliHVScanRatioDat::writeDB(): " + e.getMessage()));
66  }
67 }
68 
69 void CaliHVScanRatioDat::fetchData(std::map<EcalLogicID, CaliHVScanRatioDat>* fillMap, CaliIOV* iov) noexcept(false) {
70  this->checkConnection();
71  fillMap->clear();
72 
73  iov->setConnection(m_env, m_conn);
74  int iovID = iov->fetchID();
75  if (!iovID) {
76  // throw(std::runtime_error("CaliHVScanRatioDat::writeDB: IOV not in DB"));
77  return;
78  }
79 
80  try {
81  Statement* stmt = m_conn->createStatement();
82  stmt->setSQL(
83  "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
84  "d.hvratio, d.hvratio_rms, d.task_status "
85  "FROM channelview cv JOIN cali_hv_scan_ratio_dat d "
86  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
87  "WHERE d.iov_id = :iov_id");
88  stmt->setInt(1, iovID);
89  ResultSet* rset = stmt->executeQuery();
90 
91  std::pair<EcalLogicID, CaliHVScanRatioDat> 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.setHVRatio(rset->getFloat(7));
102  dat.setHVRatioRMS(rset->getFloat(8));
103  dat.setTaskStatus(rset->getInt(9));
104 
105  p.second = dat;
106  fillMap->insert(p);
107  }
108  } catch (SQLException& e) {
109  throw(std::runtime_error("CaliHVScanRatioDat::fetchData(): " + e.getMessage()));
110  }
111 }
void setTaskStatus(bool s)
void setHVRatio(float c)
~CaliHVScanRatioDat() override
void fetchData(std::map< EcalLogicID, CaliHVScanRatioDat > *fillVec, CaliIOV *iov) noexcept(false)
void prepareWrite() noexcept(false) override
void setHVRatioRMS(float c)
void writeDB(const EcalLogicID *ecid, const CaliHVScanRatioDat *item, CaliIOV *iov) noexcept(false)