CMS 3D CMS Logo

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

Generated on Tue Jun 9 17:40:48 2009 for CMSSW by  doxygen 1.5.4