CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/OnlineDB/EcalCondDB/src/CaliHVScanRatioDat.cc

Go to the documentation of this file.
00001 #include <stdexcept>
00002 #include <string>
00003 #include "OnlineDB/Oracle/interface/Oracle.h"
00004 
00005 #include "OnlineDB/EcalCondDB/interface/CaliHVScanRatioDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/CaliTag.h"
00007 #include "OnlineDB/EcalCondDB/interface/CaliIOV.h"
00008 
00009 using namespace std;
00010 using namespace oracle::occi;
00011 
00012 CaliHVScanRatioDat::CaliHVScanRatioDat()
00013 {
00014   m_env = NULL;
00015   m_conn = NULL;
00016   m_writeStmt = NULL;
00017 
00018   m_hvratio = 0;
00019   m_hvratioRMS = 0;
00020   m_taskStatus = false;
00021 }
00022 
00023 
00024 
00025 CaliHVScanRatioDat::~CaliHVScanRatioDat()
00026 {
00027 }
00028 
00029 
00030 
00031 void CaliHVScanRatioDat::prepareWrite()
00032   throw(std::runtime_error)
00033 {
00034   this->checkConnection();
00035   
00036   try {
00037     m_writeStmt = m_conn->createStatement();
00038     m_writeStmt->setSQL("INSERT INTO cali_hv_scan_ratio_dat (iov_id, logic_id, "
00039                         "hvratio, hvratio_rms, task_status) "
00040                         "VALUES (:iov_id, :logic_id, "
00041                         ":3, :4, :5)");
00042   } catch (SQLException &e) {
00043     throw(std::runtime_error("CaliHVScanRatioDat::prepareWrite():  "+e.getMessage()));
00044   }
00045 }
00046 
00047 
00048 
00049 void CaliHVScanRatioDat::writeDB(const EcalLogicID* ecid, const CaliHVScanRatioDat* item, CaliIOV* iov)
00050   throw(std::runtime_error)
00051 {
00052   this->checkConnection();
00053   this->checkPrepare();
00054   
00055   int iovID = iov->fetchID();
00056   if (!iovID) { throw(std::runtime_error("CaliHVScanRatioDat::writeDB:  IOV not in DB")); }
00057   
00058   int logicID = ecid->getLogicID();
00059   if (!logicID) { throw(std::runtime_error("CaliHVScanRatioDat::writeDB:  Bad EcalLogicID")); }
00060   
00061   try {
00062     m_writeStmt->setInt(1, iovID);
00063     m_writeStmt->setInt(2, logicID);
00064     
00065     m_writeStmt->setFloat(3, item->getHVRatio() );
00066     m_writeStmt->setFloat(4, item->getHVRatioRMS() );
00067     m_writeStmt->setInt(5, item->getTaskStatus() );
00068     
00069     m_writeStmt->executeUpdate();
00070   } catch (SQLException &e) {
00071     throw(std::runtime_error("CaliHVScanRatioDat::writeDB():  "+e.getMessage()));
00072   }
00073 }
00074 
00075 
00076 
00077 void CaliHVScanRatioDat::fetchData(std::map< EcalLogicID, CaliHVScanRatioDat >* fillMap, CaliIOV* iov)
00078   throw(std::runtime_error)
00079 {
00080   this->checkConnection();
00081   fillMap->clear();
00082   
00083   iov->setConnection(m_env, m_conn);
00084   int iovID = iov->fetchID();
00085   if (!iovID) { 
00086     //  throw(std::runtime_error("CaliHVScanRatioDat::writeDB:  IOV not in DB")); 
00087     return;
00088   }
00089   
00090   try {
00091     Statement* stmt = m_conn->createStatement();
00092     stmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00093                  "d.hvratio, d.hvratio_rms, d.task_status "
00094                  "FROM channelview cv JOIN cali_hv_scan_ratio_dat d "
00095                  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00096                  "WHERE d.iov_id = :iov_id");
00097     stmt->setInt(1, iovID);
00098     ResultSet* rset = stmt->executeQuery();
00099     
00100     std::pair< EcalLogicID, CaliHVScanRatioDat > p;
00101     CaliHVScanRatioDat dat;
00102     while(rset->next()) {
00103       p.first = EcalLogicID( rset->getString(1),     // name
00104                              rset->getInt(2),        // logic_id
00105                              rset->getInt(3),        // id1
00106                              rset->getInt(4),        // id2
00107                              rset->getInt(5),        // id3
00108                              rset->getString(6));    // maps_to
00109       
00110       dat.setHVRatio( rset->getFloat(7) );
00111       dat.setHVRatioRMS( rset->getFloat(8) );
00112       dat.setTaskStatus( rset->getInt(9) );
00113       
00114       p.second = dat;
00115       fillMap->insert(p);
00116     }
00117   } catch (SQLException &e) {
00118     throw(std::runtime_error("CaliHVScanRatioDat::fetchData():  "+e.getMessage()));
00119   }
00120 }