Go to the documentation of this file.00001 #include <stdexcept>
00002 #include <string>
00003 #include "OnlineDB/Oracle/interface/Oracle.h"
00004 #include <boost/lexical_cast.hpp>
00005
00006 #include "OnlineDB/EcalCondDB/interface/RunCrystalErrorsDat.h"
00007 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
00008
00009 using namespace std;
00010 using namespace oracle::occi;
00011
00012 RunCrystalErrorsDat::RunCrystalErrorsDat()
00013 {
00014 m_env = NULL;
00015 m_conn = NULL;
00016 m_writeStmt = NULL;
00017 m_errorBits = 0;
00018 }
00019
00020
00021
00022 RunCrystalErrorsDat::~RunCrystalErrorsDat()
00023 {
00024 }
00025
00026
00027
00028 void RunCrystalErrorsDat::prepareWrite()
00029 throw(std::runtime_error)
00030 {
00031 this->checkConnection();
00032
00033 try {
00034 m_writeStmt = m_conn->createStatement();
00035
00036 m_writeStmt->setSQL("INSERT INTO run_crystal_errors_dat (iov_id, logic_id, "
00037 "error_bits) "
00038 "VALUES (:iov_id, :logic_id, "
00039 "to_number(:error_bits))");
00040 } catch (SQLException &e) {
00041 throw(std::runtime_error("RunCrystalErrorsDat::prepareWrite(): "+e.getMessage()));
00042 }
00043 }
00044
00045
00046
00047 void RunCrystalErrorsDat::writeDB(const EcalLogicID* ecid, const RunCrystalErrorsDat* item, RunIOV* iov)
00048 throw(std::runtime_error)
00049 {
00050 this->checkConnection();
00051 this->checkPrepare();
00052
00053 int iovID = iov->fetchID();
00054 if (!iovID) { throw(std::runtime_error("RunCrystalErrorsDat::writeDB: IOV not in DB")); }
00055
00056 int logicID = ecid->getLogicID();
00057 if (!logicID) { throw(std::runtime_error("RunCrystalErrorsDat::writeDB: Bad EcalLogicID")); }
00058
00059 try {
00060 m_writeStmt->setInt(1, iovID);
00061 m_writeStmt->setInt(2, logicID);
00062 m_writeStmt->setString(3, ( boost::lexical_cast<std::string>(item->getErrorBits()) ).c_str());
00063 m_writeStmt->executeUpdate();
00064 } catch (SQLException &e) {
00065 throw(std::runtime_error("RunCrystalErrorsDat::writeDB(): "+e.getMessage()));
00066 }
00067 }
00068
00069
00070
00071 void RunCrystalErrorsDat::fetchData(map< EcalLogicID, RunCrystalErrorsDat >* fillMap, RunIOV* iov)
00072 throw(std::runtime_error)
00073 {
00074 this->checkConnection();
00075 fillMap->clear();
00076
00077 iov->setConnection(m_env, m_conn);
00078 int iovID = iov->fetchID();
00079 if (!iovID) {
00080
00081 return;
00082 }
00083
00084 try {
00085 Statement* stmt = m_conn->createStatement();
00086
00087 stmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00088 "to_char(d.error_bits) "
00089 "FROM channelview cv JOIN run_crystal_errors_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, RunCrystalErrorsDat > p;
00096 RunCrystalErrorsDat dat;
00097 while(rset->next()) {
00098 p.first = EcalLogicID( rset->getString(1),
00099 rset->getInt(2),
00100 rset->getInt(3),
00101 rset->getInt(4),
00102 rset->getInt(5),
00103 rset->getString(6));
00104
00105 dat.setErrorBits( boost::lexical_cast<uint64_t>(rset->getString(7)) );
00106
00107 p.second = dat;
00108 fillMap->insert(p);
00109 }
00110 m_conn->terminateStatement(stmt);
00111
00112 } catch (SQLException &e) {
00113 throw(std::runtime_error("RunCrystalErrorsDat::fetchData(): "+e.getMessage()));
00114 }
00115 }