Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 
0005 #include "OnlineDB/EcalCondDB/interface/DCULVRVoltagesDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/RunTag.h"
0007 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
0008 
0009 using namespace std;
0010 using namespace oracle::occi;
0011 
0012 DCULVRVoltagesDat::DCULVRVoltagesDat() {
0013   m_env = nullptr;
0014   m_conn = nullptr;
0015   m_writeStmt = nullptr;
0016   m_readStmt = nullptr;
0017 
0018   m_vfe1_A = 0;
0019   m_vfe2_A = 0;
0020   m_vfe3_A = 0;
0021   m_vfe4_A = 0;
0022   m_vfe5_A = 0;
0023   m_VCC = 0;
0024   m_vfe4_5_D = 0;
0025   m_vfe1_2_3_D = 0;
0026   m_buffer = 0;
0027   m_fenix = 0;
0028   m_V43_A = 0;
0029   m_OCM = 0;
0030   m_GOH = 0;
0031   m_INH = 0;
0032   m_V43_D = 0;
0033 }
0034 
0035 DCULVRVoltagesDat::~DCULVRVoltagesDat() {}
0036 
0037 void DCULVRVoltagesDat::prepareWrite() noexcept(false) {
0038   this->checkConnection();
0039 
0040   try {
0041     m_writeStmt = m_conn->createStatement();
0042     m_writeStmt->setSQL(
0043         "INSERT INTO dcu_lvr_voltages_dat (iov_id, logic_id, "
0044         "vfe1_A, vfe2_A, vfe3_A, vfe4_A, vfe5_A, VCC, vfe4_5_D, vfe1_2_3_D, buffer, fenix, V43_A, OCM, GOH, INH, "
0045         "V43_D) "
0046         "VALUES (:iov_id, :logic_id, "
0047         ":3, :4, :5, :6, :7, :8, :9, :10, :11, :12, :13, :14, :15, :16, :17)");
0048   } catch (SQLException& e) {
0049     throw(std::runtime_error("DCULVRVoltagesDat::prepareWrite():  " + e.getMessage()));
0050   }
0051 }
0052 
0053 void DCULVRVoltagesDat::writeDB(const EcalLogicID* ecid, const DCULVRVoltagesDat* item, DCUIOV* iov) noexcept(false) {
0054   this->checkConnection();
0055   this->checkPrepare();
0056 
0057   int iovID = iov->fetchID();
0058   if (!iovID) {
0059     throw(std::runtime_error("DCULVRVoltagesDat::writeDB:  IOV not in DB"));
0060   }
0061 
0062   int logicID = ecid->getLogicID();
0063   if (!logicID) {
0064     throw(std::runtime_error("DCULVRVoltagesDat::writeDB:  Bad EcalLogicID"));
0065   }
0066 
0067   try {
0068     m_writeStmt->setInt(1, iovID);
0069     m_writeStmt->setInt(2, logicID);
0070 
0071     m_writeStmt->setFloat(3, item->getVFE1_A());
0072     m_writeStmt->setFloat(4, item->getVFE2_A());
0073     m_writeStmt->setFloat(5, item->getVFE3_A());
0074     m_writeStmt->setFloat(6, item->getVFE4_A());
0075     m_writeStmt->setFloat(7, item->getVFE5_A());
0076     m_writeStmt->setFloat(8, item->getVCC());
0077     m_writeStmt->setFloat(9, item->getVFE4_5_D());
0078     m_writeStmt->setFloat(10, item->getVFE1_2_3_D());
0079     m_writeStmt->setFloat(11, item->getBuffer());
0080     m_writeStmt->setFloat(12, item->getFenix());
0081     m_writeStmt->setFloat(13, item->getV43_A());
0082     m_writeStmt->setFloat(14, item->getOCM());
0083     m_writeStmt->setFloat(15, item->getGOH());
0084     m_writeStmt->setFloat(16, item->getINH());
0085     m_writeStmt->setFloat(17, item->getV43_D());
0086 
0087     m_writeStmt->executeUpdate();
0088   } catch (SQLException& e) {
0089     throw(std::runtime_error("DCULVRVoltagesDat::writeDB():  " + e.getMessage()));
0090   }
0091 }
0092 
0093 void DCULVRVoltagesDat::fetchData(std::map<EcalLogicID, DCULVRVoltagesDat>* fillMap, DCUIOV* iov) noexcept(false) {
0094   this->checkConnection();
0095   fillMap->clear();
0096 
0097   iov->setConnection(m_env, m_conn);
0098   int iovID = iov->fetchID();
0099   if (!iovID) {
0100     //  throw(std::runtime_error("DCULVRVoltagesDat::writeDB:  IOV not in DB"));
0101     return;
0102   }
0103 
0104   try {
0105     m_readStmt->setSQL(
0106         "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
0107         "d.vfe1_A, d.vfe2_A, d.vfe3_A, d.vfe4_A, d.vfe5_A, d.VCC, d.vfe4_5_D, d.vfe1_2_3_D, d.buffer, d.fenix, "
0108         "d.V43_A, d.OCM, d.GOH, d.INH, d.V43_D  "
0109         "FROM channelview cv JOIN dcu_lvr_voltages_dat d "
0110         "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
0111         "WHERE d.iov_id = :iov_id");
0112     m_readStmt->setInt(1, iovID);
0113     ResultSet* rset = m_readStmt->executeQuery();
0114 
0115     std::pair<EcalLogicID, DCULVRVoltagesDat> p;
0116     DCULVRVoltagesDat dat;
0117     while (rset->next()) {
0118       p.first = EcalLogicID(rset->getString(1),   // name
0119                             rset->getInt(2),      // logic_id
0120                             rset->getInt(3),      // id1
0121                             rset->getInt(4),      // id2
0122                             rset->getInt(5),      // id3
0123                             rset->getString(6));  // maps_to
0124 
0125       dat.setVFE1_A(rset->getFloat(7));
0126       dat.setVFE2_A(rset->getFloat(8));
0127       dat.setVFE3_A(rset->getFloat(9));
0128       dat.setVFE4_A(rset->getFloat(10));
0129       dat.setVFE5_A(rset->getFloat(11));
0130       dat.setVCC(rset->getFloat(12));
0131       dat.setVFE4_5_D(rset->getFloat(13));
0132       dat.setVFE1_2_3_D(rset->getFloat(14));
0133       dat.setBuffer(rset->getFloat(15));
0134       dat.setFenix(rset->getFloat(16));
0135       dat.setV43_A(rset->getFloat(17));
0136       dat.setOCM(rset->getFloat(18));
0137       dat.setGOH(rset->getFloat(19));
0138       dat.setINH(rset->getFloat(20));
0139       dat.setV43_D(rset->getFloat(21));
0140 
0141       p.second = dat;
0142       fillMap->insert(p);
0143     }
0144   } catch (SQLException& e) {
0145     throw(std::runtime_error("DCULVRVoltagesDat::fetchData():  " + e.getMessage()));
0146   }
0147 }
0148 void DCULVRVoltagesDat::writeArrayDB(const std::map<EcalLogicID, DCULVRVoltagesDat>* data,
0149                                      DCUIOV* iov) noexcept(false) {
0150   this->checkConnection();
0151   this->checkPrepare();
0152 
0153   int iovID = iov->fetchID();
0154   if (!iovID) {
0155     throw(std::runtime_error("DCULVRVoltagesDat::writeArrayDB:  IOV not in DB"));
0156   }
0157 
0158   int nrows = data->size();
0159   int* ids = new int[nrows];
0160   int* iovid_vec = new int[nrows];
0161   float* xx = new float[nrows];
0162   float* yy = new float[nrows];
0163   float* zz = new float[nrows];
0164   float* ww = new float[nrows];
0165   float* uu = new float[nrows];
0166   float* tt = new float[nrows];
0167   float* rr = new float[nrows];
0168   float* pp = new float[nrows];
0169   float* ll = new float[nrows];
0170   float* mm = new float[nrows];
0171   float* nn = new float[nrows];
0172   float* qq = new float[nrows];
0173   float* ss = new float[nrows];
0174   float* vv = new float[nrows];
0175   float* hh = new float[nrows];
0176 
0177   ub2* ids_len = new ub2[nrows];
0178   ub2* iov_len = new ub2[nrows];
0179   ub2* x_len = new ub2[nrows];
0180   ub2* y_len = new ub2[nrows];
0181   ub2* z_len = new ub2[nrows];
0182   ub2* w_len = new ub2[nrows];
0183   ub2* u_len = new ub2[nrows];
0184   ub2* t_len = new ub2[nrows];
0185   ub2* r_len = new ub2[nrows];
0186   ub2* p_len = new ub2[nrows];
0187   ub2* l_len = new ub2[nrows];
0188   ub2* m_len = new ub2[nrows];
0189   ub2* n_len = new ub2[nrows];
0190   ub2* q_len = new ub2[nrows];
0191   ub2* s_len = new ub2[nrows];
0192   ub2* v_len = new ub2[nrows];
0193   ub2* h_len = new ub2[nrows];
0194 
0195   const EcalLogicID* channel;
0196   const DCULVRVoltagesDat* dataitem;
0197   int count = 0;
0198   typedef map<EcalLogicID, DCULVRVoltagesDat>::const_iterator CI;
0199   for (CI p = data->begin(); p != data->end(); ++p) {
0200     channel = &(p->first);
0201     int logicID = channel->getLogicID();
0202     if (!logicID) {
0203       throw(std::runtime_error("DCULVRVoltagesDat::writeArrayDB:  Bad EcalLogicID"));
0204     }
0205     ids[count] = logicID;
0206     iovid_vec[count] = iovID;
0207 
0208     dataitem = &(p->second);
0209     // dataIface.writeDB( channel, dataitem, iov);
0210     float x = dataitem->getVFE1_A();
0211     float y = dataitem->getVFE2_A();
0212     float z = dataitem->getVFE3_A();
0213     float w = dataitem->getVFE4_A();
0214     float u = dataitem->getVFE5_A();
0215     float t = dataitem->getVCC();
0216     float r = dataitem->getVFE4_5_D();
0217     float pi = dataitem->getVFE1_2_3_D();
0218     float l = dataitem->getBuffer();
0219     float m = dataitem->getFenix();
0220     float n = dataitem->getV43_A();
0221     float q = dataitem->getOCM();
0222     float s = dataitem->getGOH();
0223     float v = dataitem->getINH();
0224     float h = dataitem->getV43_D();
0225 
0226     xx[count] = x;
0227     yy[count] = y;
0228     zz[count] = z;
0229     ww[count] = w;
0230     uu[count] = u;
0231     tt[count] = t;
0232     rr[count] = r;
0233     pp[count] = pi;
0234     ll[count] = l;
0235     mm[count] = m;
0236     nn[count] = n;
0237     qq[count] = q;
0238     ss[count] = s;
0239     vv[count] = v;
0240     hh[count] = h;
0241 
0242     ids_len[count] = sizeof(ids[count]);
0243     iov_len[count] = sizeof(iovid_vec[count]);
0244 
0245     x_len[count] = sizeof(xx[count]);
0246     y_len[count] = sizeof(yy[count]);
0247     z_len[count] = sizeof(zz[count]);
0248     w_len[count] = sizeof(ww[count]);
0249     u_len[count] = sizeof(uu[count]);
0250     t_len[count] = sizeof(tt[count]);
0251     r_len[count] = sizeof(rr[count]);
0252     p_len[count] = sizeof(pp[count]);
0253     l_len[count] = sizeof(ll[count]);
0254     m_len[count] = sizeof(mm[count]);
0255     n_len[count] = sizeof(nn[count]);
0256     q_len[count] = sizeof(qq[count]);
0257     s_len[count] = sizeof(ss[count]);
0258     v_len[count] = sizeof(vv[count]);
0259     h_len[count] = sizeof(hh[count]);
0260     count++;
0261   }
0262   try {
0263     m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
0264     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
0265     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT, sizeof(xx[0]), x_len);
0266     m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT, sizeof(yy[0]), y_len);
0267     m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT, sizeof(zz[0]), z_len);
0268     m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIFLOAT, sizeof(ww[0]), w_len);
0269     m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIFLOAT, sizeof(uu[0]), u_len);
0270     m_writeStmt->setDataBuffer(8, (dvoid*)tt, OCCIFLOAT, sizeof(tt[0]), t_len);
0271     m_writeStmt->setDataBuffer(9, (dvoid*)rr, OCCIFLOAT, sizeof(rr[0]), r_len);
0272     m_writeStmt->setDataBuffer(10, (dvoid*)pp, OCCIFLOAT, sizeof(pp[0]), p_len);
0273     m_writeStmt->setDataBuffer(11, (dvoid*)ll, OCCIFLOAT, sizeof(ll[0]), l_len);
0274     m_writeStmt->setDataBuffer(12, (dvoid*)mm, OCCIFLOAT, sizeof(mm[0]), m_len);
0275     m_writeStmt->setDataBuffer(13, (dvoid*)nn, OCCIFLOAT, sizeof(nn[0]), n_len);
0276     m_writeStmt->setDataBuffer(14, (dvoid*)qq, OCCIFLOAT, sizeof(qq[0]), q_len);
0277     m_writeStmt->setDataBuffer(15, (dvoid*)ss, OCCIFLOAT, sizeof(ss[0]), s_len);
0278     m_writeStmt->setDataBuffer(16, (dvoid*)vv, OCCIFLOAT, sizeof(vv[0]), v_len);
0279     m_writeStmt->setDataBuffer(17, (dvoid*)hh, OCCIFLOAT, sizeof(hh[0]), h_len);
0280 
0281     m_writeStmt->executeArrayUpdate(nrows);
0282 
0283     delete[] ids;
0284     delete[] iovid_vec;
0285     delete[] xx;
0286     delete[] yy;
0287     delete[] zz;
0288     delete[] ww;
0289     delete[] uu;
0290     delete[] tt;
0291     delete[] rr;
0292     delete[] pp;
0293     delete[] ll;
0294     delete[] mm;
0295     delete[] nn;
0296     delete[] qq;
0297     delete[] ss;
0298     delete[] vv;
0299     delete[] hh;
0300 
0301     delete[] ids_len;
0302     delete[] iov_len;
0303     delete[] x_len;
0304     delete[] y_len;
0305     delete[] z_len;
0306     delete[] w_len;
0307     delete[] u_len;
0308     delete[] t_len;
0309     delete[] r_len;
0310     delete[] p_len;
0311     delete[] l_len;
0312     delete[] m_len;
0313     delete[] n_len;
0314     delete[] q_len;
0315     delete[] s_len;
0316     delete[] v_len;
0317     delete[] h_len;
0318 
0319   } catch (SQLException& e) {
0320     throw(std::runtime_error("DCULVRVoltagesDat::writeArrayDB():  " + e.getMessage()));
0321   }
0322 }