Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <stdexcept>
0002 #include <string>
0003 #include <cmath>
0004 
0005 #include "OnlineDB/EcalCondDB/interface/RunDCSLVDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
0007 
0008 using namespace std;
0009 using namespace oracle::occi;
0010 
0011 RunDCSLVDat::RunDCSLVDat() {
0012   m_env = nullptr;
0013   m_conn = nullptr;
0014   m_writeStmt = nullptr;
0015   m_readStmt = nullptr;
0016 
0017   m_lv = 0;
0018   m_lvnom = 0;
0019   m_status = 0;
0020   m_tstatus = 0;
0021 }
0022 
0023 RunDCSLVDat::~RunDCSLVDat() {}
0024 
0025 void RunDCSLVDat::prepareWrite() noexcept(false) {}
0026 
0027 void RunDCSLVDat::writeDB(const EcalLogicID* ecid, const RunDCSLVDat* item, RunIOV* iov) noexcept(false) {}
0028 
0029 void RunDCSLVDat::fetchData(map<EcalLogicID, RunDCSLVDat>* fillMap, RunIOV* iov) noexcept(false) {
0030   fetchLastData(fillMap);
0031 }
0032 
0033 ResultSet* RunDCSLVDat::getBarrelRset() {
0034   ResultSet* rset = nullptr;
0035   string query =
0036       "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
0037       " d.value_number , '5' NOMINAL_VALUE , d.VALUE_TIMESTAMP "
0038       "FROM " +
0039       getEBAccount() +
0040       ".FWWIENERMARATHONCHANNEL_LV d "
0041       " JOIN " +
0042       getEBAccount() +
0043       ".LV_MAPPING h on "
0044       " h.DPID = d.DPID join channelview cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name and "
0045       "dpe_name='MEASUREMENTSENSEVOLTAGE' ";
0046   try {
0047     m_readStmt->setSQL(query);
0048     rset = m_readStmt->executeQuery();
0049   } catch (SQLException& e) {
0050 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
0051     throw(std::runtime_error(std::string("RunDCSLVDat::getBarrelRset():  ") + e.getMessage() + " " + query));
0052 #else
0053     throw(std::runtime_error(std::string("RunDCSLVDat::getBarrelRset():  error code ") +
0054                              std::to_string(e.getErrorCode()) + " " + query));
0055 #endif
0056   }
0057   return rset;
0058 }
0059 
0060 ResultSet* RunDCSLVDat::getEndcapRset() {
0061   ResultSet* rset = nullptr;
0062   string query =
0063       "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
0064       " d.VALUE_NUMBER, '5' NOMINAL_VALUE , d.VALUE_TIMESTAMP "
0065       "FROM " +
0066       getEEAccount() +
0067       ".FWWIENERMARATHONCHANNEL_LV d "
0068       " JOIN " +
0069       getEEAccount() +
0070       ".EE_LV_MAPPING h on "
0071       " h.DPID = d.DPID join channelview cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name and "
0072       "dpe_name='MEASUREMENTSENSEVOLTAGE' ";
0073   try {
0074     m_readStmt->setSQL(query);
0075     rset = m_readStmt->executeQuery();
0076   } catch (SQLException& e) {
0077 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
0078     throw(std::runtime_error(std::string("RunDCSLVDat::getEndcapRset():  ") + e.getMessage() + " " + query));
0079 #else
0080     throw(std::runtime_error(std::string("RunDCSLVDat::getEndcapRset():  error code ") +
0081                              std::to_string(e.getErrorCode()) + " " + query));
0082 #endif
0083   }
0084   return rset;
0085 }
0086 
0087 void RunDCSLVDat::fillTheMap(ResultSet* rset, map<EcalLogicID, RunDCSLVDat>* fillMap) {
0088   std::pair<EcalLogicID, RunDCSLVDat> p;
0089   RunDCSLVDat dat;
0090   DateHandler dh(m_env, m_conn);
0091 
0092   try {
0093     while (rset->next()) {
0094       p.first = EcalLogicID(rset->getString(1),   // name
0095                             rset->getInt(2),      // logic_id
0096                             rset->getInt(3),      // id1
0097                             rset->getInt(4),      // id2
0098                             rset->getInt(5),      // id3
0099                             rset->getString(6));  // maps_to
0100 
0101       dat.setLV(rset->getFloat(7));
0102       dat.setLVNominal(rset->getFloat(8));
0103       Date sinceDate = rset->getDate(9);
0104       Tm sinceTm = dh.dateToTm(sinceDate);
0105       dat.setStatus(0);
0106       if (p.first.getName() == "EB_LV_channel") {
0107         setStatusForBarrel(dat, sinceTm);
0108       } else {
0109         setStatusForEndcaps(dat, sinceTm);
0110       }
0111       p.second = dat;
0112       fillMap->insert(p);
0113     }
0114   } catch (SQLException& e) {
0115 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
0116     throw(std::runtime_error(std::string("RunDCSLVDat::fetchData():  ") + e.getMessage()));
0117 #else
0118     throw(std::runtime_error(std::string("RunDCSLVDat::fetchData():  error code ") + std::to_string(e.getErrorCode())));
0119 #endif
0120   }
0121 }
0122 
0123 int RunDCSLVDat::nowMicroseconds() {
0124   Tm t_now_gmt;
0125 
0126   t_now_gmt.setToCurrentGMTime();
0127   int t_now_gmt_micros = t_now_gmt.microsTime();
0128   return t_now_gmt_micros;
0129 }
0130 
0131 void RunDCSLVDat::setStatusForBarrel(RunDCSLVDat& dat, const Tm& sinceTm) {
0132   int t_now_gmt_micros = nowMicroseconds();
0133 
0134   if (fabs(dat.getLV() - dat.getLVNominal()) * 1000 > maxLVDifferenceEB) {
0135     dat.setStatus(LVNOTNOMINAL);
0136   }
0137   if (dat.getLV() * 1000 < minLV) {
0138     dat.setStatus(LVOFF);
0139   }
0140 
0141   int result = 0;
0142   int d = ((int)t_now_gmt_micros - (int)sinceTm.microsTime());
0143   if (d > maxDifference) {
0144     result = -d / 1000000;
0145   }
0146   dat.setTimeStatus(result);
0147 }
0148 
0149 void RunDCSLVDat::setStatusForEndcaps(RunDCSLVDat& dat, const Tm& sinceTm) {
0150   int t_now_gmt_micros = nowMicroseconds();
0151 
0152   if (fabs(dat.getLV() - dat.getLVNominal()) * 1000 > maxLVDifferenceEE) {
0153     dat.setStatus(LVNOTNOMINAL);
0154   }
0155   if (dat.getLV() * 1000 < minLV) {
0156     dat.setStatus(LVOFF);
0157   }
0158 
0159   int result = 0;
0160   int d = ((int)t_now_gmt_micros - (int)sinceTm.microsTime());
0161   if (d > maxDifference) {
0162     result = -d / 1000000;
0163   }
0164   dat.setTimeStatus(result);
0165 }
0166 
0167 void RunDCSLVDat::fetchLastData(map<EcalLogicID, RunDCSLVDat>* fillMap) noexcept(false) {
0168   this->checkConnection();
0169 
0170   fillMap->clear();
0171 
0172   try {
0173     std::pair<EcalLogicID, RunDCSLVDat> p;
0174     RunDCSLVDat dat;
0175 
0176     ResultSet* rset = getBarrelRset();
0177 
0178     fillTheMap(rset, fillMap);
0179     rset = getEndcapRset();
0180 
0181     fillTheMap(rset, fillMap);
0182   } catch (SQLException& e) {
0183 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
0184     throw(std::runtime_error(std::string("RunDCSLVDat::fetchData():  ") + e.getMessage()));
0185 #else
0186     throw(std::runtime_error(std::string("RunDCSLVDat::fetchData():  error code ") + std::to_string(e.getErrorCode())));
0187 #endif
0188   }
0189 }