CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/OnlineDB/EcalCondDB/src/DCSPTMTempList.cc

Go to the documentation of this file.
00001 #include <stdexcept>
00002 #include "OnlineDB/Oracle/interface/Oracle.h"
00003 
00004 #include "OnlineDB/EcalCondDB/interface/Tm.h"
00005 #include "OnlineDB/EcalCondDB/interface/DateHandler.h"
00006 #include "OnlineDB/EcalCondDB/interface/DCSPTMTemp.h"
00007 #include "OnlineDB/EcalCondDB/interface/DCSPTMTempList.h"
00008 #include "OnlineDB/EcalCondDB/interface/IIOV.h"
00009 #include "OnlineDB/EcalCondDB/interface/EcalLogicID.h"
00010 
00011 using namespace std;
00012 using namespace oracle::occi;
00013 
00014 
00015 DCSPTMTempList::DCSPTMTempList()
00016 {
00017   m_conn = NULL;
00018 }
00019 
00020 DCSPTMTempList::~DCSPTMTempList()
00021 {
00022 }
00023 
00024 
00025  std::vector<DCSPTMTemp> DCSPTMTempList::getList() 
00026 {
00027   return m_vec_temp;
00028 }
00029 
00030 
00031 void DCSPTMTempList::fetchValuesForECID(EcalLogicID ecid)
00032   throw(std::runtime_error)
00033 {
00034 
00035   this->checkConnection();
00036   int nruns=0;
00037 
00038   int ecid_id=ecid.getLogicID();
00039 
00040   try {
00041     Statement* stmt0 = m_conn->createStatement();
00042     stmt0->setSQL("SELECT count(since) FROM PVSS_TEMPERATURE_DAT "
00043                  "WHERE logic_id = :logic_id  " );
00044     stmt0->setInt(1, ecid_id);
00045   
00046     ResultSet* rset0 = stmt0->executeQuery();
00047     if (rset0->next()) {
00048       nruns = rset0->getInt(1);
00049     }
00050     m_conn->terminateStatement(stmt0);
00051 
00052     cout <<"DCSPTMTempList::fetchValuesForECID>> Number of records in DB="<< nruns << endl;
00053     m_vec_temp.reserve(nruns);
00054     
00055     Statement* stmt = m_conn->createStatement();
00056     stmt->setSQL("SELECT  "
00057                  "since, till, temperature  FROM PVSS_TEMPERATURE_DAT "
00058                  "WHERE logic_id = :logic_id  order by since " );
00059     stmt->setInt(1, ecid_id);
00060 
00061     DateHandler dh(m_env, m_conn);
00062     Tm runStart;
00063     Tm runEnd;
00064   
00065     ResultSet* rset = stmt->executeQuery();
00066     int i=0;
00067     while (i<nruns) {
00068       rset->next();
00069      
00070        Date startDate = rset->getDate(1);
00071        Date endDate = rset->getDate(2);  
00072        float x = rset->getFloat(3);      
00073        runStart = dh.dateToTm( startDate );
00074        runEnd = dh.dateToTm( endDate );
00075        
00076        DCSPTMTemp r ;
00077        r.setTemperature(x);
00078        r.setStart(runStart);
00079        r.setEnd(runEnd);
00080        r.setEcalLogicID(ecid);
00081        m_vec_temp.push_back(r);
00082       
00083       i++;
00084     }
00085    
00086     cout <<"DCSPTMTempList::fetchValuesForECID>> loop done " << endl;
00087 
00088     m_conn->terminateStatement(stmt);
00089   } catch (SQLException &e) {
00090     throw(std::runtime_error("DCSPTMTempList:  "+e.getMessage()));
00091   }
00092 
00093 
00094 }
00095 
00096 void DCSPTMTempList::fetchValuesForECIDAndTime(EcalLogicID ecid, Tm start, Tm end)
00097   throw(std::runtime_error)
00098 {
00099 
00100   this->checkConnection();
00101   int nruns=0;
00102 
00103   int ecid_id=ecid.getLogicID();
00104 
00105   DateHandler dh(m_env, m_conn);
00106   Tm runStart;
00107   Tm runEnd;
00108 
00109 
00110   try {
00111     Statement* stmt0 = m_conn->createStatement();
00112     stmt0->setSQL("SELECT count(since) FROM PVSS_TEMPERATURE_DAT "
00113                  "WHERE logic_id = :logic_id  " 
00114                  "AND since >= :start_time  " 
00115                  "AND since <= :till_time  " 
00116                   );
00117     stmt0->setInt(1, ecid_id);
00118     stmt0->setDate(2, dh.tmToDate(start));
00119     stmt0->setDate(3, dh.tmToDate(end));
00120   
00121     ResultSet* rset0 = stmt0->executeQuery();
00122     if (rset0->next()) {
00123       nruns = rset0->getInt(1);
00124     }
00125     m_conn->terminateStatement(stmt0);
00126 
00127     cout <<"DCSPTMTempList::fetchValuesForECIDAndTime>> Number of records in DB="<< nruns << endl;
00128     m_vec_temp.reserve(nruns);
00129     
00130     Statement* stmt = m_conn->createStatement();
00131     stmt->setSQL("SELECT  "
00132                  "since, till, temperature  FROM PVSS_TEMPERATURE_DAT "
00133                  "WHERE logic_id = :logic_id "
00134                  "AND since >= :start_time  " 
00135                  "AND since <= :till_time  " 
00136                  " order by since " );
00137     stmt->setInt(1, ecid_id);
00138     stmt->setDate(2, dh.tmToDate(start));
00139     stmt->setDate(3, dh.tmToDate(end));
00140 
00141   
00142     ResultSet* rset = stmt->executeQuery();
00143     int i=0;
00144     while (i<nruns) {
00145       rset->next();
00146      
00147        Date startDate = rset->getDate(1);
00148        Date endDate = rset->getDate(2);  
00149        float x = rset->getFloat(3);      
00150        runStart = dh.dateToTm( startDate );
00151        runEnd = dh.dateToTm( endDate );
00152        
00153        DCSPTMTemp r ;
00154        r.setTemperature(x);
00155        r.setStart(runStart);
00156        r.setEnd(runEnd);
00157        r.setEcalLogicID(ecid);
00158        m_vec_temp.push_back(r);
00159       
00160       i++;
00161     }
00162    
00163 
00164     m_conn->terminateStatement(stmt);
00165   } catch (SQLException &e) {
00166     throw(std::runtime_error("DCSPTMTempList:  "+e.getMessage()));
00167   }
00168 
00169 
00170 }
00171