CMS 3D CMS Logo

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

Generated on Tue Jun 9 17:40:48 2009 for CMSSW by  doxygen 1.5.4