CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/OnlineDB/EcalCondDB/src/DCUVFETempDat.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/DCUVFETempDat.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 DCUVFETempDat::DCUVFETempDat()
00013 {
00014   m_env = NULL;
00015   m_conn = NULL;
00016   m_writeStmt = NULL;
00017   m_readStmt = NULL;
00018 
00019   m_vfeTemp = 0;
00020 }
00021 
00022 
00023 
00024 DCUVFETempDat::~DCUVFETempDat()
00025 {
00026 }
00027 
00028 
00029 
00030 void DCUVFETempDat::prepareWrite()
00031   throw(std::runtime_error)
00032 {
00033   this->checkConnection();
00034 
00035   try {
00036     m_writeStmt = m_conn->createStatement();
00037     m_writeStmt->setSQL("INSERT INTO dcu_vfe_temp_dat (iov_id, logic_id, "
00038                         "vfe_temp) "
00039                         "VALUES (:iov_id, :logic_id, "
00040                         ":vfe_temp)");
00041   } catch (SQLException &e) {
00042     throw(std::runtime_error("DCUVFETempDat::prepareWrite():  "+e.getMessage()));
00043   }
00044 }
00045 
00046 
00047 
00048 void DCUVFETempDat::writeDB(const EcalLogicID* ecid, const DCUVFETempDat* item, DCUIOV* iov)
00049   throw(std::runtime_error)
00050 {
00051   this->checkConnection();
00052   this->checkPrepare();
00053 
00054   int iovID = iov->fetchID();
00055   if (!iovID) { throw(std::runtime_error("DCUVFETempDat::writeDB:  IOV not in DB")); }
00056 
00057   int logicID = ecid->getLogicID();
00058   if (!logicID) { throw(std::runtime_error("DCUVFETempDat::writeDB:  Bad EcalLogicID")); }
00059   
00060   try {
00061     m_writeStmt->setInt(1, iovID);
00062     m_writeStmt->setInt(2, logicID);
00063 
00064     m_writeStmt->setFloat(3, item->getVFETemp() );
00065 
00066     m_writeStmt->executeUpdate();
00067   } catch (SQLException &e) {
00068     throw(std::runtime_error("DCUVFETempDat::writeDB():  "+e.getMessage()));
00069   }
00070 }
00071 
00072 
00073 
00074 void DCUVFETempDat::fetchData(std::map< EcalLogicID, DCUVFETempDat >* fillMap, DCUIOV* iov)
00075   throw(std::runtime_error)
00076 {
00077   this->checkConnection();
00078   fillMap->clear();
00079 
00080   iov->setConnection(m_env, m_conn);
00081   int iovID = iov->fetchID();
00082   if (!iovID) { 
00083     //  throw(std::runtime_error("DCUVFETempDat::writeDB:  IOV not in DB")); 
00084     return;
00085   }
00086 
00087   try {
00088 
00089     m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00090                  "d.vfe_temp "
00091                  "FROM channelview cv JOIN dcu_vfe_temp_dat d "
00092                  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00093                  "WHERE d.iov_id = :iov_id");
00094     m_readStmt->setInt(1, iovID);
00095     ResultSet* rset = m_readStmt->executeQuery();
00096     
00097     std::pair< EcalLogicID, DCUVFETempDat > p;
00098     DCUVFETempDat dat;
00099     while(rset->next()) {
00100       p.first = EcalLogicID( rset->getString(1),     // name
00101                              rset->getInt(2),        // logic_id
00102                              rset->getInt(3),        // id1
00103                              rset->getInt(4),        // id2
00104                              rset->getInt(5),        // id3
00105                              rset->getString(6));    // maps_to
00106 
00107       dat.setVFETemp( rset->getFloat(7) );
00108 
00109       p.second = dat;
00110       fillMap->insert(p);
00111     }
00112   } catch (SQLException &e) {
00113     throw(std::runtime_error("DCUVFETempDat::fetchData():  "+e.getMessage()));
00114   }
00115 }
00116 
00117 void DCUVFETempDat::writeArrayDB(const std::map< EcalLogicID, DCUVFETempDat >* data, DCUIOV* iov)
00118   throw(std::runtime_error)
00119 {
00120   this->checkConnection();
00121   this->checkPrepare();
00122 
00123   int iovID = iov->fetchID();
00124   if (!iovID) { throw(std::runtime_error("DCUVFETempDat::writeArrayDB:  IOV not in DB")); }
00125 
00126 
00127   int nrows=data->size(); 
00128   int* ids= new int[nrows];
00129   int* iovid_vec= new int[nrows];
00130   float* xx= new float[nrows];
00131 
00132   ub2* ids_len= new ub2[nrows];
00133   ub2* iov_len= new ub2[nrows];
00134   ub2* x_len= new ub2[nrows];
00135 
00136   const EcalLogicID* channel;
00137   const DCUVFETempDat* dataitem;
00138   int count=0;
00139   typedef map< EcalLogicID, DCUVFETempDat >::const_iterator CI;
00140   for (CI p = data->begin(); p != data->end(); ++p) {
00141         channel = &(p->first);
00142         int logicID = channel->getLogicID();
00143         if (!logicID) { throw(std::runtime_error("DCUVFETempDat::writeArrayDB:  Bad EcalLogicID")); }
00144         ids[count]=logicID;
00145         iovid_vec[count]=iovID;
00146 
00147         dataitem = &(p->second);
00148         // dataIface.writeDB( channel, dataitem, iov);
00149         float x=dataitem->getVFETemp();
00150 
00151         xx[count]=x;
00152 
00153 
00154         ids_len[count]=sizeof(ids[count]);
00155         iov_len[count]=sizeof(iovid_vec[count]);
00156         
00157         x_len[count]=sizeof(xx[count]);
00158 
00159 
00160         count++;
00161      }
00162 
00163 
00164   try {
00165     m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
00166     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
00167     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
00168    
00169 
00170     m_writeStmt->executeArrayUpdate(nrows);
00171 
00172     delete [] ids;
00173     delete [] iovid_vec;
00174     delete [] xx;
00175 
00176     delete [] ids_len;
00177     delete [] iov_len;
00178     delete [] x_len;
00179 
00180 
00181   } catch (SQLException &e) {
00182     throw(std::runtime_error("DCUVFETempDat::writeArrayDB():  "+e.getMessage()));
00183   }
00184 }