CMS 3D CMS Logo

LMFPNBluePrimDat.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/LMFPNBluePrimDat.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 LMFPNBluePrimDat::LMFPNBluePrimDat()
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    m_PNAOverPNBMean=0;
00026    m_PNAOverPNBRMS=0;
00027    m_PNAOverPNBPeak=0;
00028 
00029 }
00030 
00031 
00032 
00033 LMFPNBluePrimDat::~LMFPNBluePrimDat()
00034 {
00035 }
00036 
00037 
00038 
00039 void LMFPNBluePrimDat::prepareWrite()
00040   throw(runtime_error)
00041 {
00042   this->checkConnection();
00043 
00044   try {
00045     m_writeStmt = m_conn->createStatement();
00046     m_writeStmt->setSQL("INSERT INTO lmf_laser_blue_PN_prim_dat (lmf_iov_id, logic_id, "
00047                         "flag, mean, rms, peak,  pna_over_pnB_mean, pna_over_pnB_rms, pna_over_pnB_peak ) "
00048                         "VALUES (:1, :2, "
00049                         ":3, :4, :5, :6, :7, :8, :9 )");
00050   } catch (SQLException &e) {
00051     throw(runtime_error("LMFPNBluePrimDat::prepareWrite():  "+e.getMessage()));
00052   }
00053 }
00054 
00055 
00056 
00057 void LMFPNBluePrimDat::writeDB(const EcalLogicID* ecid, const LMFPNBluePrimDat* item, LMFRunIOV* iov)
00058   throw(runtime_error)
00059 {
00060   this->checkConnection();
00061   this->checkPrepare();
00062 
00063   int iovID = iov->fetchID();
00064   if (!iovID) { throw(runtime_error("LMFPNBluePrimDat::writeDB:  IOV not in DB")); }
00065 
00066   int logicID = ecid->getLogicID();
00067   if (!logicID) { throw(runtime_error("LMFPNBluePrimDat::writeDB:  Bad EcalLogicID")); }
00068   
00069   try {
00070     m_writeStmt->setInt(1, iovID);
00071     m_writeStmt->setInt(2, logicID);
00072 
00073     m_writeStmt->setInt(3, item->getFlag() );
00074     m_writeStmt->setFloat(4, item->getMean() );
00075     m_writeStmt->setFloat(5, item->getRMS() );
00076     m_writeStmt->setFloat(6, item->getPeak() );
00077     m_writeStmt->setFloat(7, item->getPNAOverPNBMean() );
00078     m_writeStmt->setFloat(8, item->getPNAOverPNBRMS() );
00079     m_writeStmt->setFloat(9, item->getPNAOverPNBPeak() );
00080   
00081     m_writeStmt->executeUpdate();
00082   } catch (SQLException &e) {
00083     throw(runtime_error("LMFPNBluePrimDat::writeDB():  "+e.getMessage()));
00084   }
00085 }
00086 
00087 
00088 void LMFPNBluePrimDat::writeArrayDB(const std::map< EcalLogicID, LMFPNBluePrimDat >* data, LMFRunIOV* iov)
00089   throw(runtime_error)
00090 {
00091   this->checkConnection();
00092   this->checkPrepare();
00093 
00094   int iovID = iov->fetchID();
00095   if (!iovID) { throw(runtime_error("LMFPNBluePrimDat::writeArrayDB:  IOV not in DB")); }
00096 
00097 
00098   int nrows=data->size(); 
00099   int* ids= new int[nrows];
00100   int* iovid_vec= new int[nrows];
00101   int* aa= new int[nrows];
00102   float* xx= new float[nrows];
00103   float* yy= new float[nrows];
00104   float* zz= new float[nrows];
00105   float* wwa= new float[nrows];
00106   float* uua= new float[nrows];
00107   float* tta= new float[nrows];
00108 
00109   ub2* ids_len= new ub2[nrows];
00110   ub2* iov_len= new ub2[nrows];
00111   ub2* a_len= new ub2[nrows];
00112   ub2* x_len= new ub2[nrows];
00113   ub2* y_len= new ub2[nrows];
00114   ub2* z_len= new ub2[nrows];
00115   ub2* wa_len= new ub2[nrows];
00116   ub2* ua_len= new ub2[nrows];
00117   ub2* ta_len= new ub2[nrows];
00118 
00119   const EcalLogicID* channel;
00120   const LMFPNBluePrimDat* dataitem;
00121   int count=0;
00122   typedef map< EcalLogicID, LMFPNBluePrimDat >::const_iterator CI;
00123   for (CI p = data->begin(); p != data->end(); ++p) {
00124         channel = &(p->first);
00125         int logicID = channel->getLogicID();
00126         if (!logicID) { throw(runtime_error("LMFPNBluePrimDat::writeArrayDB:  Bad EcalLogicID")); }
00127         ids[count]=logicID;
00128         iovid_vec[count]=iovID;
00129 
00130         dataitem = &(p->second);
00131         // dataIface.writeDB( channel, dataitem, iov);
00132         int a=dataitem->getFlag();
00133         float x=dataitem->getMean();
00134         float y=dataitem->getRMS();
00135         float z=dataitem->getPeak();
00136         float wa=dataitem->getPNAOverPNBMean();
00137         float ua=dataitem->getPNAOverPNBRMS();
00138         float ta=dataitem->getPNAOverPNBPeak();
00139 
00140         aa[count]=a;
00141         xx[count]=x;
00142         yy[count]=y;
00143         zz[count]=z;
00144         wwa[count]=wa;
00145         uua[count]=ua;
00146         tta[count]=ta;
00147 
00148         ids_len[count]=sizeof(ids[count]);
00149         iov_len[count]=sizeof(iovid_vec[count]);
00150         
00151         a_len[count]=sizeof(aa[count]);
00152         x_len[count]=sizeof(xx[count]);
00153         y_len[count]=sizeof(yy[count]);
00154         z_len[count]=sizeof(zz[count]);
00155         wa_len[count]=sizeof(wwa[count]);
00156         ua_len[count]=sizeof(uua[count]);
00157         ta_len[count]=sizeof(tta[count]);
00158 
00159         count++;
00160      }
00161 
00162 
00163   try {
00164     m_writeStmt->setDataBuffer(1,  (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
00165     m_writeStmt->setDataBuffer(2,  (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
00166     m_writeStmt->setDataBuffer(3,  (dvoid*)aa,  OCCIINT , sizeof(aa[0]), a_len );
00167     m_writeStmt->setDataBuffer(4,  (dvoid*)xx,  OCCIFLOAT , sizeof(xx[0]), x_len );
00168     m_writeStmt->setDataBuffer(5,  (dvoid*)yy,  OCCIFLOAT , sizeof(yy[0]), y_len );
00169     m_writeStmt->setDataBuffer(6,  (dvoid*)zz,  OCCIFLOAT , sizeof(zz[0]), z_len );
00170     m_writeStmt->setDataBuffer(7,  (dvoid*)wwa, OCCIFLOAT , sizeof(wwa[0]), wa_len );
00171     m_writeStmt->setDataBuffer(8,  (dvoid*)uua, OCCIFLOAT , sizeof(uua[0]), ua_len );
00172     m_writeStmt->setDataBuffer(9,  (dvoid*)tta, OCCIFLOAT , sizeof(tta[0]), ta_len );
00173 
00174     m_writeStmt->executeArrayUpdate(nrows);
00175 
00176     delete [] ids;
00177     delete [] iovid_vec;
00178     delete [] aa;
00179     delete [] xx;
00180     delete [] yy;
00181     delete [] zz;
00182     delete [] wwa;
00183     delete [] uua;
00184     delete [] tta;
00185 
00186     delete [] ids_len;
00187     delete [] iov_len;
00188     delete [] a_len;
00189     delete [] x_len;
00190     delete [] y_len;
00191     delete [] z_len;
00192     delete [] wa_len;
00193     delete [] ua_len;
00194     delete [] ta_len;
00195 
00196   } catch (SQLException &e) {
00197     throw(runtime_error("LMFPNBluePrimDat::writeArrayDB():  "+e.getMessage()));
00198   }
00199 }
00200 
00201 void LMFPNBluePrimDat::fetchData(std::map< EcalLogicID, LMFPNBluePrimDat >* fillMap, LMFRunIOV* iov)
00202   throw(runtime_error)
00203 {
00204   this->checkConnection();
00205   fillMap->clear();
00206 
00207   iov->setConnection(m_env, m_conn);
00208   int iovID = iov->fetchID();
00209   if (!iovID) { 
00210     //  throw(runtime_error("LMFPNBluePrimDat::writeDB:  IOV not in DB")); 
00211     return;
00212   }
00213 
00214   try {
00215   
00216     m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00217                  "d.flag, d.mean, d.rms, d.peak, d.pna_over_pnb_mean, d.pna_over_pnb_rms, d.pna_over_pnB_peak "
00218                  "FROM channelview cv JOIN lmf_laser_blue_PN_PRIM_dat d "
00219                  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00220                  "WHERE d.lmf_iov_id = :iov_id");
00221  
00222     m_readStmt->setInt(1, iovID);
00223     
00224     ResultSet* rset = m_readStmt->executeQuery();
00225      
00226     std::pair< EcalLogicID, LMFPNBluePrimDat > p;
00227     LMFPNBluePrimDat dat;
00228     while(rset->next()) {
00229       p.first = EcalLogicID( rset->getString(1),     // name
00230                              rset->getInt(2),        // logic_id
00231                              rset->getInt(3),        // id1
00232                              rset->getInt(4),        // id2
00233                              rset->getInt(5),        // id3
00234                              rset->getString(6));    // maps_to
00235 
00236       dat.setFlag( rset->getInt(7) );
00237       dat.setMean( rset->getFloat(8) );
00238       dat.setRMS( rset->getFloat(9) );
00239       dat.setPeak( rset->getFloat(10) );
00240       dat.setPNAOverPNBMean( rset->getFloat(11) );
00241       dat.setPNAOverPNBRMS( rset->getFloat(12) );
00242       dat.setPNAOverPNBPeak( rset->getFloat(13) );
00243 
00244       p.second = dat;
00245       fillMap->insert(p);
00246     }
00247 
00248   } catch (SQLException &e) {
00249     throw(runtime_error("LMFPNBluePrimDat::fetchData():  "+e.getMessage()));
00250   }
00251 }

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