00001 #include <stdexcept>
00002 #include <string>
00003 #include "OnlineDB/Oracle/interface/Oracle.h"
00004
00005 #include "OnlineDB/EcalCondDB/interface/LMFPNConfigDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/RunTag.h"
00007 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
00008
00009 using namespace std;
00010 using namespace oracle::occi;
00011
00012 LMFPNConfigDat::LMFPNConfigDat()
00013 {
00014 m_env = NULL;
00015 m_conn = NULL;
00016 m_writeStmt = NULL;
00017 m_readStmt = NULL;
00018
00019 m_pnAID = 0;
00020 m_pnBID = 0;
00021 m_pnAValidity = 0;
00022 m_pnBValidity = 0;
00023 m_pnMeanValidity = 0;
00024 }
00025
00026
00027
00028 LMFPNConfigDat::~LMFPNConfigDat()
00029 {
00030 }
00031
00032
00033
00034 void LMFPNConfigDat::prepareWrite()
00035 throw(runtime_error)
00036 {
00037 this->checkConnection();
00038
00039 try {
00040 m_writeStmt = m_conn->createStatement();
00041 m_writeStmt->setSQL("INSERT INTO lmf_pn_config_dat (iov_id, logic_id, "
00042 "pna_id, pnb_id, pna_validity, pnb_validity, pnmean_validity) "
00043 "VALUES (:iov_id, :logic_id, "
00044 ":3, :4, :5, :6, :7)");
00045 } catch (SQLException &e) {
00046 throw(runtime_error("LMFPNConfigDat::prepareWrite(): "+e.getMessage()));
00047 }
00048 }
00049
00050
00051
00052 void LMFPNConfigDat::writeDB(const EcalLogicID* ecid, const LMFPNConfigDat* item, LMFRunIOV* iov)
00053 throw(runtime_error)
00054 {
00055 this->checkConnection();
00056 this->checkPrepare();
00057
00058 int iovID = iov->fetchID();
00059 if (!iovID) { throw(runtime_error("LMFPNConfigDat::writeDB: IOV not in DB")); }
00060
00061 int logicID = ecid->getLogicID();
00062 if (!logicID) { throw(runtime_error("LMFPNConfigDat::writeDB: Bad EcalLogicID")); }
00063
00064 try {
00065 m_writeStmt->setInt(1, iovID);
00066 m_writeStmt->setInt(2, logicID);
00067
00068 m_writeStmt->setInt(3, item->getPNAID() );
00069 m_writeStmt->setInt(4, item->getPNBID() );
00070 m_writeStmt->setInt(5, item->getPNAValidity() );
00071 m_writeStmt->setInt(6, item->getPNBValidity() );
00072 m_writeStmt->setInt(7, item->getPNMeanValidity() );
00073
00074 m_writeStmt->executeUpdate();
00075 } catch (SQLException &e) {
00076 throw(runtime_error("LMFPNConfigDat::writeDB(): "+e.getMessage()));
00077 }
00078 }
00079
00080
00081
00082 void LMFPNConfigDat::fetchData(std::map< EcalLogicID, LMFPNConfigDat >* fillMap, LMFRunIOV* iov)
00083 throw(runtime_error)
00084 {
00085 this->checkConnection();
00086 fillMap->clear();
00087
00088 iov->setConnection(m_env, m_conn);
00089 int iovID = iov->fetchID();
00090 if (!iovID) {
00091
00092 return;
00093 }
00094
00095 try {
00096
00097 m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00098 "d.pna_id, d.pnb_id, d.pna_validity, d.pnb_validity, d.pnmean_validity "
00099 "FROM channelview cv JOIN lmf_pn_config_dat d "
00100 "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00101 "WHERE d.iov_id = :iov_id");
00102 m_readStmt->setInt(1, iovID);
00103 ResultSet* rset = m_readStmt->executeQuery();
00104
00105 std::pair< EcalLogicID, LMFPNConfigDat > p;
00106 LMFPNConfigDat dat;
00107 while(rset->next()) {
00108 p.first = EcalLogicID( rset->getString(1),
00109 rset->getInt(2),
00110 rset->getInt(3),
00111 rset->getInt(4),
00112 rset->getInt(5),
00113 rset->getString(6));
00114
00115 dat.setPNAID( rset->getInt(7) );
00116 dat.setPNBID( rset->getInt(8) );
00117 dat.setPNAValidity( rset->getInt(9) );
00118 dat.setPNBValidity( rset->getInt(10) );
00119 dat.setPNMeanValidity( rset->getInt(11) );
00120
00121 p.second = dat;
00122 fillMap->insert(p);
00123 }
00124
00125 } catch (SQLException &e) {
00126 throw(runtime_error("LMFPNConfigDat::fetchData(): "+e.getMessage()));
00127 }
00128 }
00129
00130