Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 
0005 #include "OnlineDB/EcalCondDB/interface/ODPedestalOffsetsDat.h"
0006 
0007 using namespace std;
0008 using namespace oracle::occi;
0009 
0010 ODPedestalOffsetsDat::ODPedestalOffsetsDat() {
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_xt = 0;
0020   m_low = 0;
0021   m_mid = 0;
0022   m_high = 0;
0023 }
0024 
0025 ODPedestalOffsetsDat::~ODPedestalOffsetsDat() {}
0026 
0027 void ODPedestalOffsetsDat::prepareWrite() noexcept(false) {
0028   this->checkConnection();
0029 
0030   try {
0031     m_writeStmt = m_conn->createStatement();
0032     m_writeStmt->setSQL("INSERT INTO " + getTable() +
0033                         " (rec_id, sm_id, fed_id, tt_id, cry_id, low, mid, high) "
0034                         "VALUES (:1, :2, :3, :4, :5, :6, :7, :8 )");
0035   } catch (SQLException& e) {
0036     throw(std::runtime_error("ODPedestalOffsetsDat::prepareWrite():  " + e.getMessage()));
0037   }
0038 }
0039 
0040 void ODPedestalOffsetsDat::writeDB(const ODPedestalOffsetsDat* item, ODFEPedestalOffsetInfo* iov) noexcept(false) {
0041   this->checkConnection();
0042 
0043   try {
0044     m_writeStmt->setInt(1, item->getId());
0045     m_writeStmt->setInt(2, item->getSMId());
0046     m_writeStmt->setInt(3, item->getFedId());
0047     m_writeStmt->setInt(4, item->getTTId());
0048     m_writeStmt->setInt(5, item->getCrystalId());
0049     m_writeStmt->setInt(6, item->getLow());
0050     m_writeStmt->setInt(7, item->getMid());
0051     m_writeStmt->setInt(8, item->getHigh());
0052 
0053     m_writeStmt->executeUpdate();
0054   } catch (SQLException& e) {
0055     throw(std::runtime_error("ODPedestalOffsetsDat::writeDB():  " + e.getMessage()));
0056   }
0057 }
0058 
0059 void ODPedestalOffsetsDat::fetchData(std::vector<ODPedestalOffsetsDat>* p,
0060                                      ODFEPedestalOffsetInfo* iov) noexcept(false) {
0061   this->checkConnection();
0062 
0063   iov->setConnection(m_env, m_conn);
0064   int iovID = iov->fetchID();
0065   if (!iovID) {
0066     std::cout << "ID not in the DB" << endl;
0067     return;
0068   }
0069 
0070   try {
0071     m_readStmt->setSQL("SELECT * FROM " + getTable() + " WHERE rec_id = :rec_id order by sm_id, fed_id, tt_id, cry_id");
0072     m_readStmt->setInt(1, iovID);
0073     ResultSet* rset = m_readStmt->executeQuery();
0074 
0075     //    std::vector< ODPedestalOffsetsDat > p;
0076     ODPedestalOffsetsDat dat;
0077     while (rset->next()) {
0078       // dat.setId( rset->getInt(1) );
0079       dat.setSMId(rset->getInt(2));
0080       dat.setFedId(rset->getInt(3));
0081       dat.setTTId(rset->getInt(4));
0082       dat.setCrystalId(rset->getInt(5));
0083       dat.setLow(rset->getInt(6));
0084       dat.setMid(rset->getInt(7));
0085       dat.setHigh(rset->getInt(8));
0086 
0087       p->push_back(dat);
0088     }
0089 
0090   } catch (SQLException& e) {
0091     throw(std::runtime_error("ODPedestalOffsetsDat::fetchData():  " + e.getMessage()));
0092   }
0093 }
0094 
0095 //  ************************************************************************   //
0096 
0097 void ODPedestalOffsetsDat::writeArrayDB(const std::vector<ODPedestalOffsetsDat>& data,
0098                                         ODFEPedestalOffsetInfo* iov) noexcept(false) {
0099   this->checkConnection();
0100 
0101   int iovID = iov->fetchID();
0102   if (!iovID) {
0103     throw(std::runtime_error("ODDelays::writeArrayDB:  ODFEDelaysInfo not in DB"));
0104   }
0105 
0106   int nrows = data.size();
0107   int* ids = new int[nrows];
0108   int* xx = new int[nrows];
0109   int* yy = new int[nrows];
0110   int* zz = new int[nrows];
0111   int* st = new int[nrows];
0112   int* xx1 = new int[nrows];
0113   int* yy1 = new int[nrows];
0114   int* zz1 = new int[nrows];
0115 
0116   ub2* ids_len = new ub2[nrows];
0117   ub2* x_len = new ub2[nrows];
0118   ub2* y_len = new ub2[nrows];
0119   ub2* z_len = new ub2[nrows];
0120   ub2* st_len = new ub2[nrows];
0121   ub2* x1_len = new ub2[nrows];
0122   ub2* y1_len = new ub2[nrows];
0123   ub2* z1_len = new ub2[nrows];
0124 
0125   ODPedestalOffsetsDat dataitem;
0126 
0127   int n_data = (int)data.size();
0128   for (int count = 0; count < n_data; count++) {
0129     dataitem = data[count];
0130     ids[count] = iovID;
0131     xx[count] = dataitem.getSMId();
0132     yy[count] = dataitem.getFedId();
0133     zz[count] = dataitem.getTTId();
0134     st[count] = dataitem.getCrystalId();
0135     xx1[count] = dataitem.getLow();
0136     yy1[count] = dataitem.getMid();
0137     zz1[count] = dataitem.getHigh();
0138 
0139     ids_len[count] = sizeof(ids[count]);
0140     x_len[count] = sizeof(xx[count]);
0141     y_len[count] = sizeof(yy[count]);
0142     z_len[count] = sizeof(zz[count]);
0143     st_len[count] = sizeof(st[count]);
0144     x1_len[count] = sizeof(xx1[count]);
0145     y1_len[count] = sizeof(yy1[count]);
0146     z1_len[count] = sizeof(zz1[count]);
0147   }
0148 
0149   try {
0150     m_writeStmt->setDataBuffer(1, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
0151     m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
0152     m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT, sizeof(yy[0]), y_len);
0153     m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT, sizeof(zz[0]), z_len);
0154     m_writeStmt->setDataBuffer(5, (dvoid*)st, OCCIINT, sizeof(st[0]), st_len);
0155     m_writeStmt->setDataBuffer(6, (dvoid*)xx1, OCCIINT, sizeof(xx1[0]), x1_len);
0156     m_writeStmt->setDataBuffer(7, (dvoid*)yy1, OCCIINT, sizeof(yy1[0]), y1_len);
0157     m_writeStmt->setDataBuffer(8, (dvoid*)zz1, OCCIINT, sizeof(zz1[0]), z1_len);
0158 
0159     m_writeStmt->executeArrayUpdate(nrows);
0160 
0161     delete[] ids;
0162     delete[] xx;
0163     delete[] yy;
0164     delete[] zz;
0165     delete[] st;
0166     delete[] xx1;
0167     delete[] yy1;
0168     delete[] zz1;
0169 
0170     delete[] ids_len;
0171     delete[] x_len;
0172     delete[] y_len;
0173     delete[] z_len;
0174     delete[] st_len;
0175     delete[] x1_len;
0176     delete[] y1_len;
0177     delete[] z1_len;
0178 
0179   } catch (SQLException& e) {
0180     throw(std::runtime_error("ODPedestalOffsetsDat::writeArrayDB():  " + e.getMessage()));
0181   }
0182 }