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