00001 #include <stdexcept>
00002 #include <cassert>
00003 #include <string>
00004 #include "OnlineDB/Oracle/interface/Oracle.h"
00005
00006 #include "OnlineDB/EcalCondDB/interface/LMFLaserPulseDat.h"
00007 #include "OnlineDB/EcalCondDB/interface/RunTag.h"
00008 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
00009
00010 using namespace std;
00011 using namespace oracle::occi;
00012
00013 int LMFLaserPulseDat::_color = LMFLaserPulseDat::iBlue;
00014
00015 LMFLaserPulseDat::LMFLaserPulseDat()
00016 {
00017 assert( _color>=iBlue && _color<=iIRed );
00018
00019 m_env = NULL;
00020 m_conn = NULL;
00021 m_writeStmt = NULL;
00022 m_readStmt = NULL;
00023
00024
00025 m_fit_method = 0;
00026 m_ampl = 0;
00027 m_time = 0;
00028 m_rise = 0;
00029 m_fwhm = 0;
00030 m_fw20 = 0;
00031 m_fw80 = 0;
00032 m_sliding = 0;
00033
00034 }
00035
00036
00037
00038 LMFLaserPulseDat::~LMFLaserPulseDat()
00039 {
00040 }
00041
00042
00043
00044 void LMFLaserPulseDat::prepareWrite()
00045 throw(runtime_error)
00046 {
00047 this->checkConnection();
00048
00049
00050 std::string command_ = "INSERT INTO XXXXXX (lmf_iov_id, logic_id, fit_method, mtq_ampl, mtq_time, mtq_rise, mtq_fwhm, mtq_fw20, mtq_fw80, mtq_sliding ) VALUES (:1, :2, :3, :4, :5, :6, :7, :8, :9, :10 )";
00051 command_.replace( command_.find("XXXXXX",0), 6, getTable() );
00052
00053 try {
00054 m_writeStmt = m_conn->createStatement();
00055 m_writeStmt->setSQL( command_.c_str() );
00056 } catch (SQLException &e) {
00057 throw(runtime_error("LMFLaserPulseDat::prepareWrite(): "+e.getMessage()));
00058 }
00059 }
00060
00061
00062
00063 void LMFLaserPulseDat::writeDB(const EcalLogicID* ecid, const LMFLaserPulseDat* item, LMFRunIOV* iov)
00064 throw(runtime_error)
00065 {
00066 this->checkConnection();
00067 this->checkPrepare();
00068
00069 int iovID = iov->fetchID();
00070 if (!iovID) { throw(runtime_error("LMFLaserPulseDat::writeDB: IOV not in DB")); }
00071
00072 int logicID = ecid->getLogicID();
00073 if (!logicID) { throw(runtime_error("LMFLaserPulseDat::writeDB: Bad EcalLogicID")); }
00074
00075 try {
00076 m_writeStmt->setInt(1, iovID);
00077 m_writeStmt->setInt(2, logicID);
00078
00079
00080 m_writeStmt->setInt(3, item->getFitMethod() );
00081 m_writeStmt->setFloat(4, item->getAmplitude() );
00082 m_writeStmt->setFloat(5, item->getTime() );
00083 m_writeStmt->setFloat(6, item->getRise() );
00084 m_writeStmt->setFloat(7, item->getFWHM() );
00085 m_writeStmt->setFloat(8, item->getFW20() );
00086 m_writeStmt->setFloat(9, item->getFW80() );
00087 m_writeStmt->setFloat(10, item->getSliding() );
00088
00089 m_writeStmt->executeUpdate();
00090 } catch (SQLException &e) {
00091 throw(runtime_error("LMFLaserPulseDat::writeDB(): "+e.getMessage()));
00092 }
00093 }
00094
00095
00096
00097 void LMFLaserPulseDat::fetchData(std::map< EcalLogicID, LMFLaserPulseDat >* fillMap, LMFRunIOV* iov)
00098 throw(runtime_error)
00099 {
00100 this->checkConnection();
00101 fillMap->clear();
00102
00103 iov->setConnection(m_env, m_conn);
00104 int iovID = iov->fetchID();
00105 if (!iovID) {
00106
00107 return;
00108 }
00109
00110
00111 std::string command_ = "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, d.fit_method, d.mtq_ampl, d.mtq_time, d.mtq_rise, d.mtq_fwhm, d.mtq_fw20, d.mtq_fw80, d.mtq_sliding FROM channelview cv JOIN XXXXXX d ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to WHERE d.lmf_iov_id = :lmf_iov_id";
00112 command_.replace( command_.find("XXXXXX",0), 6, getTable() );
00113
00114 try {
00115
00116 m_readStmt->setSQL( command_.c_str() );
00117 m_readStmt->setInt(1, iovID);
00118 ResultSet* rset = m_readStmt->executeQuery();
00119
00120 std::pair< EcalLogicID, LMFLaserPulseDat > p;
00121 LMFLaserPulseDat dat;
00122 while(rset->next()) {
00123 p.first = EcalLogicID( rset->getString(1),
00124 rset->getInt(2),
00125 rset->getInt(3),
00126 rset->getInt(4),
00127 rset->getInt(5),
00128 rset->getString(6));
00129
00130
00131 dat.setFitMethod( rset->getInt(7) );
00132 dat.setAmplitude( rset->getFloat(8) );
00133 dat.setTime( rset->getFloat(9) );
00134 dat.setRise( rset->getFloat(10) );
00135 dat.setFWHM( rset->getFloat(11) );
00136 dat.setFW20( rset->getFloat(12) );
00137 dat.setFW80( rset->getFloat(13) );
00138 dat.setSliding( rset->getFloat(14) );
00139
00140 p.second = dat;
00141 fillMap->insert(p);
00142 }
00143
00144 } catch (SQLException &e) {
00145 throw(runtime_error("LMFLaserPulseDat::fetchData(): "+e.getMessage()));
00146 }
00147 }
00148
00149 void
00150 LMFLaserPulseDat::setColor( int color ) { _color = color; }