Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 
0005 #include "OnlineDB/EcalCondDB/interface/MonPulseShapeDat.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 MonPulseShapeDat::MonPulseShapeDat() {
0013   m_env = nullptr;
0014   m_conn = nullptr;
0015   m_writeStmt = nullptr;
0016   m_readStmt = nullptr;
0017 
0018   m_samplesG1.assign(10, 0);
0019   m_samplesG6.assign(10, 0);
0020   m_samplesG12.assign(10, 0);
0021 }
0022 
0023 MonPulseShapeDat::~MonPulseShapeDat() {}
0024 
0025 void MonPulseShapeDat::prepareWrite() noexcept(false) {
0026   this->checkConnection();
0027 
0028   try {
0029     m_writeStmt = m_conn->createStatement();
0030     m_writeStmt->setSQL(
0031         "INSERT INTO mon_pulse_shape_dat (iov_id, logic_id, "
0032         "g1_avg_sample_01, g1_avg_sample_02, g1_avg_sample_03, g1_avg_sample_04, g1_avg_sample_05, g1_avg_sample_06, "
0033         "g1_avg_sample_07, g1_avg_sample_08, g1_avg_sample_09, g1_avg_sample_10, "
0034         "g6_avg_sample_01, g6_avg_sample_02, g6_avg_sample_03, g6_avg_sample_04, g6_avg_sample_05, g6_avg_sample_06, "
0035         "g6_avg_sample_07, g6_avg_sample_08, g6_avg_sample_09, g6_avg_sample_10, "
0036         "g12_avg_sample_01, g12_avg_sample_02, g12_avg_sample_03, g12_avg_sample_04, g12_avg_sample_05, "
0037         "g12_avg_sample_06, g12_avg_sample_07, g12_avg_sample_08, g12_avg_sample_09, g12_avg_sample_10) "
0038         "VALUES (:iov_id, :logic_id, "
0039         ":g1_avg_sample_01, :g1_avg_sample_02, :g1_avg_sample_03, :g1_avg_sample_04, :g1_avg_sample_05, "
0040         ":g1_avg_sample_06, :g1_avg_sample_07, :g1_avg_sample_08, :g1_avg_sample_09, :g1_avg_sample_10,"
0041         ":g6_avg_sample_01, :g6_avg_sample_02, :g6_avg_sample_03, :g6_avg_sample_04, :g6_avg_sample_05, "
0042         ":g6_avg_sample_06, :g6_avg_sample_07, :g6_avg_sample_08, :g6_avg_sample_09, :g6_avg_sample_10,"
0043         ":g12_avg_sample_01, :g12_avg_sample_02, :g12_avg_sample_03, :g12_avg_sample_04, :g12_avg_sample_05, "
0044         ":g12_avg_sample_06, :g12_avg_sample_07, :g12_avg_sample_08, :g12_avg_sample_09, :g12_avg_sample_10)");
0045 
0046   } catch (SQLException& e) {
0047     throw(std::runtime_error("MonPulseShapeDat::prepareWrite():  " + e.getMessage()));
0048   }
0049 }
0050 
0051 void MonPulseShapeDat::writeDB(const EcalLogicID* ecid, const MonPulseShapeDat* item, MonRunIOV* iov) noexcept(false) {
0052   this->checkConnection();
0053   this->checkPrepare();
0054 
0055   int iovID = iov->fetchID();
0056   if (!iovID) {
0057     throw(std::runtime_error("MonPulseShapeDat::writeDB:  IOV not in DB"));
0058   }
0059 
0060   int logicID = ecid->getLogicID();
0061   if (!logicID) {
0062     throw(std::runtime_error("MonPulseShapeDat::writeDB:  Bad EcalLogicID"));
0063   }
0064 
0065   try {
0066     m_writeStmt->setInt(1, iovID);
0067     m_writeStmt->setInt(2, logicID);
0068 
0069     int gain[] = {1, 6, 12};
0070     std::vector<float> samples;
0071     for (int i = 0; i < 3; i++) {
0072       samples = item->getSamples(gain[i]);
0073       for (int j = 0; j < 10; j++) {
0074         m_writeStmt->setFloat(3 + (10 * i) + j, samples.at(j));
0075       }
0076     }
0077 
0078     m_writeStmt->executeUpdate();
0079   } catch (SQLException& e) {
0080     throw(std::runtime_error("MonPulseShapeDat::writeDB:  " + e.getMessage()));
0081   } catch (exception& e) {
0082     throw(std::runtime_error("MonPulseShapeDat::writeDB:  " + string(e.what())));
0083   }
0084 }
0085 
0086 void MonPulseShapeDat::fetchData(std::map<EcalLogicID, MonPulseShapeDat>* fillMap, MonRunIOV* 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("MonPulseShapeDat::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.g1_avg_sample_01, d.g1_avg_sample_02, d.g1_avg_sample_03, d.g1_avg_sample_04, d.g1_avg_sample_05, "
0101         "d.g1_avg_sample_06, d.g1_avg_sample_07, d.g1_avg_sample_08, d.g1_avg_sample_09, d.g1_avg_sample_10, "
0102         "d.g6_avg_sample_01, d.g6_avg_sample_02, d.g6_avg_sample_03, d.g6_avg_sample_04, d.g6_avg_sample_05, "
0103         "d.g6_avg_sample_06, d.g6_avg_sample_07, d.g6_avg_sample_08, d.g6_avg_sample_09, d.g6_avg_sample_10, "
0104         "d.g12_avg_sample_01, d.g12_avg_sample_02, d.g12_avg_sample_03, d.g12_avg_sample_04, d.g12_avg_sample_05, "
0105         "d.g12_avg_sample_06, d.g12_avg_sample_07, d.g12_avg_sample_08, d.g12_avg_sample_09, d.g12_avg_sample_10 "
0106         "FROM channelview cv JOIN mon_pulse_shape_dat d "
0107         "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
0108         "WHERE d.iov_id = :iov_id");
0109     m_readStmt->setInt(1, iovID);
0110     ResultSet* rset = m_readStmt->executeQuery();
0111 
0112     std::pair<EcalLogicID, MonPulseShapeDat> p;
0113     MonPulseShapeDat 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       int gain[] = {1, 6, 12};
0123       std::vector<float> samples(10);
0124       for (int i = 0; i < 3; i++) {
0125         samples.clear();
0126         for (int j = 0; j < 10; j++) {
0127           samples.push_back(rset->getFloat(7 + (10 * i) + j));
0128         }
0129         dat.setSamples(samples, gain[i]);
0130       }
0131 
0132       p.second = dat;
0133       fillMap->insert(p);
0134     }
0135   } catch (SQLException& e) {
0136     throw(std::runtime_error("MonPulseShapeDat::fetchData:  " + e.getMessage()));
0137   }
0138 }