Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 
0005 #include "OnlineDB/EcalCondDB/interface/MonPedestalOffsetsDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/MonRunTag.h"
0007 #include "OnlineDB/EcalCondDB/interface/MonRunIOV.h"
0008 
0009 using namespace std;
0010 using namespace oracle::occi;
0011 
0012 MonPedestalOffsetsDat::MonPedestalOffsetsDat() {
0013   m_env = nullptr;
0014   m_conn = nullptr;
0015   m_writeStmt = nullptr;
0016   m_readStmt = nullptr;
0017 
0018   m_dacG1 = 0;
0019   m_dacG6 = 0;
0020   m_dacG12 = 0;
0021   m_taskStatus = false;
0022 }
0023 
0024 MonPedestalOffsetsDat::~MonPedestalOffsetsDat() {}
0025 
0026 void MonPedestalOffsetsDat::prepareWrite() noexcept(false) {
0027   this->checkConnection();
0028 
0029   try {
0030     m_writeStmt = m_conn->createStatement();
0031     m_writeStmt->setSQL(
0032         "INSERT INTO mon_pedestal_offsets_dat (iov_id, logic_id, "
0033         "dac_g1, dac_g6, dac_g12, task_status) "
0034         "VALUES (:iov_id, :logic_id, "
0035         ":dac_g1, :dac_g6, :dac_g12, :task_status)");
0036   } catch (SQLException& e) {
0037     throw(std::runtime_error("MonPedestalOffsetsDat::prepareWrite():  " + e.getMessage()));
0038   }
0039 }
0040 
0041 void MonPedestalOffsetsDat::writeDB(const EcalLogicID* ecid,
0042                                     const MonPedestalOffsetsDat* item,
0043                                     MonRunIOV* iov) noexcept(false) {
0044   this->checkConnection();
0045   this->checkPrepare();
0046 
0047   int iovID = iov->fetchID();
0048   if (!iovID) {
0049     throw(std::runtime_error("MonPedestalOffsetsDat::writeDB:  IOV not in DB"));
0050   }
0051 
0052   int logicID = ecid->getLogicID();
0053   if (!logicID) {
0054     throw(std::runtime_error("MonPedestalOffsetsDat::writeDB:  Bad EcalLogicID"));
0055   }
0056 
0057   try {
0058     m_writeStmt->setInt(1, iovID);
0059     m_writeStmt->setInt(2, logicID);
0060     m_writeStmt->setInt(3, item->getDACG1());
0061     m_writeStmt->setInt(4, item->getDACG6());
0062     m_writeStmt->setInt(5, item->getDACG12());
0063     m_writeStmt->setInt(6, item->getTaskStatus());
0064 
0065     m_writeStmt->executeUpdate();
0066   } catch (SQLException& e) {
0067     throw(std::runtime_error("MonPedestalOffsetsDat::writeDB():  " + e.getMessage()));
0068   }
0069 }
0070 
0071 void MonPedestalOffsetsDat::fetchData(std::map<EcalLogicID, MonPedestalOffsetsDat>* fillMap,
0072                                       MonRunIOV* iov,
0073                                       std::string mappa) noexcept(false) {
0074   this->checkConnection();
0075   fillMap->clear();
0076 
0077   iov->setConnection(m_env, m_conn);
0078   int iovID = iov->fetchID();
0079   if (!iovID) {
0080     //  throw(std::runtime_error("MonPedestalOffsetsDat::writeDB:  IOV not in DB"));
0081     return;
0082   }
0083 
0084   try {
0085     m_readStmt->setSQL(
0086         "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
0087         "d.dac_g1, d.dac_g6, d.dac_g12, d.task_status "
0088         "FROM channelview cv JOIN mon_pedestal_offsets_dat d "
0089         "ON cv.logic_id = d.logic_id AND cv.name = " +
0090         mappa + " WHERE d.iov_id = :iov_id");
0091     m_readStmt->setInt(1, iovID);
0092     ResultSet* rset = m_readStmt->executeQuery();
0093 
0094     std::pair<EcalLogicID, MonPedestalOffsetsDat> p;
0095     MonPedestalOffsetsDat dat;
0096     while (rset->next()) {
0097       p.first = EcalLogicID(rset->getString(1),   // name
0098                             rset->getInt(2),      // logic_id
0099                             rset->getInt(3),      // id1
0100                             rset->getInt(4),      // id2
0101                             rset->getInt(5),      // id3
0102                             rset->getString(6));  // maps_to
0103 
0104       dat.setDACG1(rset->getInt(7));
0105       dat.setDACG6(rset->getInt(8));
0106       dat.setDACG12(rset->getInt(9));
0107       dat.setTaskStatus(rset->getInt(10));
0108 
0109       p.second = dat;
0110       fillMap->insert(p);
0111     }
0112   } catch (SQLException& e) {
0113     throw(std::runtime_error("MonPedestalOffsetsDat::fetchData():  " + e.getMessage()));
0114   }
0115 }
0116 
0117 void MonPedestalOffsetsDat::writeArrayDB(const std::map<EcalLogicID, MonPedestalOffsetsDat>* data,
0118                                          MonRunIOV* iov) noexcept(false) {
0119   this->checkConnection();
0120   this->checkPrepare();
0121 
0122   int iovID = iov->fetchID();
0123   if (!iovID) {
0124     throw(std::runtime_error("MonPedestalOffsetsDat::writeArrayDB:  IOV not in DB"));
0125   }
0126 
0127   int nrows = data->size();
0128   int* ids = new int[nrows];
0129   int* iovid_vec = new int[nrows];
0130   float* xx = new float[nrows];
0131   float* yy = new float[nrows];
0132   float* zz = new float[nrows];
0133   int* st = new int[nrows];
0134 
0135   ub2* ids_len = new ub2[nrows];
0136   ub2* iov_len = new ub2[nrows];
0137   ub2* x_len = new ub2[nrows];
0138   ub2* y_len = new ub2[nrows];
0139   ub2* z_len = new ub2[nrows];
0140   ub2* st_len = new ub2[nrows];
0141 
0142   const EcalLogicID* channel;
0143   const MonPedestalOffsetsDat* dataitem;
0144   int count = 0;
0145   typedef map<EcalLogicID, MonPedestalOffsetsDat>::const_iterator CI;
0146   for (CI p = data->begin(); p != data->end(); ++p) {
0147     channel = &(p->first);
0148     int logicID = channel->getLogicID();
0149     if (!logicID) {
0150       throw(std::runtime_error("MonPedestalOffsetsDat::writeArrayDB:  Bad EcalLogicID"));
0151     }
0152     ids[count] = logicID;
0153     iovid_vec[count] = iovID;
0154 
0155     dataitem = &(p->second);
0156     // dataIface.writeDB( channel, dataitem, iov);
0157     float x = dataitem->getDACG1();
0158     float y = dataitem->getDACG6();
0159     float z = dataitem->getDACG12();
0160     int statu = dataitem->getTaskStatus();
0161 
0162     xx[count] = x;
0163     yy[count] = y;
0164     zz[count] = z;
0165     st[count] = statu;
0166 
0167     ids_len[count] = sizeof(ids[count]);
0168     iov_len[count] = sizeof(iovid_vec[count]);
0169 
0170     x_len[count] = sizeof(xx[count]);
0171     y_len[count] = sizeof(yy[count]);
0172     z_len[count] = sizeof(zz[count]);
0173     st_len[count] = sizeof(st[count]);
0174 
0175     count++;
0176   }
0177 
0178   try {
0179     m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
0180     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
0181     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT, sizeof(xx[0]), x_len);
0182     m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT, sizeof(yy[0]), y_len);
0183     m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT, sizeof(zz[0]), z_len);
0184     m_writeStmt->setDataBuffer(6, (dvoid*)st, OCCIINT, sizeof(st[0]), st_len);
0185 
0186     m_writeStmt->executeArrayUpdate(nrows);
0187 
0188     delete[] ids;
0189     delete[] iovid_vec;
0190     delete[] xx;
0191     delete[] yy;
0192     delete[] zz;
0193     delete[] st;
0194 
0195     delete[] ids_len;
0196     delete[] iov_len;
0197     delete[] x_len;
0198     delete[] y_len;
0199     delete[] z_len;
0200     delete[] st_len;
0201 
0202   } catch (SQLException& e) {
0203     throw(std::runtime_error("MonPedestalOffsetsDat::writeArrayDB():  " + e.getMessage()));
0204   }
0205 }