CMS 3D CMS Logo

LMFLaserBluePulseDat.cc

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

Generated on Tue Jun 9 17:40:48 2009 for CMSSW by  doxygen 1.5.4