00001 #include <stdexcept>
00002 #include <string>
00003 #include "OnlineDB/Oracle/interface/Oracle.h"
00004
00005 #include "OnlineDB/EcalCondDB/interface/LMFLaserIRedNormDat.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 LMFLaserIRedNormDat::LMFLaserIRedNormDat()
00013 {
00014 m_env = NULL;
00015 m_conn = NULL;
00016 m_writeStmt = NULL;
00017 m_readStmt = NULL;
00018
00019 m_apdOverPNAMean = 0;
00020 m_apdOverPNARMS = 0;
00021 m_apdOverPNBMean = 0;
00022 m_apdOverPNMean = 0;
00023 m_apdOverPNRMS = 0;
00024 }
00025
00026
00027
00028 LMFLaserIRedNormDat::~LMFLaserIRedNormDat()
00029 {
00030 }
00031
00032
00033
00034 void LMFLaserIRedNormDat::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_laser_ired_norm_dat (iov_id, logic_id, "
00042 "apd_over_pnA_mean, apd_over_pnA_rms, apd_over_pnB_mean, apd_over_pnB_rms, apd_over_pn_mean, apd_over_pn_rms) "
00043 "VALUES (:iov_id, :logic_id, "
00044 ":3, :4, :5, :6, :7, :8)");
00045 } catch (SQLException &e) {
00046 throw(runtime_error("LMFLaserIRedNormDat::prepareWrite(): "+e.getMessage()));
00047 }
00048 }
00049
00050
00051
00052 void LMFLaserIRedNormDat::writeDB(const EcalLogicID* ecid, const LMFLaserIRedNormDat* 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("LMFLaserIRedNormDat::writeDB: IOV not in DB")); }
00060
00061 int logicID = ecid->getLogicID();
00062 if (!logicID) { throw(runtime_error("LMFLaserIRedNormDat::writeDB: Bad EcalLogicID")); }
00063
00064 try {
00065 m_writeStmt->setInt(1, iovID);
00066 m_writeStmt->setInt(2, logicID);
00067
00068 m_writeStmt->setFloat(3, item->getAPDOverPNAMean() );
00069 m_writeStmt->setFloat(4, item->getAPDOverPNARMS() );
00070 m_writeStmt->setFloat(5, item->getAPDOverPNBMean() );
00071 m_writeStmt->setFloat(6, item->getAPDOverPNBRMS() );
00072 m_writeStmt->setFloat(7, item->getAPDOverPNMean() );
00073 m_writeStmt->setFloat(8, item->getAPDOverPNRMS() );
00074
00075
00076 m_writeStmt->executeUpdate();
00077 } catch (SQLException &e) {
00078 throw(runtime_error("LMFLaserIRedNormDat::writeDB(): "+e.getMessage()));
00079 }
00080 }
00081
00082
00083
00084 void LMFLaserIRedNormDat::fetchData(std::map< EcalLogicID, LMFLaserIRedNormDat >* fillMap, LMFRunIOV* iov)
00085 throw(runtime_error)
00086 {
00087 this->checkConnection();
00088 fillMap->clear();
00089
00090 iov->setConnection(m_env, m_conn);
00091 int iovID = iov->fetchID();
00092 if (!iovID) {
00093
00094 return;
00095 }
00096
00097 try {
00098
00099 m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00100 "d.apd_over_pnA_mean, d.apd_over_pnA_rms, d.apd_over_pnB_mean, d.apd_over_pnB_rms, d.apd_over_pn_mean, d.apd_over_pn_rms "
00101 "FROM channelview cv JOIN lmf_laser_ired_norm_dat d "
00102 "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00103 "WHERE d.iov_id = :iov_id");
00104 m_readStmt->setInt(1, iovID);
00105 ResultSet* rset = m_readStmt->executeQuery();
00106
00107 std::pair< EcalLogicID, LMFLaserIRedNormDat > p;
00108 LMFLaserIRedNormDat dat;
00109 while(rset->next()) {
00110 p.first = EcalLogicID( rset->getString(1),
00111 rset->getInt(2),
00112 rset->getInt(3),
00113 rset->getInt(4),
00114 rset->getInt(5),
00115 rset->getString(6));
00116
00117 dat.setAPDOverPNAMean( rset->getFloat(7) );
00118 dat.setAPDOverPNARMS( rset->getFloat(8) );
00119 dat.setAPDOverPNBMean( rset->getFloat(9) );
00120 dat.setAPDOverPNBRMS( rset->getFloat(10) );
00121 dat.setAPDOverPNMean( rset->getFloat(11) );
00122 dat.setAPDOverPNRMS( rset->getFloat(12) );
00123
00124
00125 p.second = dat;
00126 fillMap->insert(p);
00127 }
00128
00129 } catch (SQLException &e) {
00130 throw(runtime_error("LMFLaserIRedNormDat::fetchData(): "+e.getMessage()));
00131 }
00132 }