Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:15:11

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 
0005 #include "OnlineDB/EcalCondDB/interface/DCUCCSDat.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 DCUCCSDat::DCUCCSDat() {
0013   m_env = nullptr;
0014   m_conn = nullptr;
0015   m_writeStmt = nullptr;
0016   m_readStmt = nullptr;
0017 
0018   m_m1_vdd1 = 0;
0019   m_m2_vdd1 = 0;
0020   m_m1_vdd2 = 0;
0021   m_m2_vdd2 = 0;
0022   m_m1_vinj = 0;
0023   m_m2_vinj = 0;
0024   m_m1_vcc = 0;
0025   m_m2_vcc = 0;
0026   m_m1_dcutemp = 0;
0027   m_m2_dcutemp = 0;
0028   m_ccstemplow = 0;
0029   m_ccstemphigh = 0;
0030 }
0031 
0032 DCUCCSDat::~DCUCCSDat() {}
0033 
0034 void DCUCCSDat::prepareWrite() noexcept(false) {
0035   this->checkConnection();
0036 
0037   try {
0038     m_writeStmt = m_conn->createStatement();
0039     m_writeStmt->setSQL(
0040         "INSERT INTO dcu_ccs_dat (iov_id, logic_id, "
0041         "m1_vdd1, m2_vdd1, m1_vdd2, m2_vdd2, m1_vinj, "
0042         "m2_vinj, m1_vcc, m2_vcc, m1_dcutemp, m2_dcutemp, "
0043         "ccstemplow, ccstemphigh) "
0044         "VALUES (:iov_id, :logic_id, "
0045         ":m1_vdd1, :m2_vdd1, :m1_vdd2, :m2_vdd2, :m1_vinj, "
0046         ":m2_vinj, :m1_vcc, :m2_vcc, :m1_dcutemp, "
0047         ":m2_dcutemp, :ccstemplow, :ccstemphigh)");
0048   } catch (SQLException& e) {
0049     throw(std::runtime_error("DCUCCSDat::prepareWrite():  " + e.getMessage()));
0050   }
0051 }
0052 
0053 void DCUCCSDat::writeDB(const EcalLogicID* ecid, const DCUCCSDat* 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("DCUCCSDat::writeDB:  IOV not in DB"));
0060   }
0061 
0062   int logicID = ecid->getLogicID();
0063   if (!logicID) {
0064     throw(std::runtime_error("DCUCCSDat::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->getM1VDD1());
0072     m_writeStmt->setFloat(4, item->getM2VDD1());
0073     m_writeStmt->setFloat(5, item->getM1VDD2());
0074     m_writeStmt->setFloat(6, item->getM2VDD2());
0075     m_writeStmt->setFloat(7, item->getM1Vinj());
0076     m_writeStmt->setFloat(8, item->getM2Vinj());
0077     m_writeStmt->setFloat(9, item->getM1Vcc());
0078     m_writeStmt->setFloat(10, item->getM2Vcc());
0079     m_writeStmt->setFloat(11, item->getM1DCUTemp());
0080     m_writeStmt->setFloat(12, item->getM2DCUTemp());
0081     m_writeStmt->setFloat(13, item->getCCSTempLow());
0082     m_writeStmt->setFloat(14, item->getCCSTempHigh());
0083 
0084     m_writeStmt->executeUpdate();
0085   } catch (SQLException& e) {
0086     throw(std::runtime_error("DCUCCSDat::writeDB():  " + e.getMessage()));
0087   }
0088 }
0089 
0090 void DCUCCSDat::fetchData(std::map<EcalLogicID, DCUCCSDat>* fillMap, DCUIOV* iov) noexcept(false) {
0091   this->checkConnection();
0092   fillMap->clear();
0093 
0094   iov->setConnection(m_env, m_conn);
0095   int iovID = iov->fetchID();
0096   if (!iovID) {
0097     //  throw(std::runtime_error("DCUCCSDat::writeDB:  IOV not in DB"));
0098     return;
0099   }
0100 
0101   try {
0102     m_readStmt->setSQL(
0103         "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, "
0104         "cv.maps_to, "
0105         "d.m1_vdd1, d.m2_vdd1, d.m1_vdd2, d.m2_vdd2, "
0106         "d.m1_vinj, d.m2_vinj, "
0107         "d.m1_vcc, d.m2_vcc, "
0108         "d.m1_dcutemp, d.m2_dcutemp, "
0109         "d.ccstemplow, d.ccstemphigh "
0110         "FROM channelview cv JOIN dcu_ccs_dat d "
0111         "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
0112         "WHERE d.iov_id = :iov_id");
0113     m_readStmt->setInt(1, iovID);
0114     ResultSet* rset = m_readStmt->executeQuery();
0115 
0116     std::pair<EcalLogicID, DCUCCSDat> p;
0117     DCUCCSDat dat;
0118     while (rset->next()) {
0119       p.first = EcalLogicID(rset->getString(1),   // name
0120                             rset->getInt(2),      // logic_id
0121                             rset->getInt(3),      // id1
0122                             rset->getInt(4),      // id2
0123                             rset->getInt(5),      // id3
0124                             rset->getString(6));  // maps_to
0125 
0126       dat.setVDD(rset->getFloat(7), rset->getFloat(9), rset->getFloat(8), rset->getFloat(10));
0127       dat.setVinj(rset->getFloat(11), rset->getFloat(12));
0128       dat.setVcc(rset->getFloat(13), rset->getFloat(14));
0129       dat.setDCUTemp(rset->getFloat(15), rset->getFloat(16));
0130       dat.setCCSTemp(rset->getFloat(17), rset->getFloat(18));
0131       p.second = dat;
0132       fillMap->insert(p);
0133     }
0134   } catch (SQLException& e) {
0135     throw(std::runtime_error("DCUCCSDat::fetchData():  " + e.getMessage()));
0136   }
0137 }
0138 
0139 void DCUCCSDat::writeArrayDB(const std::map<EcalLogicID, DCUCCSDat>* data, DCUIOV* iov) noexcept(false) {
0140   this->checkConnection();
0141   this->checkPrepare();
0142 
0143   int iovID = iov->fetchID();
0144   if (!iovID) {
0145     throw(std::runtime_error("DCUCCSDat::writeArrayDB:  IOV not in DB"));
0146   }
0147 
0148   int nrows = data->size();
0149   int* ids = new int[nrows];
0150   int* iovid_vec = new int[nrows];
0151   float* x1 = new float[nrows];
0152   float* x2 = new float[nrows];
0153   float* x3 = new float[nrows];
0154   float* x4 = new float[nrows];
0155   float* x5 = new float[nrows];
0156   float* x6 = new float[nrows];
0157   float* x7 = new float[nrows];
0158   float* x8 = new float[nrows];
0159   float* x9 = new float[nrows];
0160   float* xa = new float[nrows];
0161   float* xb = new float[nrows];
0162   float* xc = new float[nrows];
0163 
0164   ub2* ids_len = new ub2[nrows];
0165   ub2* iov_len = new ub2[nrows];
0166   ub2* x_len = new ub2[nrows];
0167 
0168   const EcalLogicID* channel;
0169   const DCUCCSDat* dataitem;
0170   int count = 0;
0171   typedef map<EcalLogicID, DCUCCSDat>::const_iterator CI;
0172   for (CI p = data->begin(); p != data->end(); ++p) {
0173     channel = &(p->first);
0174     int logicID = channel->getLogicID();
0175     if (!logicID) {
0176       throw(std::runtime_error("DCUCCSDat::writeArrayDB:  Bad EcalLogicID"));
0177     }
0178     ids[count] = logicID;
0179     iovid_vec[count] = iovID;
0180 
0181     dataitem = &(p->second);
0182 
0183     x1[count] = dataitem->getM1VDD1();
0184     x2[count] = dataitem->getM2VDD1();
0185     x3[count] = dataitem->getM1VDD2();
0186     x4[count] = dataitem->getM2VDD2();
0187     x5[count] = dataitem->getM1Vinj();
0188     x6[count] = dataitem->getM2Vinj();
0189     x7[count] = dataitem->getM1Vcc();
0190     x8[count] = dataitem->getM2Vcc();
0191     x9[count] = dataitem->getM1DCUTemp();
0192     xa[count] = dataitem->getM2DCUTemp();
0193     xb[count] = dataitem->getCCSTempLow();
0194     xc[count] = dataitem->getCCSTempHigh();
0195 
0196     ids_len[count] = sizeof(ids[count]);
0197     iov_len[count] = sizeof(iovid_vec[count]);
0198 
0199     x_len[count] = sizeof(x1[count]);
0200 
0201     count++;
0202   }
0203 
0204   try {
0205     m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
0206     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
0207     m_writeStmt->setDataBuffer(3, (dvoid*)x1, OCCIFLOAT, sizeof(x1[0]), x_len);
0208     m_writeStmt->setDataBuffer(3, (dvoid*)x2, OCCIFLOAT, sizeof(x1[0]), x_len);
0209     m_writeStmt->setDataBuffer(3, (dvoid*)x3, OCCIFLOAT, sizeof(x1[0]), x_len);
0210     m_writeStmt->setDataBuffer(3, (dvoid*)x4, OCCIFLOAT, sizeof(x1[0]), x_len);
0211     m_writeStmt->setDataBuffer(3, (dvoid*)x5, OCCIFLOAT, sizeof(x1[0]), x_len);
0212     m_writeStmt->setDataBuffer(3, (dvoid*)x6, OCCIFLOAT, sizeof(x1[0]), x_len);
0213     m_writeStmt->setDataBuffer(3, (dvoid*)x7, OCCIFLOAT, sizeof(x1[0]), x_len);
0214     m_writeStmt->setDataBuffer(3, (dvoid*)x8, OCCIFLOAT, sizeof(x1[0]), x_len);
0215     m_writeStmt->setDataBuffer(3, (dvoid*)x9, OCCIFLOAT, sizeof(x1[0]), x_len);
0216     m_writeStmt->setDataBuffer(3, (dvoid*)xa, OCCIFLOAT, sizeof(x1[0]), x_len);
0217     m_writeStmt->setDataBuffer(3, (dvoid*)xb, OCCIFLOAT, sizeof(x1[0]), x_len);
0218     m_writeStmt->setDataBuffer(3, (dvoid*)xc, OCCIFLOAT, sizeof(x1[0]), x_len);
0219 
0220     m_writeStmt->executeArrayUpdate(nrows);
0221 
0222     delete[] ids;
0223     delete[] iovid_vec;
0224     delete[] x1;
0225     delete[] x2;
0226     delete[] x3;
0227     delete[] x4;
0228     delete[] x5;
0229     delete[] x6;
0230     delete[] x7;
0231     delete[] x8;
0232     delete[] x9;
0233     delete[] xa;
0234     delete[] xb;
0235     delete[] xc;
0236 
0237     delete[] ids_len;
0238     delete[] iov_len;
0239     delete[] x_len;
0240 
0241   } catch (SQLException& e) {
0242     throw(std::runtime_error("DCUCCSDat::writeArrayDB():  " + e.getMessage()));
0243   }
0244 }