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