CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/OnlineDB/EcalCondDB/src/RunLaserRunDat.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/RunLaserRunDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
00007 
00008 using namespace std;
00009 using namespace oracle::occi;
00010 
00011 RunLaserRunDat::RunLaserRunDat()
00012 {
00013   m_env = NULL;
00014   m_conn = NULL;
00015   m_writeStmt = NULL;
00016   m_laserSeqType = "";
00017   m_laserSeqCond = "";
00018 }
00019 
00020 
00021 
00022 RunLaserRunDat::~RunLaserRunDat()
00023 {
00024 }
00025 
00026 
00027 
00028 void RunLaserRunDat::prepareWrite()
00029   throw(std::runtime_error)
00030 {
00031   this->checkConnection();
00032 
00033   try {
00034     m_writeStmt = m_conn->createStatement();
00035     m_writeStmt->setSQL("INSERT INTO run_laserrun_config_dat (iov_id, logic_id, "
00036                         "laser_sequence_type, laser_sequence_cond) "
00037                         "VALUES (:1, :2, "
00038                         ":3, :4 )");
00039   } catch (SQLException &e) {
00040     throw(std::runtime_error("RunLaserRunDat::prepareWrite():  "+e.getMessage()));
00041   }
00042 }
00043 
00044 
00045 
00046 void RunLaserRunDat::writeDB(const EcalLogicID* ecid, const RunLaserRunDat* item, RunIOV* iov)
00047   throw(std::runtime_error)
00048 {
00049   this->checkConnection();
00050   this->checkPrepare();
00051 
00052   int iovID = iov->fetchID();
00053   if (!iovID) { throw(std::runtime_error("RunLaserRunDat::writeDB:  IOV not in DB")); }
00054 
00055   int logicID = ecid->getLogicID();
00056   if (!logicID) { throw(std::runtime_error("RunLaserRunDat::writeDB:  Bad EcalLogicID")); }
00057   
00058   try {
00059     m_writeStmt->setInt(1, iovID);
00060     m_writeStmt->setInt(2, logicID);
00061     m_writeStmt->setString(3, item->getLaserSequenceType());
00062     m_writeStmt->setString(4, item->getLaserSequenceCond());
00063 
00064     m_writeStmt->executeUpdate();
00065   } catch (SQLException &e) {
00066     throw(std::runtime_error("RunLaserRunDat::writeDB():  "+e.getMessage()));
00067   }
00068 }
00069 
00070 
00071 
00072 void RunLaserRunDat::fetchData(map< EcalLogicID, RunLaserRunDat >* fillMap, RunIOV* iov)
00073   throw(std::runtime_error)
00074 {
00075   this->checkConnection();
00076   fillMap->clear();
00077 
00078   iov->setConnection(m_env, m_conn);
00079   int iovID = iov->fetchID();
00080   if (!iovID) { 
00081     //  throw(std::runtime_error("RunLaserRunDat::writeDB:  IOV not in DB")); 
00082     return;
00083   }
00084 
00085   try {
00086     Statement* stmt = m_conn->createStatement();
00087     stmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00088                  "d.laser_sequence_type, d.laser_sequence_cond "
00089                  "FROM channelview cv JOIN run_laserrun_config_dat d "
00090                  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00091                  "WHERE d.iov_id = :iov_id");
00092     stmt->setInt(1, iovID);
00093     ResultSet* rset = stmt->executeQuery();
00094     
00095     std::pair< EcalLogicID, RunLaserRunDat > p;
00096     RunLaserRunDat dat;
00097     while(rset->next()) {
00098       p.first = EcalLogicID( rset->getString(1),     // name
00099                              rset->getInt(2),        // logic_id
00100                              rset->getInt(3),        // id1
00101                              rset->getInt(4),        // id2
00102                              rset->getInt(5),        // id3
00103                              rset->getString(6));    // maps_to
00104 
00105       dat.setLaserSequenceType( rset->getString(7));    // maps_to
00106       dat.setLaserSequenceCond( rset->getString(8));    // maps_to
00107 
00108       p.second = dat;
00109       fillMap->insert(p);
00110     }
00111     m_conn->terminateStatement(stmt);
00112   } catch (SQLException &e) {
00113     throw(std::runtime_error("RunLaserRunDat::fetchData():  "+e.getMessage()));
00114   }
00115 }