CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/OnlineDB/EcalCondDB/src/CaliTempDat.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/CaliTempDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/CaliTag.h"
00007 #include "OnlineDB/EcalCondDB/interface/CaliIOV.h"
00008 
00009 using namespace std;
00010 using namespace oracle::occi;
00011 
00012 CaliTempDat::CaliTempDat()
00013 {
00014   m_env = NULL;
00015   m_conn = NULL;
00016   m_writeStmt = NULL;
00017 
00018   m_beta = 0;
00019   m_r25 = 0;
00020   m_offset = 0;
00021   m_taskStatus = false;
00022 }
00023 
00024 
00025 
00026 CaliTempDat::~CaliTempDat()
00027 {
00028 }
00029 
00030 
00031 
00032 void CaliTempDat::prepareWrite()
00033   throw(std::runtime_error)
00034 {
00035   this->checkConnection();
00036   
00037   try {
00038     m_writeStmt = m_conn->createStatement();
00039     m_writeStmt->setSQL("INSERT INTO cali_temp_dat (iov_id, logic_id, "
00040                         " beta, r25, offset,  task_status) "
00041                         "VALUES (:iov_id, :logic_id, "
00042                         ":3, :4, :5, :6 )");
00043   } catch (SQLException &e) {
00044     throw(std::runtime_error("CaliTempDat::prepareWrite():  "+e.getMessage()));
00045   }
00046 }
00047 
00048 
00049 
00050 void CaliTempDat::writeDB(const EcalLogicID* ecid, const CaliTempDat* item, CaliIOV* iov)
00051   throw(std::runtime_error)
00052 {
00053   this->checkConnection();
00054   this->checkPrepare();
00055   
00056   int iovID = iov->fetchID();
00057   if (!iovID) { throw(std::runtime_error("CaliTempDat::writeDB:  IOV not in DB")); }
00058   
00059   int logicID = ecid->getLogicID();
00060   if (!logicID) { throw(std::runtime_error("CaliTempDat::writeDB:  Bad EcalLogicID")); }
00061   
00062   try {
00063     m_writeStmt->setInt(1, iovID);
00064     m_writeStmt->setInt(2, logicID);
00065     
00066     m_writeStmt->setFloat(3, item->getBeta() );
00067     m_writeStmt->setFloat(4, item->getR25() );
00068     m_writeStmt->setFloat(5, item->getOffset() );
00069     m_writeStmt->setInt(6, item->getTaskStatus() );
00070     
00071     m_writeStmt->executeUpdate();
00072   } catch (SQLException &e) {
00073     throw(std::runtime_error("CaliTempDat::writeDB():  "+e.getMessage()));
00074   }
00075 }
00076 
00077 
00078 
00079 void CaliTempDat::fetchData(std::map< EcalLogicID, CaliTempDat >* fillMap, CaliIOV* iov)
00080   throw(std::runtime_error)
00081 {
00082   this->checkConnection();
00083   fillMap->clear();
00084   
00085   iov->setConnection(m_env, m_conn);
00086   int iovID = iov->fetchID();
00087   if (!iovID) { 
00088     //  throw(std::runtime_error("CaliTempDat::writeDB:  IOV not in DB")); 
00089     return;
00090   }
00091   
00092   try {
00093     
00094     m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00095                  "d.beta, d.r25, d.offset, d.task_status "
00096                  "FROM channelview cv JOIN cali_temp_dat d "
00097                  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00098                  "WHERE d.iov_id = :iov_id");
00099     m_readStmt->setInt(1, iovID);
00100     ResultSet* rset = m_readStmt->executeQuery();
00101     
00102     std::pair< EcalLogicID, CaliTempDat > p;
00103     CaliTempDat dat;
00104     while(rset->next()) {
00105       p.first = EcalLogicID( rset->getString(1),     // name
00106                              rset->getInt(2),        // logic_id
00107                              rset->getInt(3),        // id1
00108                              rset->getInt(4),        // id2
00109                              rset->getInt(5),        // id3
00110                              rset->getString(6));    // maps_to
00111       
00112       dat.setBeta( rset->getFloat(7) );
00113       dat.setR25( rset->getFloat(8) );
00114       dat.setOffset( rset->getFloat(9) );
00115       dat.setTaskStatus( rset->getInt(10) );
00116       
00117       p.second = dat;
00118       fillMap->insert(p);
00119     }
00120   } catch (SQLException &e) {
00121     throw(std::runtime_error("CaliTempDat::fetchData():  "+e.getMessage()));
00122   }
00123 }
00124 
00125 void CaliTempDat::writeArrayDB(const std::map< EcalLogicID, CaliTempDat >* data, CaliIOV* iov)
00126   throw(std::runtime_error)
00127 {
00128   this->checkConnection();
00129   this->checkPrepare();
00130 
00131   int iovID = iov->fetchID();
00132   if (!iovID) { throw(std::runtime_error("CaliTempDat::writeArrayDB:  IOV not in DB")); }
00133 
00134 
00135   int nrows=data->size();
00136   int* ids= new int[nrows];
00137   int* iovid_vec= new int[nrows];
00138   float* xx= new float[nrows];
00139   float* yy= new float[nrows];
00140   float* zz= new float[nrows];
00141   int* st= new int[nrows];
00142 
00143   ub2* ids_len= new ub2[nrows];
00144   ub2* iov_len= new ub2[nrows];
00145   ub2* x_len= new ub2[nrows];
00146   ub2* y_len= new ub2[nrows];
00147   ub2* z_len= new ub2[nrows];
00148   ub2* st_len= new ub2[nrows];
00149 
00150   const EcalLogicID* channel;
00151   const CaliTempDat* dataitem;
00152   int count=0;
00153   typedef map< EcalLogicID, CaliTempDat >::const_iterator CI;
00154   for (CI p = data->begin(); p != data->end(); ++p) {
00155     channel = &(p->first);
00156     int logicID = channel->getLogicID();
00157     if (!logicID) { throw(std::runtime_error("CaliTempDat::writeArrayDB:  Bad EcalLogicID")); }
00158     ids[count]=logicID;
00159     iovid_vec[count]=iovID;
00160 
00161     dataitem = &(p->second);
00162     // dataIface.writeDB( channel, dataitem, iov);
00163     float x=dataitem->getBeta();
00164     float y=dataitem->getR25();
00165     float z=dataitem->getOffset();
00166     int statu=dataitem->getTaskStatus();
00167 
00168 
00169 
00170     xx[count]=x;
00171     yy[count]=y;
00172     zz[count]=z;
00173     st[count]=statu;
00174 
00175 
00176     ids_len[count]=sizeof(ids[count]);
00177     iov_len[count]=sizeof(iovid_vec[count]);
00178 
00179     x_len[count]=sizeof(xx[count]);
00180     y_len[count]=sizeof(yy[count]);
00181     z_len[count]=sizeof(zz[count]);
00182     st_len[count]=sizeof(st[count]);
00183 
00184     count++;
00185   }
00186 
00187 
00188   try {
00189     m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
00190     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
00191     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
00192     m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
00193     m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT , sizeof(zz[0]), z_len );
00194     m_writeStmt->setDataBuffer(6, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
00195 
00196 
00197     m_writeStmt->executeArrayUpdate(nrows);
00198 
00199     delete [] ids;
00200     delete [] iovid_vec;
00201     delete [] xx;
00202     delete [] yy;
00203     delete [] zz;
00204     delete [] st;
00205 
00206 
00207     delete [] ids_len;
00208     delete [] iov_len;
00209     delete [] x_len;
00210     delete [] y_len;
00211     delete [] z_len;
00212 
00213     delete [] st_len;
00214 
00215 
00216 
00217   } catch (SQLException &e) {
00218     throw(std::runtime_error("MonPedestalsDat::writeArrayDB():  "+e.getMessage()));
00219   }
00220 }