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