CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/OnlineDB/EcalCondDB/src/DCULVRVoltagesDat.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/DCULVRVoltagesDat.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 DCULVRVoltagesDat::DCULVRVoltagesDat()
00013 {
00014   m_env = NULL;
00015   m_conn = NULL;
00016   m_writeStmt = NULL;
00017   m_readStmt = NULL;
00018 
00019   m_vfe1_A = 0;
00020   m_vfe2_A = 0;
00021   m_vfe3_A = 0;
00022   m_vfe4_A = 0;
00023   m_vfe5_A = 0;
00024   m_VCC = 0;
00025   m_vfe4_5_D = 0;
00026   m_vfe1_2_3_D = 0;
00027   m_buffer = 0;
00028   m_fenix = 0;
00029   m_V43_A = 0;
00030   m_OCM = 0;
00031   m_GOH = 0;
00032   m_INH = 0;
00033   m_V43_D = 0;
00034 }
00035 
00036 
00037 
00038 DCULVRVoltagesDat::~DCULVRVoltagesDat()
00039 {
00040 }
00041 
00042 
00043 
00044 void DCULVRVoltagesDat::prepareWrite()
00045   throw(std::runtime_error)
00046 {
00047   this->checkConnection();
00048 
00049   try {
00050     m_writeStmt = m_conn->createStatement();
00051     m_writeStmt->setSQL("INSERT INTO dcu_lvr_voltages_dat (iov_id, logic_id, "
00052                         "vfe1_A, vfe2_A, vfe3_A, vfe4_A, vfe5_A, VCC, vfe4_5_D, vfe1_2_3_D, buffer, fenix, V43_A, OCM, GOH, INH, V43_D) "
00053                         "VALUES (:iov_id, :logic_id, "
00054                         ":3, :4, :5, :6, :7, :8, :9, :10, :11, :12, :13, :14, :15, :16, :17)");
00055   } catch (SQLException &e) {
00056     throw(std::runtime_error("DCULVRVoltagesDat::prepareWrite():  "+e.getMessage()));
00057   }
00058 }
00059 
00060 
00061 
00062 void DCULVRVoltagesDat::writeDB(const EcalLogicID* ecid, const DCULVRVoltagesDat* item, DCUIOV* iov)
00063   throw(std::runtime_error)
00064 {
00065   this->checkConnection();
00066   this->checkPrepare();
00067 
00068   int iovID = iov->fetchID();
00069   if (!iovID) { throw(std::runtime_error("DCULVRVoltagesDat::writeDB:  IOV not in DB")); }
00070 
00071   int logicID = ecid->getLogicID();
00072   if (!logicID) { throw(std::runtime_error("DCULVRVoltagesDat::writeDB:  Bad EcalLogicID")); }
00073   
00074   try {
00075     m_writeStmt->setInt(1, iovID);
00076     m_writeStmt->setInt(2, logicID);
00077 
00078     m_writeStmt->setFloat(3, item->getVFE1_A() );
00079     m_writeStmt->setFloat(4, item->getVFE2_A() );
00080     m_writeStmt->setFloat(5, item->getVFE3_A() );
00081     m_writeStmt->setFloat(6, item->getVFE4_A() );
00082     m_writeStmt->setFloat(7, item->getVFE5_A() );
00083     m_writeStmt->setFloat(8, item->getVCC() );
00084     m_writeStmt->setFloat(9, item->getVFE4_5_D() );
00085     m_writeStmt->setFloat(10, item->getVFE1_2_3_D() );
00086     m_writeStmt->setFloat(11, item->getBuffer() );
00087     m_writeStmt->setFloat(12, item->getFenix() );
00088     m_writeStmt->setFloat(13, item->getV43_A() );
00089     m_writeStmt->setFloat(14, item->getOCM() );
00090     m_writeStmt->setFloat(15, item->getGOH() );
00091     m_writeStmt->setFloat(16, item->getINH() );
00092     m_writeStmt->setFloat(17, item->getV43_D() );
00093 
00094     m_writeStmt->executeUpdate();
00095   } catch (SQLException &e) {
00096     throw(std::runtime_error("DCULVRVoltagesDat::writeDB():  "+e.getMessage()));
00097   }
00098 }
00099 
00100 
00101 
00102 void DCULVRVoltagesDat::fetchData(std::map< EcalLogicID, DCULVRVoltagesDat >* fillMap, DCUIOV* iov)
00103   throw(std::runtime_error)
00104 {
00105   this->checkConnection();
00106   fillMap->clear();
00107 
00108   iov->setConnection(m_env, m_conn);
00109   int iovID = iov->fetchID();
00110   if (!iovID) { 
00111     //  throw(std::runtime_error("DCULVRVoltagesDat::writeDB:  IOV not in DB")); 
00112     return;
00113   }
00114 
00115   try {
00116 
00117     m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00118                  "d.vfe1_A, d.vfe2_A, d.vfe3_A, d.vfe4_A, d.vfe5_A, d.VCC, d.vfe4_5_D, d.vfe1_2_3_D, d.buffer, d.fenix, d.V43_A, d.OCM, d.GOH, d.INH, d.V43_D  "
00119                  "FROM channelview cv JOIN dcu_lvr_voltages_dat d "
00120                  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00121                  "WHERE d.iov_id = :iov_id");
00122     m_readStmt->setInt(1, iovID);
00123     ResultSet* rset = m_readStmt->executeQuery();
00124     
00125     std::pair< EcalLogicID, DCULVRVoltagesDat > p;
00126     DCULVRVoltagesDat dat;
00127     while(rset->next()) {
00128       p.first = EcalLogicID( rset->getString(1),     // name
00129                              rset->getInt(2),        // logic_id
00130                              rset->getInt(3),        // id1
00131                              rset->getInt(4),        // id2
00132                              rset->getInt(5),        // id3
00133                              rset->getString(6));    // maps_to
00134 
00135       dat.setVFE1_A( rset->getFloat(7) );
00136       dat.setVFE2_A( rset->getFloat(8) );
00137       dat.setVFE3_A( rset->getFloat(9) );
00138       dat.setVFE4_A( rset->getFloat(10) );
00139       dat.setVFE5_A( rset->getFloat(11) );
00140       dat.setVCC( rset->getFloat(12) );
00141       dat.setVFE4_5_D( rset->getFloat(13) );
00142       dat.setVFE1_2_3_D( rset->getFloat(14) );
00143       dat.setBuffer( rset->getFloat(15) );
00144       dat.setFenix( rset->getFloat(16) );
00145       dat.setV43_A( rset->getFloat(17) );
00146       dat.setOCM( rset->getFloat(18) );
00147       dat.setGOH( rset->getFloat(19) );
00148       dat.setINH( rset->getFloat(20) );
00149       dat.setV43_D( rset->getFloat(21) );
00150 
00151       p.second = dat;
00152       fillMap->insert(p);
00153     }
00154   } catch (SQLException &e) {
00155     throw(std::runtime_error("DCULVRVoltagesDat::fetchData():  "+e.getMessage()));
00156   }
00157 }
00158 void DCULVRVoltagesDat::writeArrayDB(const std::map< EcalLogicID, DCULVRVoltagesDat >* data, DCUIOV* iov)
00159   throw(std::runtime_error)
00160 {
00161   this->checkConnection();
00162   this->checkPrepare();
00163 
00164   int iovID = iov->fetchID();
00165   if (!iovID) { throw(std::runtime_error("DCULVRVoltagesDat::writeArrayDB:  IOV not in DB")); }
00166 
00167 
00168   int nrows=data->size(); 
00169   int* ids= new int[nrows];
00170   int* iovid_vec= new int[nrows];
00171   float* xx= new float[nrows];
00172   float* yy= new float[nrows];
00173   float* zz= new float[nrows];
00174   float* ww= new float[nrows];
00175   float* uu= new float[nrows];
00176   float* tt= new float[nrows];
00177   float* rr= new float[nrows];
00178   float* pp= new float[nrows];
00179   float* ll= new float[nrows];
00180   float* mm= new float[nrows];
00181   float* nn= new float[nrows];
00182   float* qq= new float[nrows];
00183   float* ss= new float[nrows];
00184   float* vv= new float[nrows];
00185   float* hh= new float[nrows];
00186 
00187 
00188   ub2* ids_len= new ub2[nrows];
00189   ub2* iov_len= new ub2[nrows];
00190   ub2* x_len= new ub2[nrows];
00191   ub2* y_len= new ub2[nrows];
00192   ub2* z_len= new ub2[nrows];
00193   ub2* w_len= new ub2[nrows];
00194   ub2* u_len= new ub2[nrows];
00195   ub2* t_len= new ub2[nrows];
00196   ub2* r_len= new ub2[nrows];
00197   ub2* p_len= new ub2[nrows];
00198   ub2* l_len= new ub2[nrows];
00199   ub2* m_len= new ub2[nrows];
00200   ub2* n_len= new ub2[nrows];
00201   ub2* q_len= new ub2[nrows];
00202   ub2* s_len= new ub2[nrows];
00203   ub2* v_len= new ub2[nrows];
00204   ub2* h_len= new ub2[nrows];
00205   
00206   const EcalLogicID* channel;
00207   const DCULVRVoltagesDat* dataitem;
00208   int count=0;
00209   typedef map< EcalLogicID, DCULVRVoltagesDat >::const_iterator CI;
00210   for (CI p = data->begin(); p != data->end(); ++p) {
00211         channel = &(p->first);
00212         int logicID = channel->getLogicID();
00213         if (!logicID) { throw(std::runtime_error("DCULVRVoltagesDat::writeArrayDB:  Bad EcalLogicID")); }
00214         ids[count]=logicID;
00215         iovid_vec[count]=iovID;
00216 
00217         dataitem = &(p->second);
00218         // dataIface.writeDB( channel, dataitem, iov);
00219         float x=dataitem->getVFE1_A();
00220         float y=dataitem->getVFE2_A();
00221         float z=dataitem->getVFE3_A();
00222         float w=dataitem->getVFE4_A();
00223         float u=dataitem->getVFE5_A();
00224         float t=dataitem->getVCC();
00225         float r=dataitem->getVFE4_5_D();
00226         float p=dataitem->getVFE1_2_3_D();
00227         float l=dataitem->getBuffer();
00228         float m=dataitem->getFenix();
00229         float n=dataitem->getV43_A();
00230         float q=dataitem->getOCM();
00231         float s=dataitem->getGOH();
00232         float v=dataitem->getINH();
00233         float h=dataitem->getV43_D();
00234 
00235         xx[count]=x;
00236         yy[count]=y;
00237         zz[count]=z;
00238         ww[count]=w;
00239         uu[count]=u;
00240         tt[count]=t;
00241         rr[count]=r;
00242         pp[count]=p;
00243         ll[count]=l;
00244         mm[count]=m;
00245         nn[count]=n;
00246         qq[count]=q;
00247         ss[count]=s;
00248         vv[count]=v;
00249         hh[count]=h;
00250 
00251         ids_len[count]=sizeof(ids[count]);
00252         iov_len[count]=sizeof(iovid_vec[count]);
00253         
00254         x_len[count]=sizeof(xx[count]);
00255         y_len[count]=sizeof(yy[count]);
00256         z_len[count]=sizeof(zz[count]);
00257         w_len[count]=sizeof(ww[count]);
00258         u_len[count]=sizeof(uu[count]);
00259         t_len[count]=sizeof(tt[count]);
00260         r_len[count]=sizeof(rr[count]);
00261         p_len[count]=sizeof(pp[count]);
00262         l_len[count]=sizeof(ll[count]);
00263         m_len[count]=sizeof(mm[count]);
00264         n_len[count]=sizeof(nn[count]);
00265         q_len[count]=sizeof(qq[count]);
00266         s_len[count]=sizeof(ss[count]);
00267         v_len[count]=sizeof(vv[count]);
00268         h_len[count]=sizeof(hh[count]);
00269         count++;
00270      }
00271   try {
00272     m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
00273     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
00274     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
00275     m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
00276     m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT , sizeof(zz[0]), z_len );
00277     m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIFLOAT , sizeof(ww[0]), w_len );
00278     m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIFLOAT , sizeof(uu[0]), u_len );
00279     m_writeStmt->setDataBuffer(8, (dvoid*)tt, OCCIFLOAT , sizeof(tt[0]), t_len );
00280     m_writeStmt->setDataBuffer(9, (dvoid*)rr, OCCIFLOAT , sizeof(rr[0]), r_len );
00281     m_writeStmt->setDataBuffer(10, (dvoid*)pp, OCCIFLOAT , sizeof(pp[0]), p_len );
00282     m_writeStmt->setDataBuffer(11, (dvoid*)ll, OCCIFLOAT , sizeof(ll[0]), l_len );
00283     m_writeStmt->setDataBuffer(12, (dvoid*)mm, OCCIFLOAT , sizeof(mm[0]), m_len );
00284     m_writeStmt->setDataBuffer(13, (dvoid*)nn, OCCIFLOAT , sizeof(nn[0]), n_len );
00285     m_writeStmt->setDataBuffer(14, (dvoid*)qq, OCCIFLOAT , sizeof(qq[0]), q_len );
00286     m_writeStmt->setDataBuffer(15, (dvoid*)ss, OCCIFLOAT , sizeof(ss[0]), s_len );
00287     m_writeStmt->setDataBuffer(16, (dvoid*)vv, OCCIFLOAT , sizeof(vv[0]), v_len );
00288     m_writeStmt->setDataBuffer(17, (dvoid*)hh, OCCIFLOAT , sizeof(hh[0]), h_len );
00289    
00290 
00291     m_writeStmt->executeArrayUpdate(nrows);
00292 
00293     delete [] ids;
00294     delete [] iovid_vec;
00295     delete [] xx;
00296     delete [] yy;
00297     delete [] zz;
00298     delete [] ww;
00299     delete [] uu;
00300     delete [] tt;
00301     delete [] rr;
00302     delete [] pp;
00303     delete [] ll;
00304     delete [] mm;
00305     delete [] nn;
00306     delete [] qq;
00307     delete [] ss;
00308     delete [] vv;
00309     delete [] hh;
00310 
00311     delete [] ids_len;
00312     delete [] iov_len;
00313     delete [] x_len;
00314     delete [] y_len;
00315     delete [] z_len;
00316     delete [] w_len;
00317     delete [] u_len;
00318     delete [] t_len;
00319     delete [] r_len;
00320     delete [] p_len;
00321     delete [] l_len;
00322     delete [] m_len;
00323     delete [] n_len;
00324     delete [] q_len;
00325     delete [] s_len;
00326     delete [] v_len;
00327     delete [] h_len;
00328 
00329   } catch (SQLException &e) {
00330     throw(std::runtime_error("DCULVRVoltagesDat::writeArrayDB():  "+e.getMessage()));
00331   }
00332 }