Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:59

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 
0005 #include "OnlineDB/EcalCondDB/interface/FEConfigLinDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/FEConfigLinInfo.h"
0007 
0008 using namespace std;
0009 using namespace oracle::occi;
0010 
0011 FEConfigLinDat::FEConfigLinDat() {
0012   m_env = nullptr;
0013   m_conn = nullptr;
0014   m_writeStmt = nullptr;
0015   m_readStmt = nullptr;
0016 
0017   m_multx12 = 0;
0018   m_multx6 = 0;
0019   m_multx1 = 0;
0020   m_shift12 = 0;
0021   m_shift6 = 0;
0022   m_shift1 = 0;
0023 }
0024 
0025 FEConfigLinDat::~FEConfigLinDat() {}
0026 
0027 void FEConfigLinDat::prepareWrite() noexcept(false) {
0028   this->checkConnection();
0029 
0030   try {
0031     m_writeStmt = m_conn->createStatement();
0032     m_writeStmt->setSQL(
0033         "INSERT INTO fe_config_lin_dat (lin_conf_id, logic_id, "
0034         " multx12, multx6, multx1, shift12, shift6, shift1 ) "
0035         "VALUES (:lin_conf_id, :logic_id, "
0036         ":multx12, :multx6, :multx1, :shift12, :shift6, :shift1 )");
0037   } catch (SQLException& e) {
0038     throw(std::runtime_error("FEConfigLinDat::prepareWrite():  " + e.getMessage()));
0039   }
0040 }
0041 
0042 void FEConfigLinDat::writeDB(const EcalLogicID* ecid,
0043                              const FEConfigLinDat* item,
0044                              FEConfigLinInfo* iconf) noexcept(false) {
0045   this->checkConnection();
0046   this->checkPrepare();
0047 
0048   int iconfID = iconf->fetchID();
0049   if (!iconfID) {
0050     throw(std::runtime_error("FEConfigLinDat::writeDB:  ICONF not in DB"));
0051   }
0052 
0053   int logicID = ecid->getLogicID();
0054   if (!logicID) {
0055     throw(std::runtime_error("FEConfigLinDat::writeDB:  Bad EcalLogicID"));
0056   }
0057 
0058   try {
0059     m_writeStmt->setInt(1, iconfID);
0060     m_writeStmt->setInt(2, logicID);
0061     m_writeStmt->setInt(3, item->getMultX12());
0062     m_writeStmt->setInt(4, item->getMultX6());
0063     m_writeStmt->setInt(5, item->getMultX1());
0064     m_writeStmt->setInt(6, item->getShift12());
0065     m_writeStmt->setInt(7, item->getShift6());
0066     m_writeStmt->setInt(8, item->getShift1());
0067 
0068     m_writeStmt->executeUpdate();
0069   } catch (SQLException& e) {
0070     throw(std::runtime_error("FEConfigLinDat::writeDB():  " + e.getMessage()));
0071   }
0072 }
0073 
0074 void FEConfigLinDat::fetchData(map<EcalLogicID, FEConfigLinDat>* fillMap, FEConfigLinInfo* iconf) noexcept(false) {
0075   this->checkConnection();
0076   fillMap->clear();
0077 
0078   iconf->setConnection(m_env, m_conn);
0079   int iconfID = iconf->fetchID();
0080   if (!iconfID) {
0081     //  throw(std::runtime_error("FEConfigLinDat::writeDB:  ICONF not in DB"));
0082     return;
0083   }
0084 
0085   try {
0086     m_readStmt->setSQL(
0087         "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
0088         "d.multx12, d.multx6, d.multx1, d.shift12, d.shift6, d.shift1 "
0089         "FROM channelview cv JOIN fe_config_lin_dat d "
0090         "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
0091         "WHERE lin_conf_id = :lin_conf_id");
0092     m_readStmt->setInt(1, iconfID);
0093     ResultSet* rset = m_readStmt->executeQuery();
0094 
0095     std::pair<EcalLogicID, FEConfigLinDat> p;
0096     FEConfigLinDat dat;
0097     while (rset->next()) {
0098       p.first = EcalLogicID(rset->getString(1),   // name
0099                             rset->getInt(2),      // logic_id
0100                             rset->getInt(3),      // id1
0101                             rset->getInt(4),      // id2
0102                             rset->getInt(5),      // id3
0103                             rset->getString(6));  // maps_to
0104 
0105       dat.setMultX12(rset->getInt(7));
0106       dat.setMultX6(rset->getInt(8));
0107       dat.setMultX1(rset->getInt(9));
0108       dat.setShift12(rset->getInt(10));
0109       dat.setShift6(rset->getInt(11));
0110       dat.setShift1(rset->getInt(12));
0111 
0112       p.second = dat;
0113       fillMap->insert(p);
0114     }
0115   } catch (SQLException& e) {
0116     throw(std::runtime_error("FEConfigLinDat::fetchData:  " + e.getMessage()));
0117   }
0118 }
0119 
0120 void FEConfigLinDat::writeArrayDB(const std::map<EcalLogicID, FEConfigLinDat>* data,
0121                                   FEConfigLinInfo* iconf) noexcept(false) {
0122   this->checkConnection();
0123   this->checkPrepare();
0124 
0125   int iconfID = iconf->fetchID();
0126   if (!iconfID) {
0127     throw(std::runtime_error("FEConfigLinDat::writeArrayDB:  ICONF not in DB"));
0128   }
0129 
0130   int nrows = data->size();
0131   int* ids = new int[nrows];
0132   int* iconfid_vec = new int[nrows];
0133   int* xx = new int[nrows];
0134   int* yy = new int[nrows];
0135   int* zz = new int[nrows];
0136   int* ww = new int[nrows];
0137   int* rr = new int[nrows];
0138   int* ss = new int[nrows];
0139 
0140   ub2* ids_len = new ub2[nrows];
0141   ub2* iconf_len = new ub2[nrows];
0142   ub2* x_len = new ub2[nrows];
0143   ub2* y_len = new ub2[nrows];
0144   ub2* z_len = new ub2[nrows];
0145   ub2* w_len = new ub2[nrows];
0146   ub2* r_len = new ub2[nrows];
0147   ub2* s_len = new ub2[nrows];
0148 
0149   const EcalLogicID* channel;
0150   const FEConfigLinDat* dataitem;
0151   int count = 0;
0152   typedef map<EcalLogicID, FEConfigLinDat>::const_iterator CI;
0153   for (CI p = data->begin(); p != data->end(); ++p) {
0154     channel = &(p->first);
0155     int logicID = channel->getLogicID();
0156     if (!logicID) {
0157       throw(std::runtime_error("FEConfigLinDat::writeArrayDB:  Bad EcalLogicID"));
0158     }
0159     ids[count] = logicID;
0160     iconfid_vec[count] = iconfID;
0161 
0162     dataitem = &(p->second);
0163     // dataIface.writeDB( channel, dataitem, iconf);
0164     int x = dataitem->getMultX12();
0165     int y = dataitem->getMultX6();
0166     int z = dataitem->getMultX1();
0167     int w = dataitem->getShift12();
0168     int r = dataitem->getShift6();
0169     int s = dataitem->getShift1();
0170 
0171     xx[count] = x;
0172     yy[count] = y;
0173     zz[count] = z;
0174     ww[count] = w;
0175     rr[count] = r;
0176     ss[count] = s;
0177 
0178     ids_len[count] = sizeof(ids[count]);
0179     iconf_len[count] = sizeof(iconfid_vec[count]);
0180 
0181     x_len[count] = sizeof(xx[count]);
0182     y_len[count] = sizeof(yy[count]);
0183     z_len[count] = sizeof(zz[count]);
0184     w_len[count] = sizeof(ww[count]);
0185     r_len[count] = sizeof(rr[count]);
0186     s_len[count] = sizeof(ss[count]);
0187 
0188     count++;
0189   }
0190 
0191   try {
0192     m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]), iconf_len);
0193     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
0194     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
0195     m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIINT, sizeof(yy[0]), y_len);
0196     m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIINT, sizeof(zz[0]), z_len);
0197     m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIINT, sizeof(ww[0]), w_len);
0198     m_writeStmt->setDataBuffer(7, (dvoid*)rr, OCCIINT, sizeof(rr[0]), r_len);
0199     m_writeStmt->setDataBuffer(8, (dvoid*)ss, OCCIINT, sizeof(ss[0]), s_len);
0200 
0201     m_writeStmt->executeArrayUpdate(nrows);
0202 
0203     delete[] ids;
0204     delete[] iconfid_vec;
0205     delete[] xx;
0206     delete[] yy;
0207     delete[] zz;
0208     delete[] ww;
0209     delete[] rr;
0210     delete[] ss;
0211 
0212     delete[] ids_len;
0213     delete[] iconf_len;
0214     delete[] x_len;
0215     delete[] y_len;
0216     delete[] z_len;
0217     delete[] w_len;
0218     delete[] r_len;
0219     delete[] s_len;
0220 
0221   } catch (SQLException& e) {
0222     throw(std::runtime_error("FEConfigLinDat::writeArrayDB():  " + e.getMessage()));
0223   }
0224 }