File indexing completed on 2024-04-06 12:23:12
0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004
0005 #include "OnlineDB/EcalCondDB/interface/RunPTMTempDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
0007
0008 using namespace std;
0009 using namespace oracle::occi;
0010
0011 RunPTMTempDat::RunPTMTempDat() {
0012 m_env = nullptr;
0013 m_conn = nullptr;
0014 m_writeStmt = nullptr;
0015 m_readStmt = nullptr;
0016
0017 m_temperature = 0;
0018 }
0019
0020 RunPTMTempDat::~RunPTMTempDat() {}
0021
0022 void RunPTMTempDat::prepareWrite() noexcept(false) {
0023 this->checkConnection();
0024
0025 try {
0026 m_writeStmt = m_conn->createStatement();
0027 m_writeStmt->setSQL(
0028 "INSERT INTO run_temperature_ptm_dat (iov_id, logic_id, "
0029 "temperature) "
0030 "VALUES (:iov_id, :logic_id, "
0031 ":temperature)");
0032 } catch (SQLException& e) {
0033 throw(std::runtime_error("RunPTMTempDat::prepareWrite(): " + e.getMessage()));
0034 }
0035 }
0036
0037 void RunPTMTempDat::writeDB(const EcalLogicID* ecid, const RunPTMTempDat* item, RunIOV* iov) noexcept(false) {
0038 this->checkConnection();
0039 this->checkPrepare();
0040
0041 int iovID = iov->fetchID();
0042 if (!iovID) {
0043 throw(std::runtime_error("RunPTMTempDat::writeDB: IOV not in DB"));
0044 }
0045
0046 int logicID = ecid->getLogicID();
0047 if (!logicID) {
0048 throw(std::runtime_error("RunPTMTempDat::writeDB: Bad EcalLogicID"));
0049 }
0050
0051 try {
0052 m_writeStmt->setInt(1, iovID);
0053 m_writeStmt->setInt(2, logicID);
0054 m_writeStmt->setFloat(3, item->getTemperature());
0055
0056 m_writeStmt->executeUpdate();
0057 } catch (SQLException& e) {
0058 throw(std::runtime_error("RunPTMTempDat::writeDB(): " + e.getMessage()));
0059 }
0060 }
0061
0062 void RunPTMTempDat::fetchData(map<EcalLogicID, RunPTMTempDat>* fillMap, RunIOV* iov) noexcept(false) {
0063 this->checkConnection();
0064 fillMap->clear();
0065
0066 iov->setConnection(m_env, m_conn);
0067 int iovID = iov->fetchID();
0068 if (!iovID) {
0069
0070 return;
0071 }
0072
0073 try {
0074 m_readStmt->setSQL(
0075 "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
0076 "d.temperature "
0077 "FROM channelview cv JOIN RUN_TEMPERATURE_PTM_DAT d "
0078 "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
0079 "WHERE d.iov_id = :iov_id");
0080 m_readStmt->setInt(1, iovID);
0081 ResultSet* rset = m_readStmt->executeQuery();
0082
0083 std::pair<EcalLogicID, RunPTMTempDat> p;
0084 RunPTMTempDat dat;
0085 while (rset->next()) {
0086 p.first = EcalLogicID(rset->getString(1),
0087 rset->getInt(2),
0088 rset->getInt(3),
0089 rset->getInt(4),
0090 rset->getInt(5),
0091 rset->getString(6));
0092
0093 dat.setTemperature(rset->getFloat(7));
0094
0095 p.second = dat;
0096 fillMap->insert(p);
0097 }
0098
0099 } catch (SQLException& e) {
0100 throw(std::runtime_error("RunPTMTempDat::fetchData(): " + e.getMessage()));
0101 }
0102 }