CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/OnlineDB/EcalCondDB/src/RunDCSLVDat.cc

Go to the documentation of this file.
00001 #include <stdexcept>
00002 #include <string>
00003 #include <math.h>
00004 
00005 #include "OnlineDB/EcalCondDB/interface/RunDCSLVDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
00007 
00008 using namespace std;
00009 using namespace oracle::occi;
00010 
00011 RunDCSLVDat::RunDCSLVDat()
00012 {
00013   m_env = NULL;
00014   m_conn = NULL;
00015   m_writeStmt = NULL;
00016   m_readStmt = NULL;
00017 
00018   m_lv = 0;
00019   m_lvnom = 0;
00020   m_status= 0;
00021   m_tstatus= 0;
00022 }
00023 
00024 
00025 
00026 RunDCSLVDat::~RunDCSLVDat()
00027 {
00028 }
00029 
00030 
00031 
00032 void RunDCSLVDat::prepareWrite()
00033   throw(std::runtime_error)
00034 {
00035 
00036 
00037 }
00038 
00039 
00040 
00041 void RunDCSLVDat::writeDB(const EcalLogicID* ecid, const RunDCSLVDat* item, RunIOV* iov)
00042   throw(std::runtime_error)
00043 {
00044 }
00045 
00046 
00047 
00048 void RunDCSLVDat::fetchData(map< EcalLogicID, RunDCSLVDat >* fillMap, RunIOV* iov)
00049   throw(std::runtime_error)
00050 {
00051   fetchLastData(fillMap);
00052 
00053 }
00054 
00055 ResultSet *RunDCSLVDat::getBarrelRset() {
00056   ResultSet* rset = NULL;
00057   string query = "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00058     " d.value_number , '5' NOMINAL_VALUE , d.VALUE_TIMESTAMP "
00059     "FROM "+ getEBAccount()+".FWWIENERMARATHONCHANNEL_LV d "
00060     " JOIN "+ getEBAccount()+".LV_MAPPING h on "
00061     " h.DPID = d.DPID join channelview cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name and dpe_name='MEASUREMENTSENSEVOLTAGE' "; 
00062   try {
00063     m_readStmt->setSQL(query);
00064     rset = m_readStmt->executeQuery();
00065   }
00066   catch (SQLException e) {
00067     throw(std::runtime_error("RunDCSLVDat::getBarrelRset():  " + e.getMessage() + " " + query));
00068   }
00069   return rset;
00070 }
00071 
00072 ResultSet *RunDCSLVDat::getEndcapRset() {
00073   ResultSet* rset = NULL;
00074   string query = "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00075     " d.VALUE_NUMBER, '5' NOMINAL_VALUE , d.VALUE_TIMESTAMP "
00076     "FROM "+ getEEAccount()+".FWWIENERMARATHONCHANNEL_LV d "
00077     " JOIN "+ getEEAccount()+".EE_LV_MAPPING h on "
00078     " h.DPID = d.DPID join channelview cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name and dpe_name='MEASUREMENTSENSEVOLTAGE' "; 
00079   try {
00080     m_readStmt->setSQL(query);
00081     rset = m_readStmt->executeQuery();
00082   }
00083   catch (SQLException e) {
00084     throw(std::runtime_error("RunDCSLVDat::getEndcapRset():  " + e.getMessage() + " " + query));
00085   }
00086   return rset;
00087 }
00088 
00089 void RunDCSLVDat::fillTheMap(ResultSet *rset, 
00090                                map< EcalLogicID, RunDCSLVDat >* fillMap) {
00091   std::pair< EcalLogicID, RunDCSLVDat > p;
00092   RunDCSLVDat dat;
00093   DateHandler dh(m_env, m_conn);
00094 
00095   try {
00096     while(rset->next()) {
00097       p.first = EcalLogicID( rset->getString(1),     // name
00098                              rset->getInt(2),        // logic_id
00099                              rset->getInt(3),        // id1
00100                              rset->getInt(4),        // id2
00101                              rset->getInt(5),        // id3
00102                              rset->getString(6));    // maps_to
00103       
00104       dat.setLV(        rset->getFloat(7) );
00105       dat.setLVNominal( rset->getFloat(8) );
00106       Date sinceDate = rset->getDate(9);
00107       Tm  sinceTm = dh.dateToTm( sinceDate );
00108       dat.setStatus(0);
00109       if (p.first.getName() == "EB_LV_channel") {
00110         setStatusForBarrel(dat, sinceTm);      
00111       } else {
00112         setStatusForEndcaps(dat, sinceTm);      
00113       }
00114       p.second = dat;
00115       fillMap->insert(p);
00116     } 
00117   }
00118   catch (SQLException &e) {
00119     throw(std::runtime_error("RunDCSLVDat::fetchData():  "+e.getMessage()));
00120   }
00121 }
00122 
00123 int  RunDCSLVDat::nowMicroseconds() {
00124   Tm t_now_gmt;
00125   
00126   t_now_gmt.setToCurrentGMTime();
00127   int t_now_gmt_micros = t_now_gmt.microsTime();
00128   return t_now_gmt_micros;
00129 }
00130 
00131 
00132 void RunDCSLVDat::setStatusForBarrel(RunDCSLVDat &dat, Tm sinceTm) {
00133   int t_now_gmt_micros = nowMicroseconds();
00134 
00135   if (fabs(dat.getLV() - dat.getLVNominal())*1000 > maxLVDifferenceEB) {
00136     dat.setStatus(LVNOTNOMINAL);
00137   }
00138   if (dat.getLV()*1000 < minLV) {
00139     dat.setStatus(LVOFF);
00140   }
00141 
00142   int result=0;
00143   int d= ((int)t_now_gmt_micros - (int)sinceTm.microsTime()) ;
00144   if (d> maxDifference) {
00145     result= -d/1000000 ;
00146   }
00147   dat.setTimeStatus(result);
00148 
00149 
00150 }
00151 
00152 void  RunDCSLVDat::setStatusForEndcaps(RunDCSLVDat &dat, Tm sinceTm) {
00153   int t_now_gmt_micros = nowMicroseconds();
00154 
00155   if (fabs(dat.getLV() - dat.getLVNominal())*1000 > maxLVDifferenceEE) {
00156     dat.setStatus(LVNOTNOMINAL);
00157   }
00158   if (dat.getLV()*1000 < minLV) {
00159     dat.setStatus(LVOFF);
00160   }
00161 
00162   int result=0;
00163   int d= ((int)t_now_gmt_micros - (int)sinceTm.microsTime()) ;
00164   if (d> maxDifference) {
00165     result= -d/1000000 ;
00166   }
00167   dat.setTimeStatus(result);
00168 
00169 
00170 }
00171 
00172 void RunDCSLVDat::fetchLastData(map< EcalLogicID, RunDCSLVDat >* fillMap )
00173   throw(std::runtime_error)
00174 {
00175   this->checkConnection();
00176 
00177   fillMap->clear();
00178 
00179   try {
00180     std::pair< EcalLogicID, RunDCSLVDat > p;
00181     RunDCSLVDat dat;
00182 
00183     ResultSet* rset = getBarrelRset();
00184     
00185     fillTheMap(rset, fillMap);
00186     rset = getEndcapRset();
00187     
00188     fillTheMap(rset, fillMap);
00189   } 
00190   catch (SQLException &e) {
00191     throw(std::runtime_error("RunDCSLVDat::fetchData():  "+e.getMessage()));
00192   }
00193 }