Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:07

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