Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 
0005 #include "OnlineDB/EcalCondDB/interface/MODDCCDetailsDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/MODRunIOV.h"
0007 
0008 using namespace std;
0009 using namespace oracle::occi;
0010 
0011 MODDCCDetailsDat::MODDCCDetailsDat() {
0012   m_env = nullptr;
0013   m_conn = nullptr;
0014   m_writeStmt = nullptr;
0015   m_readStmt = nullptr;
0016 
0017   m_qpll = 0;
0018   m_opto = 0;
0019   m_tout = 0;
0020   m_head = 0;
0021   m_evnu = 0;
0022   m_bxnu = 0;
0023   m_evpa = 0;
0024   m_odpa = 0;
0025   m_blsi = 0;
0026   m_alff = 0;
0027   m_fuff = 0;
0028   m_fusu = 0;
0029 }
0030 
0031 MODDCCDetailsDat::~MODDCCDetailsDat() {}
0032 
0033 void MODDCCDetailsDat::prepareWrite() noexcept(false) {
0034   this->checkConnection();
0035 
0036   try {
0037     m_writeStmt = m_conn->createStatement();
0038     m_writeStmt->setSQL(" INSERT INTO " + getTable() +
0039                         " (iov_id, logic_id, "
0040                         " qpll_error, optical_link, data_timeout, dcc_header, event_number, bx_number, "
0041                         " even_parity, odd_parity, block_size, almost_full_fifo, full_fifo, "
0042                         " forced_full_supp ) "
0043                         " VALUES (:iov_id, :logic_id, "
0044                         " :1, :2, :3, :4, :5, :6, :7, :8, :9, :10, :11, :12 ) ");
0045   } catch (SQLException& e) {
0046     throw(std::runtime_error("MODDCCDetailsDat::prepareWrite():  " + e.getMessage()));
0047   }
0048 }
0049 
0050 void MODDCCDetailsDat::writeDB(const EcalLogicID* ecid, const MODDCCDetailsDat* item, MODRunIOV* iov) noexcept(false) {
0051   this->checkConnection();
0052   this->checkPrepare();
0053 
0054   int iovID = iov->fetchID();
0055   if (!iovID) {
0056     throw(std::runtime_error("MODDCCDetailsDat::writeDB:  IOV not in DB"));
0057   }
0058 
0059   int logicID = ecid->getLogicID();
0060   if (!logicID) {
0061     throw(std::runtime_error("MODDCCDetailsDat::writeDB:  Bad EcalLogicID"));
0062   }
0063 
0064   try {
0065     m_writeStmt->setInt(1, iovID);
0066     m_writeStmt->setInt(2, logicID);
0067     m_writeStmt->setInt(3, item->getQPLL());
0068     m_writeStmt->setInt(4, item->getOpticalLink());
0069     m_writeStmt->setInt(5, item->getDataTimeout());
0070     m_writeStmt->setInt(6, item->getHeader());
0071     m_writeStmt->setInt(7, item->getEventNumber());
0072     m_writeStmt->setInt(8, item->getBXNumber());
0073     m_writeStmt->setInt(9, item->getEvenParity());
0074     m_writeStmt->setInt(10, item->getOddParity());
0075     m_writeStmt->setInt(11, item->getBlockSize());
0076     m_writeStmt->setInt(12, item->getAlmostFullFIFO());
0077     m_writeStmt->setInt(13, item->getFullFIFO());
0078     m_writeStmt->setInt(14, item->getForcedFullSupp());
0079 
0080     m_writeStmt->executeUpdate();
0081   } catch (SQLException& e) {
0082     throw(std::runtime_error("MODDCCDetailsDat::writeDB():  " + e.getMessage()));
0083   }
0084 }
0085 
0086 void MODDCCDetailsDat::fetchData(std::map<EcalLogicID, MODDCCDetailsDat>* fillMap, MODRunIOV* iov) noexcept(false) {
0087   this->checkConnection();
0088   fillMap->clear();
0089 
0090   iov->setConnection(m_env, m_conn);
0091   int iovID = iov->fetchID();
0092   if (!iovID) {
0093     //  throw(std::runtime_error("MODDCCDetailsDat::writeDB:  IOV not in DB"));
0094     return;
0095   }
0096 
0097   try {
0098     m_readStmt->setSQL(
0099         "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
0100         " d.qpll_error, d.optical_link, d.data_timeout, d.dcc_header, d.event_number, d.bx_number, d.even_parity, "
0101         "d.odd_parity, d.block_size, d.almost_full_fifo, d.full_fifo, d.forced_full_supp "
0102         "FROM channelview cv JOIN " +
0103         getTable() +
0104         " d "
0105         "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
0106         "WHERE d.iov_id = :iov_id");
0107     m_readStmt->setInt(1, iovID);
0108     ResultSet* rset = m_readStmt->executeQuery();
0109 
0110     std::pair<EcalLogicID, MODDCCDetailsDat> p;
0111     MODDCCDetailsDat dat;
0112     while (rset->next()) {
0113       p.first = EcalLogicID(rset->getString(1),   // name
0114                             rset->getInt(2),      // logic_id
0115                             rset->getInt(3),      // id1
0116                             rset->getInt(4),      // id2
0117                             rset->getInt(5),      // id3
0118                             rset->getString(6));  // maps_to
0119 
0120       dat.setQPLL(rset->getInt(7));
0121       dat.setOpticalLink(rset->getInt(8));
0122       dat.setDataTimeout(rset->getInt(9));
0123       dat.setHeader(rset->getInt(10));
0124       dat.setEventNumber(rset->getInt(11));
0125       dat.setBXNumber(rset->getInt(12));
0126       dat.setEvenParity(rset->getInt(13));
0127       dat.setOddParity(rset->getInt(14));
0128       dat.setBlockSize(rset->getInt(15));
0129       dat.setAlmostFullFIFO(rset->getInt(16));
0130       dat.setFullFIFO(rset->getInt(17));
0131       dat.setForcedFullSupp(rset->getInt(18));
0132 
0133       p.second = dat;
0134       fillMap->insert(p);
0135     }
0136   } catch (SQLException& e) {
0137     throw(std::runtime_error("MODDCCDetailsDat::fetchData():  " + e.getMessage()));
0138   }
0139 }
0140 
0141 void MODDCCDetailsDat::writeArrayDB(const std::map<EcalLogicID, MODDCCDetailsDat>* data,
0142                                     MODRunIOV* iov) noexcept(false) {
0143   this->checkConnection();
0144   this->checkPrepare();
0145 
0146   int iovID = iov->fetchID();
0147   if (!iovID) {
0148     throw(std::runtime_error("MODDCCDetailsDat::writeArrayDB:  IOV not in DB"));
0149   }
0150 
0151   int nrows = data->size();
0152   int* ids = new int[nrows];
0153   int* iovid_vec = new int[nrows];
0154   int* xx1 = new int[nrows];
0155   int* xx2 = new int[nrows];
0156   int* xx3 = new int[nrows];
0157   int* xx4 = new int[nrows];
0158   int* xx5 = new int[nrows];
0159   int* xx6 = new int[nrows];
0160   int* xx7 = new int[nrows];
0161   int* xx8 = new int[nrows];
0162   int* xx9 = new int[nrows];
0163   int* xx10 = new int[nrows];
0164   int* xx11 = new int[nrows];
0165   int* xx12 = new int[nrows];
0166 
0167   ub2* ids_len = new ub2[nrows];
0168   ub2* iov_len = new ub2[nrows];
0169   ub2* x1_len = new ub2[nrows];
0170   ub2* x2_len = new ub2[nrows];
0171   ub2* x3_len = new ub2[nrows];
0172   ub2* x4_len = new ub2[nrows];
0173   ub2* x5_len = new ub2[nrows];
0174   ub2* x6_len = new ub2[nrows];
0175   ub2* x7_len = new ub2[nrows];
0176   ub2* x8_len = new ub2[nrows];
0177   ub2* x9_len = new ub2[nrows];
0178   ub2* x10_len = new ub2[nrows];
0179   ub2* x11_len = new ub2[nrows];
0180   ub2* x12_len = new ub2[nrows];
0181 
0182   const EcalLogicID* channel;
0183   const MODDCCDetailsDat* dataitem;
0184   int count = 0;
0185   typedef map<EcalLogicID, MODDCCDetailsDat>::const_iterator CI;
0186   for (CI p = data->begin(); p != data->end(); ++p) {
0187     channel = &(p->first);
0188     int logicID = channel->getLogicID();
0189     if (!logicID) {
0190       throw(std::runtime_error("MODDCCDetailsDat::writeArrayDB:  Bad EcalLogicID"));
0191     }
0192     ids[count] = logicID;
0193     iovid_vec[count] = iovID;
0194 
0195     dataitem = &(p->second);
0196     // dataIface.writeDB( channel, dataitem, iov);
0197     int x1 = dataitem->getQPLL();
0198     int x2 = dataitem->getOpticalLink();
0199     int x3 = dataitem->getDataTimeout();
0200     int x4 = dataitem->getHeader();
0201     int x5 = dataitem->getEventNumber();
0202     int x6 = dataitem->getBXNumber();
0203     int x7 = dataitem->getEvenParity();
0204     int x8 = dataitem->getOddParity();
0205     int x9 = dataitem->getBlockSize();
0206     int x10 = dataitem->getAlmostFullFIFO();
0207     int x11 = dataitem->getFullFIFO();
0208     int x12 = dataitem->getForcedFullSupp();
0209 
0210     xx1[count] = x1;
0211     xx2[count] = x2;
0212     xx3[count] = x3;
0213     xx4[count] = x4;
0214     xx5[count] = x5;
0215     xx6[count] = x6;
0216     xx7[count] = x7;
0217     xx8[count] = x8;
0218     xx9[count] = x9;
0219     xx10[count] = x10;
0220     xx11[count] = x11;
0221     xx12[count] = x12;
0222 
0223     ids_len[count] = sizeof(ids[count]);
0224     iov_len[count] = sizeof(iovid_vec[count]);
0225 
0226     x1_len[count] = sizeof(xx1[count]);
0227     x2_len[count] = sizeof(xx2[count]);
0228     x3_len[count] = sizeof(xx3[count]);
0229     x4_len[count] = sizeof(xx4[count]);
0230     x5_len[count] = sizeof(xx5[count]);
0231     x6_len[count] = sizeof(xx6[count]);
0232     x7_len[count] = sizeof(xx7[count]);
0233     x8_len[count] = sizeof(xx8[count]);
0234     x9_len[count] = sizeof(xx9[count]);
0235     x10_len[count] = sizeof(xx10[count]);
0236     x11_len[count] = sizeof(xx11[count]);
0237     x12_len[count] = sizeof(xx12[count]);
0238 
0239     count++;
0240   }
0241 
0242   try {
0243     m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
0244     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
0245     m_writeStmt->setDataBuffer(3, (dvoid*)xx1, OCCIINT, sizeof(xx1[0]), x1_len);
0246     m_writeStmt->setDataBuffer(4, (dvoid*)xx2, OCCIINT, sizeof(xx2[0]), x2_len);
0247     m_writeStmt->setDataBuffer(5, (dvoid*)xx3, OCCIINT, sizeof(xx3[0]), x3_len);
0248     m_writeStmt->setDataBuffer(6, (dvoid*)xx4, OCCIINT, sizeof(xx4[0]), x4_len);
0249     m_writeStmt->setDataBuffer(7, (dvoid*)xx5, OCCIINT, sizeof(xx5[0]), x5_len);
0250     m_writeStmt->setDataBuffer(8, (dvoid*)xx6, OCCIINT, sizeof(xx6[0]), x6_len);
0251     m_writeStmt->setDataBuffer(9, (dvoid*)xx7, OCCIINT, sizeof(xx7[0]), x7_len);
0252     m_writeStmt->setDataBuffer(10, (dvoid*)xx8, OCCIINT, sizeof(xx8[0]), x8_len);
0253     m_writeStmt->setDataBuffer(11, (dvoid*)xx9, OCCIINT, sizeof(xx9[0]), x9_len);
0254     m_writeStmt->setDataBuffer(12, (dvoid*)xx10, OCCIINT, sizeof(xx10[0]), x10_len);
0255     m_writeStmt->setDataBuffer(13, (dvoid*)xx11, OCCIINT, sizeof(xx11[0]), x11_len);
0256     m_writeStmt->setDataBuffer(14, (dvoid*)xx12, OCCIINT, sizeof(xx12[0]), x12_len);
0257 
0258     m_writeStmt->executeArrayUpdate(nrows);
0259 
0260     delete[] ids;
0261     delete[] iovid_vec;
0262     delete[] xx1;
0263     delete[] xx2;
0264     delete[] xx3;
0265     delete[] xx4;
0266     delete[] xx5;
0267     delete[] xx6;
0268     delete[] xx7;
0269     delete[] xx8;
0270     delete[] xx9;
0271     delete[] xx10;
0272     delete[] xx11;
0273     delete[] xx12;
0274 
0275     delete[] ids_len;
0276     delete[] iov_len;
0277     delete[] x1_len;
0278     delete[] x2_len;
0279     delete[] x3_len;
0280     delete[] x4_len;
0281     delete[] x5_len;
0282     delete[] x6_len;
0283     delete[] x7_len;
0284     delete[] x8_len;
0285     delete[] x9_len;
0286     delete[] x10_len;
0287     delete[] x11_len;
0288     delete[] x12_len;
0289 
0290   } catch (SQLException& e) {
0291     throw(std::runtime_error("MonPedestalsDat::writeArrayDB():  " + e.getMessage()));
0292   }
0293 }