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