Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:02

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