File indexing completed on 2024-04-06 12:23:01
0001 #include <stdexcept>
0002 #include "OnlineDB/Oracle/interface/Oracle.h"
0003
0004 #include "OnlineDB/EcalCondDB/interface/Tm.h"
0005 #include "OnlineDB/EcalCondDB/interface/DateHandler.h"
0006 #include "OnlineDB/EcalCondDB/interface/DCSPTMTemp.h"
0007 #include "OnlineDB/EcalCondDB/interface/DCSPTMTempList.h"
0008 #include "OnlineDB/EcalCondDB/interface/IIOV.h"
0009 #include "OnlineDB/EcalCondDB/interface/EcalLogicID.h"
0010
0011 using namespace std;
0012 using namespace oracle::occi;
0013
0014 DCSPTMTempList::DCSPTMTempList() { m_conn = nullptr; }
0015
0016 DCSPTMTempList::~DCSPTMTempList() {}
0017
0018 std::vector<DCSPTMTemp> DCSPTMTempList::getList() { return m_vec_temp; }
0019
0020 void DCSPTMTempList::fetchValuesForECID(const EcalLogicID& ecid) noexcept(false) {
0021 this->checkConnection();
0022 int nruns = 0;
0023
0024 int ecid_id = ecid.getLogicID();
0025
0026 try {
0027 Statement* stmt0 = m_conn->createStatement();
0028 stmt0->setSQL(
0029 "SELECT count(since) FROM PVSS_TEMPERATURE_DAT "
0030 "WHERE logic_id = :logic_id ");
0031 stmt0->setInt(1, ecid_id);
0032
0033 ResultSet* rset0 = stmt0->executeQuery();
0034 if (rset0->next()) {
0035 nruns = rset0->getInt(1);
0036 }
0037 m_conn->terminateStatement(stmt0);
0038
0039 cout << "DCSPTMTempList::fetchValuesForECID>> Number of records in DB=" << nruns << endl;
0040 m_vec_temp.reserve(nruns);
0041
0042 Statement* stmt = m_conn->createStatement();
0043 stmt->setSQL(
0044 "SELECT "
0045 "since, till, temperature FROM PVSS_TEMPERATURE_DAT "
0046 "WHERE logic_id = :logic_id order by since ");
0047 stmt->setInt(1, ecid_id);
0048
0049 DateHandler dh(m_env, m_conn);
0050 Tm runStart;
0051 Tm runEnd;
0052
0053 ResultSet* rset = stmt->executeQuery();
0054 int i = 0;
0055 while (i < nruns) {
0056 rset->next();
0057
0058 Date startDate = rset->getDate(1);
0059 Date endDate = rset->getDate(2);
0060 float x = rset->getFloat(3);
0061 runStart = dh.dateToTm(startDate);
0062 runEnd = dh.dateToTm(endDate);
0063
0064 DCSPTMTemp r;
0065 r.setTemperature(x);
0066 r.setStart(runStart);
0067 r.setEnd(runEnd);
0068 r.setEcalLogicID(ecid);
0069 m_vec_temp.push_back(r);
0070
0071 i++;
0072 }
0073
0074 cout << "DCSPTMTempList::fetchValuesForECID>> loop done " << endl;
0075
0076 m_conn->terminateStatement(stmt);
0077 } catch (SQLException& e) {
0078 throw(std::runtime_error("DCSPTMTempList: " + e.getMessage()));
0079 }
0080 }
0081
0082 void DCSPTMTempList::fetchValuesForECIDAndTime(const EcalLogicID& ecid,
0083 const Tm& start,
0084 const Tm& end) noexcept(false) {
0085 this->checkConnection();
0086 int nruns = 0;
0087
0088 int ecid_id = ecid.getLogicID();
0089
0090 DateHandler dh(m_env, m_conn);
0091 Tm runStart;
0092 Tm runEnd;
0093
0094 try {
0095 Statement* stmt0 = m_conn->createStatement();
0096 stmt0->setSQL(
0097 "SELECT count(since) FROM PVSS_TEMPERATURE_DAT "
0098 "WHERE logic_id = :logic_id "
0099 "AND since >= :start_time "
0100 "AND since <= :till_time ");
0101 stmt0->setInt(1, ecid_id);
0102 stmt0->setDate(2, dh.tmToDate(start));
0103 stmt0->setDate(3, dh.tmToDate(end));
0104
0105 ResultSet* rset0 = stmt0->executeQuery();
0106 if (rset0->next()) {
0107 nruns = rset0->getInt(1);
0108 }
0109 m_conn->terminateStatement(stmt0);
0110
0111 cout << "DCSPTMTempList::fetchValuesForECIDAndTime>> Number of records in DB=" << nruns << endl;
0112 m_vec_temp.reserve(nruns);
0113
0114 Statement* stmt = m_conn->createStatement();
0115 stmt->setSQL(
0116 "SELECT "
0117 "since, till, temperature FROM PVSS_TEMPERATURE_DAT "
0118 "WHERE logic_id = :logic_id "
0119 "AND since >= :start_time "
0120 "AND since <= :till_time "
0121 " order by since ");
0122 stmt->setInt(1, ecid_id);
0123 stmt->setDate(2, dh.tmToDate(start));
0124 stmt->setDate(3, dh.tmToDate(end));
0125
0126 ResultSet* rset = stmt->executeQuery();
0127 int i = 0;
0128 while (i < nruns) {
0129 rset->next();
0130
0131 Date startDate = rset->getDate(1);
0132 Date endDate = rset->getDate(2);
0133 float x = rset->getFloat(3);
0134 runStart = dh.dateToTm(startDate);
0135 runEnd = dh.dateToTm(endDate);
0136
0137 DCSPTMTemp r;
0138 r.setTemperature(x);
0139 r.setStart(runStart);
0140 r.setEnd(runEnd);
0141 r.setEcalLogicID(ecid);
0142 m_vec_temp.push_back(r);
0143
0144 i++;
0145 }
0146
0147 m_conn->terminateStatement(stmt);
0148 } catch (SQLException& e) {
0149 throw(std::runtime_error("DCSPTMTempList: " + e.getMessage()));
0150 }
0151 }