File indexing completed on 2023-03-17 11:15:22
0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004
0005 #include "OnlineDB/EcalCondDB/interface/ODDelaysDat.h"
0006
0007 using namespace std;
0008 using namespace oracle::occi;
0009
0010 ODDelaysDat::ODDelaysDat() {
0011 m_env = nullptr;
0012 m_conn = nullptr;
0013 m_writeStmt = nullptr;
0014 m_readStmt = nullptr;
0015
0016 m_sm = 0;
0017 m_fed = 0;
0018 m_tt = 0;
0019 m_t1 = 0;
0020 }
0021
0022 ODDelaysDat::~ODDelaysDat() {}
0023
0024 void ODDelaysDat::prepareWrite() noexcept(false) {
0025 this->checkConnection();
0026
0027 try {
0028 m_writeStmt = m_conn->createStatement();
0029 m_writeStmt->setSQL("INSERT INTO " + getTable() +
0030 " (rec_id, sm_id, fed_id, tt_id, time_offset ) "
0031 "VALUES (:1, :2, :3, :4, :5 )");
0032 } catch (SQLException& e) {
0033 throw(std::runtime_error("ODDelaysDat::prepareWrite(): " + e.getMessage()));
0034 }
0035 }
0036
0037 void ODDelaysDat::writeDB(const ODDelaysDat* item, ODFEDelaysInfo* iov) noexcept(false) {
0038 this->checkConnection();
0039
0040 try {
0041 m_writeStmt->setInt(1, item->getId());
0042 m_writeStmt->setInt(2, item->getSMId());
0043 m_writeStmt->setInt(3, item->getFedId());
0044 m_writeStmt->setInt(4, item->getTTId());
0045 m_writeStmt->setInt(5, item->getTimeOffset());
0046
0047 m_writeStmt->executeUpdate();
0048 } catch (SQLException& e) {
0049 throw(std::runtime_error("ODDelaysDat::writeDB(): " + e.getMessage()));
0050 }
0051 }
0052
0053 void ODDelaysDat::fetchData(std::vector<ODDelaysDat>* p, ODFEDelaysInfo* iov) noexcept(false) {
0054 iov->setConnection(m_env, m_conn);
0055 int iovID = iov->fetchID();
0056 fetchData(p, iovID);
0057 }
0058
0059 void ODDelaysDat::fetchData(std::vector<ODDelaysDat>* p, int iovID) noexcept(false) {
0060 this->checkConnection();
0061
0062 if (!iovID) {
0063
0064 return;
0065 }
0066
0067 try {
0068 m_readStmt = m_conn->createStatement();
0069 m_readStmt->setSQL("SELECT * FROM " + getTable() + " WHERE rec_id = :rec_id order by sm_id, fed_id, tt_id");
0070 m_readStmt->setInt(1, iovID);
0071 ResultSet* rset = m_readStmt->executeQuery();
0072
0073
0074 ODDelaysDat dat;
0075 while (rset->next()) {
0076
0077 dat.setSMId(rset->getInt(2));
0078 dat.setFedId(rset->getInt(3));
0079 dat.setTTId(rset->getInt(4));
0080 dat.setTimeOffset(rset->getInt(5));
0081
0082 p->push_back(dat);
0083 }
0084 } catch (SQLException& e) {
0085 throw(std::runtime_error("ODDelaysDat::fetchData(): " + e.getMessage()));
0086 }
0087 }
0088
0089
0090
0091 void ODDelaysDat::writeArrayDB(const std::vector<ODDelaysDat>& data, ODFEDelaysInfo* iov) noexcept(false) {
0092 this->checkConnection();
0093
0094 int iovID = iov->fetchID();
0095 if (!iovID) {
0096 throw(std::runtime_error("ODDelays::writeArrayDB: ODFEDelaysInfo not in DB"));
0097 }
0098
0099 int nrows = data.size();
0100 int* ids = new int[nrows];
0101 int* xx = new int[nrows];
0102 int* yy = new int[nrows];
0103 int* zz = new int[nrows];
0104 int* st = new int[nrows];
0105
0106 ub2* ids_len = new ub2[nrows];
0107 ub2* x_len = new ub2[nrows];
0108 ub2* y_len = new ub2[nrows];
0109 ub2* z_len = new ub2[nrows];
0110 ub2* st_len = new ub2[nrows];
0111
0112 ODDelaysDat dataitem;
0113
0114 int n_data = (int)data.size();
0115
0116 for (int count = 0; count < n_data; count++) {
0117 dataitem = data[count];
0118 ids[count] = iovID;
0119 xx[count] = dataitem.getSMId();
0120 yy[count] = dataitem.getFedId();
0121 zz[count] = dataitem.getTTId();
0122 st[count] = dataitem.getTimeOffset();
0123
0124 ids_len[count] = sizeof(ids[count]);
0125 x_len[count] = sizeof(xx[count]);
0126 y_len[count] = sizeof(yy[count]);
0127 z_len[count] = sizeof(zz[count]);
0128 st_len[count] = sizeof(st[count]);
0129 }
0130
0131 try {
0132 m_writeStmt->setDataBuffer(1, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
0133 m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
0134 m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT, sizeof(yy[0]), y_len);
0135 m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT, sizeof(zz[0]), z_len);
0136 m_writeStmt->setDataBuffer(5, (dvoid*)st, OCCIINT, sizeof(st[0]), st_len);
0137
0138 m_writeStmt->executeArrayUpdate(nrows);
0139
0140 delete[] ids;
0141 delete[] xx;
0142 delete[] yy;
0143 delete[] zz;
0144 delete[] st;
0145
0146 delete[] ids_len;
0147 delete[] x_len;
0148 delete[] y_len;
0149 delete[] z_len;
0150 delete[] st_len;
0151
0152 } catch (SQLException& e) {
0153 throw(std::runtime_error("ODDelaysDat::writeArrayDB(): " + e.getMessage()));
0154 }
0155 }