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 #include <list>
0005 #include <string>
0006 #include <map>
0007 
0008 #include "OnlineDB/EcalCondDB/interface/RunDCSMagnetDat.h"
0009 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
0010 #include "OnlineDB/EcalCondDB/interface/Tm.h"
0011 
0012 using namespace std;
0013 using namespace oracle::occi;
0014 
0015 RunDCSMagnetDat::RunDCSMagnetDat() {
0016   m_env = nullptr;
0017   m_conn = nullptr;
0018   m_writeStmt = nullptr;
0019   m_readStmt = nullptr;
0020 
0021   m_current = 0;
0022   m_time = Tm();
0023 }
0024 
0025 RunDCSMagnetDat::~RunDCSMagnetDat() {}
0026 
0027 void RunDCSMagnetDat::setTime(const Tm& start) { m_time = start; }
0028 
0029 Tm RunDCSMagnetDat::getTime() const { return m_time; }
0030 
0031 void RunDCSMagnetDat::prepareWrite() noexcept(false) {}
0032 
0033 void RunDCSMagnetDat::writeDB(const EcalLogicID* ecid, const RunDCSMagnetDat* item, RunIOV* iov) noexcept(false) {}
0034 
0035 void RunDCSMagnetDat::fetchData(map<EcalLogicID, RunDCSMagnetDat>* fillMap, RunIOV* iov) noexcept(false) {
0036   std::cout << "going to call fetchLastData" << std::endl;
0037   fetchLastData(fillMap);
0038   std::cout << "returned from fetchLastData" << std::endl;
0039 }
0040 
0041 ResultSet* RunDCSMagnetDat::getMagnetRset() {
0042   DateHandler dh(m_env, m_conn);
0043 
0044   ResultSet* rset = nullptr;
0045   string query = "SELECT c.name, c.logic_id, c.id1, c.id2, c.id3, c.maps_to , v.value_number, v.change_date from " +
0046                  getMagnetAccount() +
0047                  ".CMSFWMAGNET_LV v, channelview c where v.dpe_name= 'CURRENT' and  c.name=maps_to and c.name='EB' ";
0048   try {
0049     std::cout << "query:" << query << std::endl;
0050 
0051     m_readStmt->setSQL(query);
0052     rset = m_readStmt->executeQuery();
0053   } catch (SQLException& e) {
0054 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
0055     throw(std::runtime_error(std::string("RunDCSMagnetDat::getBarrelRset():  ") + e.getMessage() + " " + query));
0056 #else
0057     throw(std::runtime_error(std::string("RunDCSMagnetDat::getBarrelRset():  error code ") +
0058                              std::to_string(e.getErrorCode()) + " " + query));
0059 #endif
0060   }
0061   return rset;
0062 }
0063 
0064 void RunDCSMagnetDat::fillTheMap(ResultSet* rset, map<EcalLogicID, RunDCSMagnetDat>* fillMap) {
0065   // method for last value queries
0066 
0067   std::pair<EcalLogicID, RunDCSMagnetDat> p;
0068   RunDCSMagnetDat dat;
0069   DateHandler dh(m_env, m_conn);
0070 
0071   try {
0072     while (rset->next()) {
0073       p.first = EcalLogicID(rset->getString(1),   // name
0074                             rset->getInt(2),      // logic_id
0075                             rset->getInt(3),      // id1
0076                             rset->getInt(4),      // id2
0077                             rset->getInt(5),      // id3
0078                             rset->getString(6));  // maps_to
0079 
0080       std::cout << "done the logic id" << std::endl;
0081       dat.setMagnetCurrent(rset->getFloat(7));
0082       std::cout << "done the magnet current" << std::endl;
0083 
0084       Date sinceDate = rset->getDate(8);
0085       std::cout << "done the date" << std::endl;
0086 
0087       Tm sinceTm = dh.dateToTm(sinceDate);
0088       dat.setTime(sinceTm);
0089 
0090       p.second = dat;
0091       fillMap->insert(p);
0092     }
0093   } catch (SQLException& e) {
0094 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
0095     throw(std::runtime_error(std::string("RunDCSMagnetDat::fetchData():  ") + e.getMessage()));
0096 #else
0097     throw(std::runtime_error(std::string("RunDCSMagnetDat::fetchData():  error code ") +
0098                              std::to_string(e.getErrorCode())));
0099 #endif
0100   }
0101 }
0102 
0103 int RunDCSMagnetDat::nowMicroseconds() {
0104   Tm t_now_gmt;
0105 
0106   t_now_gmt.setToCurrentGMTime();
0107   int t_now_gmt_micros = t_now_gmt.microsTime();
0108   return t_now_gmt_micros;
0109 }
0110 
0111 void RunDCSMagnetDat::fetchLastData(map<EcalLogicID, RunDCSMagnetDat>* fillMap) noexcept(false) {
0112   this->checkConnection();
0113 
0114   std::cout << "fetchLastData>>1" << std::endl;
0115 
0116   fillMap->clear();
0117 
0118   std::cout << "fetchLastData>>2" << std::endl;
0119 
0120   try {
0121     std::pair<EcalLogicID, RunDCSMagnetDat> p;
0122     RunDCSMagnetDat dat;
0123     std::cout << "fetchLastData>>3" << std::endl;
0124 
0125     ResultSet* rset = getMagnetRset();
0126 
0127     std::cout << "fetchLastData>>4" << std::endl;
0128 
0129     fillTheMap(rset, fillMap);
0130     std::cout << "fetchLastData>>5" << std::endl;
0131 
0132   } catch (SQLException& e) {
0133 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
0134     throw(std::runtime_error(std::string("RunDCSMagnetDat::fetchData():  ") + e.getMessage()));
0135 #else
0136     throw(std::runtime_error(std::string("RunDCSMagnetDat::fetchData():  error code ") +
0137                              std::to_string(e.getErrorCode())));
0138 #endif
0139   }
0140 }