CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/OnlineDB/EcalCondDB/src/RunDCSMagnetDat.cc

Go to the documentation of this file.
00001 #include <stdexcept>
00002 #include <string>
00003 #include <math.h>
00004 #include <list>
00005 #include <string>
00006 #include <map>
00007 
00008 #include "OnlineDB/EcalCondDB/interface/RunDCSMagnetDat.h"
00009 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
00010 #include "OnlineDB/EcalCondDB/interface/Tm.h"
00011 
00012 using namespace std;
00013 using namespace oracle::occi;
00014 
00015 RunDCSMagnetDat::RunDCSMagnetDat()
00016 {
00017   m_env = NULL;
00018   m_conn = NULL;
00019   m_writeStmt = NULL;
00020   m_readStmt = NULL;
00021 
00022   m_current = 0;
00023   m_time=Tm();
00024 }
00025 
00026 
00027 
00028 RunDCSMagnetDat::~RunDCSMagnetDat()
00029 {
00030 }
00031 
00032 void RunDCSMagnetDat::setTime(Tm start)
00033 {
00034     m_time = start;
00035 }
00036 
00037 Tm RunDCSMagnetDat::getTime() const
00038 {
00039   return m_time;
00040 }
00041 
00042 
00043 
00044 
00045 
00046 void RunDCSMagnetDat::prepareWrite()
00047   throw(std::runtime_error)
00048 {
00049 
00050 
00051 }
00052 
00053 
00054 
00055 void RunDCSMagnetDat::writeDB(const EcalLogicID* ecid, const RunDCSMagnetDat* item, RunIOV* iov)
00056   throw(std::runtime_error)
00057 {
00058 }
00059 
00060 
00061 
00062 void RunDCSMagnetDat::fetchData(map< EcalLogicID, RunDCSMagnetDat >* fillMap, RunIOV* iov)
00063   throw(std::runtime_error)
00064 {
00065 
00066   std::cout<<"going to call fetchLastData"<<std::endl;
00067   fetchLastData(fillMap);
00068   std::cout<<"returned from fetchLastData"<<std::endl;
00069 
00070 }
00071 
00072 
00073 ResultSet *RunDCSMagnetDat::getMagnetRset() {
00074 
00075   DateHandler dh(m_env, m_conn);
00076 
00077   ResultSet* rset = NULL;
00078   string query="SELECT c.name, c.logic_id, c.id1, c.id2, c.id3, c.maps_to , v.value_number, v.change_date from "+ getMagnetAccount()+
00079     ".CMSFWMAGNET_LV v, channelview c where v.dpe_name= 'CURRENT' and  c.name=maps_to and c.name='EB' " ;
00080   try {
00081 
00082     std::cout<<"query:"<<query<<std::endl;
00083 
00084     m_readStmt->setSQL(query);
00085     rset = m_readStmt->executeQuery();
00086   }
00087   catch (SQLException e) {
00088     throw(std::runtime_error("RunDCSMagnetDat::getBarrelRset():  " + e.getMessage() + " " + query));
00089   }
00090   return rset;
00091 }
00092 
00093 
00094 
00095 void RunDCSMagnetDat::fillTheMap(ResultSet *rset, 
00096                                map< EcalLogicID, RunDCSMagnetDat >* fillMap) {
00097 
00098   // method for last value queries 
00099 
00100   std::pair< EcalLogicID, RunDCSMagnetDat > p;
00101   RunDCSMagnetDat dat;
00102   DateHandler dh(m_env, m_conn);
00103 
00104   try {
00105     while(rset->next()) {
00106       p.first = EcalLogicID( rset->getString(1),     // name
00107                              rset->getInt(2),        // logic_id
00108                              rset->getInt(3),        // id1
00109                              rset->getInt(4),        // id2
00110                              rset->getInt(5),        // id3
00111                              rset->getString(6));    // maps_to
00112       
00113     std::cout<<"done the logic id"<<std::endl;
00114       dat.setMagnetCurrent( rset->getFloat(7) );
00115     std::cout<<"done the magnet current"<<std::endl;
00116 
00117       Date sinceDate = rset->getDate(8);
00118     std::cout<<"done the date"<<std::endl;
00119 
00120       Tm sinceTm = dh.dateToTm( sinceDate );
00121       dat.setTime(sinceTm);
00122 
00123       p.second = dat;
00124       fillMap->insert(p);
00125     } 
00126   }
00127   catch (SQLException &e) {
00128     throw(std::runtime_error("RunDCSMagnetDat::fetchData():  "+e.getMessage()));
00129   }
00130 }
00131 
00132 
00133 
00134 
00135 int  RunDCSMagnetDat::nowMicroseconds() {
00136   Tm t_now_gmt;
00137   
00138   t_now_gmt.setToCurrentGMTime();
00139   int t_now_gmt_micros = t_now_gmt.microsTime();
00140   return t_now_gmt_micros;
00141 }
00142 
00143 
00144 
00145 void RunDCSMagnetDat::fetchLastData(map< EcalLogicID, RunDCSMagnetDat >* fillMap )
00146   throw(std::runtime_error)
00147 {
00148   this->checkConnection();
00149 
00150   std::cout<<"fetchLastData>>1"<<std::endl;
00151 
00152   fillMap->clear();
00153 
00154   std::cout<<"fetchLastData>>2"<<std::endl;
00155 
00156 
00157   try {
00158     std::pair< EcalLogicID, RunDCSMagnetDat > p;
00159     RunDCSMagnetDat dat;
00160   std::cout<<"fetchLastData>>3"<<std::endl;
00161 
00162     ResultSet* rset = getMagnetRset();
00163     
00164   std::cout<<"fetchLastData>>4"<<std::endl;
00165 
00166     fillTheMap(rset, fillMap);
00167   std::cout<<"fetchLastData>>5"<<std::endl;
00168 
00169 
00170   } 
00171   catch (SQLException &e) {
00172     throw(std::runtime_error("RunDCSMagnetDat::fetchData():  "+e.getMessage()));
00173   }
00174 }
00175