Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:02

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 
0005 #include "OnlineDB/EcalCondDB/interface/FEConfigCokeDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/FEConfigCokeInfo.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 
0009 using namespace std;
0010 using namespace oracle::occi;
0011 
0012 FEConfigCokeDat::FEConfigCokeDat() {
0013   m_env = nullptr;
0014   m_conn = nullptr;
0015   m_writeStmt = nullptr;
0016   m_readStmt = nullptr;
0017 
0018   clear();
0019 }
0020 
0021 FEConfigCokeDat::~FEConfigCokeDat() {}
0022 
0023 void FEConfigCokeDat::prepareWrite() noexcept(false) {
0024   this->checkConnection();
0025 
0026   try {
0027     m_writeStmt = m_conn->createStatement();
0028     m_writeStmt->setSQL(
0029         "INSERT INTO " + getTable() +
0030         " (coke_conf_id, logic_id, "
0031         " THRESHOLD, SUCC_EVENT_LIMIT, CUMUL_EVENT_LIMIT, SUCC_DETECT_ENABLE, CUMUL_DETECT_ENABLE, THD1_THRESHOLD, "
0032         "SUCC1_EV_LIMIT, CUMUL1_EV_LIMIT, COMBI_MODE, OCC_MODE, COMB_SUCC_DETECT, COMB_CUMUL_DETECT, OCC_DETECT, "
0033         "CUMUL1_DETECT, THD2_THRESHOLD , OCC_LIMIT , THD3_THRESHOLD , CUMUL2_LIMIT , STOP_BUFW  ) "
0034         "VALUES (:coke_conf_id, :logic_id, "
0035         ":m1, :m2, :m3, :m4, :m5, :m6, :m7, :m8, :m9, :m10, :m11, :m12, :m13, :m14, :m15, :m16, :m17, :m18, :m19 )");
0036   } catch (SQLException& e) {
0037     throw cms::Exception("SQLException") << "FEConfigCokeDat::prepareWrite(): " << e.getMessage();
0038   }
0039 }
0040 
0041 void FEConfigCokeDat::writeDB(const EcalLogicID* ecid,
0042                               const FEConfigCokeDat* item,
0043                               FEConfigCokeInfo* iconf) noexcept(false) {
0044   this->checkConnection();
0045   this->checkPrepare();
0046 
0047   int iconfID = iconf->fetchID();
0048   if (!iconfID) {
0049     throw(std::runtime_error("FEConfigCokeDat::writeDB:  ICONF not in DB"));
0050   }
0051 
0052   int logicID = ecid->getLogicID();
0053   if (!logicID) {
0054     throw(std::runtime_error("FEConfigCokeDat::writeDB:  Bad EcalLogicID"));
0055   }
0056 
0057   try {
0058     m_writeStmt->setInt(1, iconfID);
0059     m_writeStmt->setInt(2, logicID);
0060     m_writeStmt->setInt(3, item->getPar1());
0061     m_writeStmt->setInt(4, item->getPar2());
0062     m_writeStmt->setInt(5, item->getPar3());
0063     m_writeStmt->setInt(6, item->getPar4());
0064     m_writeStmt->setInt(7, item->getPar5());
0065     m_writeStmt->setInt(8, item->getPar6());
0066     m_writeStmt->setInt(9, item->getPar7());
0067     m_writeStmt->setInt(10, item->getPar8());
0068     m_writeStmt->setInt(11, item->getPar9());
0069     m_writeStmt->setInt(12, item->getPar10());
0070     m_writeStmt->setInt(13, item->getPar11());
0071     m_writeStmt->setInt(14, item->getPar12());
0072     m_writeStmt->setInt(15, item->getPar13());
0073     m_writeStmt->setInt(16, item->getPar14());
0074     m_writeStmt->setInt(17, item->getPar15());
0075     m_writeStmt->setInt(18, item->getPar16());
0076     m_writeStmt->setInt(19, item->getPar17());
0077     m_writeStmt->setInt(20, item->getPar18());
0078     m_writeStmt->setInt(21, item->getPar19());
0079 
0080     m_writeStmt->executeUpdate();
0081   } catch (SQLException& e) {
0082     throw cms::Exception("SQLException") << "FEConfigCokeDat::writeDB():  " << e.getMessage();
0083   }
0084 }
0085 
0086 void FEConfigCokeDat::fetchData(map<EcalLogicID, FEConfigCokeDat>* fillMap, FEConfigCokeInfo* iconf) noexcept(false) {
0087   this->checkConnection();
0088   fillMap->clear();
0089 
0090   iconf->setConnection(m_env, m_conn);
0091   int iconfID = iconf->fetchID();
0092   if (!iconfID) {
0093     //  throw(std::runtime_error("FEConfigCokeDat::writeDB:  ICONF 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.THRESHOLD, d.SUCC_EVENT_LIMIT, d.CUMUL_EVENT_LIMIT, d.SUCC_DETECT_ENABLE, d.CUMUL_DETECT_ENABLE, "
0101         "d.THD1_THRESHOLD, d.SUCC1_EV_LIMIT, d.CUMUL1_EV_LIMIT, d.COMBI_MODE, d.OCC_MODE, d.COMB_SUCC_DETECT, "
0102         "d.COMB_CUMUL_DETECT, d.OCC_DETECT, d.CUMUL1_DETECT, d.THD2_THRESHOLD , d.OCC_LIMIT , d.THD3_THRESHOLD , "
0103         "d.CUMUL2_LIMIT , d.STOP_BUFW  "
0104         "FROM channelview cv JOIN " +
0105         getTable() +
0106         " d "
0107         "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
0108         "WHERE coke_conf_id = :coke_conf_id");
0109     m_readStmt->setInt(1, iconfID);
0110     ResultSet* rset = m_readStmt->executeQuery();
0111 
0112     std::pair<EcalLogicID, FEConfigCokeDat> p;
0113     FEConfigCokeDat dat;
0114     while (rset->next()) {
0115       p.first = EcalLogicID(rset->getString(1),   // name
0116                             rset->getInt(2),      // logic_id
0117                             rset->getInt(3),      // id1
0118                             rset->getInt(4),      // id2
0119                             rset->getInt(5),      // id3
0120                             rset->getString(6));  // maps_to
0121 
0122       dat.setPar1(rset->getInt(7));
0123       dat.setPar2(rset->getInt(8));
0124       dat.setPar3(rset->getInt(9));
0125       dat.setPar4(rset->getInt(10));
0126       dat.setPar5(rset->getInt(11));
0127       dat.setPar6(rset->getInt(12));
0128       dat.setPar7(rset->getInt(13));
0129       dat.setPar8(rset->getInt(14));
0130       dat.setPar9(rset->getInt(15));
0131       dat.setPar10(rset->getInt(16));
0132       dat.setPar11(rset->getInt(17));
0133       dat.setPar12(rset->getInt(18));
0134       dat.setPar13(rset->getInt(19));
0135       dat.setPar14(rset->getInt(20));
0136       dat.setPar15(rset->getInt(21));
0137       dat.setPar16(rset->getInt(22));
0138       dat.setPar17(rset->getInt(23));
0139       dat.setPar18(rset->getInt(24));
0140       dat.setPar19(rset->getInt(25));
0141 
0142       p.second = dat;
0143       fillMap->insert(p);
0144     }
0145   } catch (SQLException& e) {
0146     throw cms::Exception("SQLException") << "FEConfigCokeDat::fetchData:  " << e.getMessage();
0147   }
0148 }
0149 
0150 void FEConfigCokeDat::writeArrayDB(const std::map<EcalLogicID, FEConfigCokeDat>* data,
0151                                    FEConfigCokeInfo* iconf) noexcept(false) {
0152   this->checkConnection();
0153   this->checkPrepare();
0154 
0155   int iconfID = iconf->fetchID();
0156   if (!iconfID) {
0157     throw(std::runtime_error("FEConfigCokeDat::writeArrayDB:  ICONF not in DB"));
0158   }
0159 
0160   int nrows = data->size();
0161   int* ids = new int[nrows];
0162   int* iconfid_vec = new int[nrows];
0163   int* xx1 = new int[nrows];
0164   int* xx2 = new int[nrows];
0165   int* xx3 = new int[nrows];
0166   int* xx4 = new int[nrows];
0167   int* xx5 = new int[nrows];
0168   int* xx6 = new int[nrows];
0169   int* xx7 = new int[nrows];
0170   int* xx8 = new int[nrows];
0171   int* xx9 = new int[nrows];
0172   int* xx10 = new int[nrows];
0173   int* xx11 = new int[nrows];
0174   int* xx12 = new int[nrows];
0175   int* xx13 = new int[nrows];
0176   int* xx14 = new int[nrows];
0177   int* xx15 = new int[nrows];
0178   int* xx16 = new int[nrows];
0179   int* xx17 = new int[nrows];
0180   int* xx18 = new int[nrows];
0181   int* xx19 = new int[nrows];
0182 
0183   ub2* ids_len = new ub2[nrows];
0184   ub2* iconf_len = new ub2[nrows];
0185   ub2* x1_len = new ub2[nrows];
0186   ub2* x2_len = new ub2[nrows];
0187   ub2* x3_len = new ub2[nrows];
0188   ub2* x4_len = new ub2[nrows];
0189   ub2* x5_len = new ub2[nrows];
0190   ub2* x6_len = new ub2[nrows];
0191   ub2* x7_len = new ub2[nrows];
0192   ub2* x8_len = new ub2[nrows];
0193   ub2* x9_len = new ub2[nrows];
0194   ub2* x10_len = new ub2[nrows];
0195   ub2* x11_len = new ub2[nrows];
0196   ub2* x12_len = new ub2[nrows];
0197   ub2* x13_len = new ub2[nrows];
0198   ub2* x14_len = new ub2[nrows];
0199   ub2* x15_len = new ub2[nrows];
0200   ub2* x16_len = new ub2[nrows];
0201   ub2* x17_len = new ub2[nrows];
0202   ub2* x18_len = new ub2[nrows];
0203   ub2* x19_len = new ub2[nrows];
0204 
0205   const EcalLogicID* channel;
0206   const FEConfigCokeDat* dataitem;
0207   int count = 0;
0208   typedef map<EcalLogicID, FEConfigCokeDat>::const_iterator CI;
0209   for (CI p = data->begin(); p != data->end(); ++p) {
0210     channel = &(p->first);
0211     int logicID = channel->getLogicID();
0212     if (!logicID) {
0213       throw(std::runtime_error("FEConfigCokeDat::writeArrayDB:  Bad EcalLogicID"));
0214     }
0215     ids[count] = logicID;
0216     iconfid_vec[count] = iconfID;
0217 
0218     dataitem = &(p->second);
0219 
0220     xx1[count] = dataitem->getPar1();
0221     xx2[count] = dataitem->getPar2();
0222     xx3[count] = dataitem->getPar3();
0223     xx4[count] = dataitem->getPar4();
0224     xx5[count] = dataitem->getPar5();
0225     xx6[count] = dataitem->getPar6();
0226     xx7[count] = dataitem->getPar7();
0227     xx8[count] = dataitem->getPar8();
0228     xx9[count] = dataitem->getPar9();
0229     xx10[count] = dataitem->getPar10();
0230     xx11[count] = dataitem->getPar11();
0231     xx12[count] = dataitem->getPar12();
0232     xx13[count] = dataitem->getPar13();
0233     xx14[count] = dataitem->getPar14();
0234     xx15[count] = dataitem->getPar15();
0235     xx16[count] = dataitem->getPar16();
0236     xx17[count] = dataitem->getPar17();
0237     xx18[count] = dataitem->getPar18();
0238     xx19[count] = dataitem->getPar19();
0239 
0240     ids_len[count] = sizeof(ids[count]);
0241     iconf_len[count] = sizeof(iconfid_vec[count]);
0242 
0243     x1_len[count] = sizeof(xx1[count]);
0244     x2_len[count] = sizeof(xx2[count]);
0245     x3_len[count] = sizeof(xx3[count]);
0246     x4_len[count] = sizeof(xx4[count]);
0247     x5_len[count] = sizeof(xx5[count]);
0248     x6_len[count] = sizeof(xx6[count]);
0249     x7_len[count] = sizeof(xx7[count]);
0250     x8_len[count] = sizeof(xx8[count]);
0251     x9_len[count] = sizeof(xx9[count]);
0252     x10_len[count] = sizeof(xx10[count]);
0253     x11_len[count] = sizeof(xx11[count]);
0254     x12_len[count] = sizeof(xx12[count]);
0255     x13_len[count] = sizeof(xx13[count]);
0256     x14_len[count] = sizeof(xx14[count]);
0257     x15_len[count] = sizeof(xx15[count]);
0258     x16_len[count] = sizeof(xx16[count]);
0259     x17_len[count] = sizeof(xx17[count]);
0260     x18_len[count] = sizeof(xx18[count]);
0261     x19_len[count] = sizeof(xx19[count]);
0262 
0263     count++;
0264   }
0265 
0266   try {
0267     m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]), iconf_len);
0268     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
0269     m_writeStmt->setDataBuffer(3, (dvoid*)xx1, OCCIINT, sizeof(xx1[0]), x1_len);
0270     m_writeStmt->setDataBuffer(4, (dvoid*)xx2, OCCIINT, sizeof(xx2[0]), x2_len);
0271     m_writeStmt->setDataBuffer(5, (dvoid*)xx3, OCCIINT, sizeof(xx3[0]), x3_len);
0272     m_writeStmt->setDataBuffer(6, (dvoid*)xx4, OCCIINT, sizeof(xx4[0]), x4_len);
0273     m_writeStmt->setDataBuffer(7, (dvoid*)xx5, OCCIINT, sizeof(xx5[0]), x5_len);
0274     m_writeStmt->setDataBuffer(8, (dvoid*)xx6, OCCIINT, sizeof(xx6[0]), x6_len);
0275     m_writeStmt->setDataBuffer(9, (dvoid*)xx7, OCCIINT, sizeof(xx7[0]), x7_len);
0276     m_writeStmt->setDataBuffer(10, (dvoid*)xx8, OCCIINT, sizeof(xx8[0]), x8_len);
0277     m_writeStmt->setDataBuffer(11, (dvoid*)xx9, OCCIINT, sizeof(xx9[0]), x9_len);
0278     m_writeStmt->setDataBuffer(12, (dvoid*)xx10, OCCIINT, sizeof(xx10[0]), x10_len);
0279     m_writeStmt->setDataBuffer(13, (dvoid*)xx11, OCCIINT, sizeof(xx11[0]), x11_len);
0280     m_writeStmt->setDataBuffer(14, (dvoid*)xx12, OCCIINT, sizeof(xx12[0]), x12_len);
0281     m_writeStmt->setDataBuffer(15, (dvoid*)xx13, OCCIINT, sizeof(xx13[0]), x13_len);
0282     m_writeStmt->setDataBuffer(16, (dvoid*)xx14, OCCIINT, sizeof(xx14[0]), x14_len);
0283     m_writeStmt->setDataBuffer(17, (dvoid*)xx15, OCCIINT, sizeof(xx15[0]), x15_len);
0284     m_writeStmt->setDataBuffer(18, (dvoid*)xx16, OCCIINT, sizeof(xx16[0]), x16_len);
0285     m_writeStmt->setDataBuffer(19, (dvoid*)xx17, OCCIINT, sizeof(xx17[0]), x17_len);
0286     m_writeStmt->setDataBuffer(20, (dvoid*)xx18, OCCIINT, sizeof(xx18[0]), x18_len);
0287     m_writeStmt->setDataBuffer(21, (dvoid*)xx19, OCCIINT, sizeof(xx19[0]), x19_len);
0288 
0289     m_writeStmt->executeArrayUpdate(nrows);
0290 
0291     delete[] ids;
0292     delete[] iconfid_vec;
0293     delete[] xx1;
0294     delete[] xx2;
0295     delete[] xx3;
0296     delete[] xx4;
0297     delete[] xx5;
0298     delete[] xx6;
0299     delete[] xx7;
0300     delete[] xx8;
0301     delete[] xx9;
0302     delete[] xx10;
0303     delete[] xx11;
0304     delete[] xx12;
0305     delete[] xx13;
0306     delete[] xx14;
0307     delete[] xx15;
0308     delete[] xx16;
0309     delete[] xx17;
0310     delete[] xx18;
0311     delete[] xx19;
0312 
0313     delete[] ids_len;
0314     delete[] iconf_len;
0315     delete[] x1_len;
0316     delete[] x2_len;
0317     delete[] x3_len;
0318     delete[] x4_len;
0319     delete[] x5_len;
0320     delete[] x6_len;
0321     delete[] x7_len;
0322     delete[] x8_len;
0323     delete[] x9_len;
0324     delete[] x10_len;
0325     delete[] x11_len;
0326     delete[] x12_len;
0327     delete[] x13_len;
0328     delete[] x14_len;
0329     delete[] x15_len;
0330     delete[] x16_len;
0331     delete[] x17_len;
0332     delete[] x18_len;
0333     delete[] x19_len;
0334 
0335   } catch (SQLException& e) {
0336     throw cms::Exception("SQLException") << "FEConfigCokeDat::writeArrayDB():  " << e.getMessage();
0337   }
0338 }