CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/OnlineDB/EcalCondDB/src/DCUCCSDat.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/DCUCCSDat.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 DCUCCSDat::DCUCCSDat()
00013 {
00014   m_env = NULL;
00015   m_conn = NULL;
00016   m_writeStmt = NULL;
00017   m_readStmt = NULL;
00018 
00019   m_m1_vdd1 = 0;
00020   m_m2_vdd1 = 0;
00021   m_m1_vdd2 = 0;
00022   m_m2_vdd2 = 0;
00023   m_m1_vinj = 0;
00024   m_m2_vinj = 0;
00025   m_m1_vcc = 0;
00026   m_m2_vcc = 0;
00027   m_m1_dcutemp = 0;
00028   m_m2_dcutemp = 0;
00029   m_ccstemplow = 0;
00030   m_ccstemphigh = 0;
00031 }
00032 
00033 DCUCCSDat::~DCUCCSDat()
00034 {
00035 }
00036 
00037 void DCUCCSDat::prepareWrite()
00038   throw(std::runtime_error)
00039 {
00040   this->checkConnection();
00041 
00042   try {
00043     m_writeStmt = m_conn->createStatement();
00044     m_writeStmt->setSQL("INSERT INTO dcu_ccs_dat (iov_id, logic_id, "
00045                         "m1_vdd1, m2_vdd1, m1_vdd2, m2_vdd2, m1_vinj, "
00046                         "m2_vinj, m1_vcc, m2_vcc, m1_dcutemp, m2_dcutemp, "
00047                         "ccstemplow, ccstemphigh) "
00048                         "VALUES (:iov_id, :logic_id, "
00049                         ":m1_vdd1, :m2_vdd1, :m1_vdd2, :m2_vdd2, :m1_vinj, "
00050                         ":m2_vinj, :m1_vcc, :m2_vcc, :m1_dcutemp, "
00051                         ":m2_dcutemp, :ccstemplow, :ccstemphigh)");
00052   } catch (SQLException &e) {
00053     throw(std::runtime_error("DCUCCSDat::prepareWrite():  " + 
00054                              e.getMessage()));
00055   }
00056 }
00057 
00058 
00059 
00060 void DCUCCSDat::writeDB(const EcalLogicID* ecid, const DCUCCSDat* item, 
00061                         DCUIOV* iov)
00062   throw(std::runtime_error)
00063 {
00064   this->checkConnection();
00065   this->checkPrepare();
00066 
00067   int iovID = iov->fetchID();
00068   if (!iovID) { 
00069     throw(std::runtime_error("DCUCCSDat::writeDB:  IOV not in DB")); 
00070   }
00071 
00072   int logicID = ecid->getLogicID();
00073   if (!logicID) { 
00074     throw(std::runtime_error("DCUCCSDat::writeDB:  Bad EcalLogicID")); 
00075   }
00076   
00077   try {
00078     m_writeStmt->setInt(1, iovID);
00079     m_writeStmt->setInt(2, logicID);
00080 
00081     m_writeStmt->setFloat( 3, item->getM1VDD1() );
00082     m_writeStmt->setFloat( 4, item->getM2VDD1() );
00083     m_writeStmt->setFloat( 5, item->getM1VDD2() );
00084     m_writeStmt->setFloat( 6, item->getM2VDD2() );
00085     m_writeStmt->setFloat( 7, item->getM1Vinj() );
00086     m_writeStmt->setFloat( 8, item->getM2Vinj() );
00087     m_writeStmt->setFloat( 9, item->getM1Vcc() );
00088     m_writeStmt->setFloat(10, item->getM2Vcc() );
00089     m_writeStmt->setFloat(11, item->getM1DCUTemp() );
00090     m_writeStmt->setFloat(12, item->getM2DCUTemp() );
00091     m_writeStmt->setFloat(13, item->getCCSTempLow() );
00092     m_writeStmt->setFloat(14, item->getCCSTempHigh() );
00093 
00094     m_writeStmt->executeUpdate();
00095   } catch (SQLException &e) {
00096     throw(std::runtime_error("DCUCCSDat::writeDB():  " + e.getMessage()));
00097   }
00098 }
00099 
00100 void DCUCCSDat::fetchData(std::map< EcalLogicID, DCUCCSDat >* fillMap, 
00101                           DCUIOV* iov)
00102   throw(std::runtime_error)
00103 {
00104   this->checkConnection();
00105   fillMap->clear();
00106 
00107   iov->setConnection(m_env, m_conn);
00108   int iovID = iov->fetchID();
00109   if (!iovID) { 
00110     //  throw(std::runtime_error("DCUCCSDat::writeDB:  IOV not in DB")); 
00111     return;
00112   }
00113 
00114   try {
00115 
00116     m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, "
00117                        "cv.maps_to, "
00118                        "d.m1_vdd1, d.m2_vdd1, d.m1_vdd2, d.m2_vdd2, "
00119                        "d.m1_vinj, d.m2_vinj, "
00120                        "d.m1_vcc, d.m2_vcc, "
00121                        "d.m1_dcutemp, d.m2_dcutemp, "
00122                        "d.ccstemplow, d.ccstemphigh "
00123                        "FROM channelview cv JOIN dcu_ccs_dat d "
00124                        "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00125                        "WHERE d.iov_id = :iov_id");
00126     m_readStmt->setInt(1, iovID);
00127     ResultSet* rset = m_readStmt->executeQuery();
00128     
00129     std::pair< EcalLogicID, DCUCCSDat > p;
00130     DCUCCSDat dat;
00131     while(rset->next()) {
00132       p.first = EcalLogicID( rset->getString(1),     // name
00133                              rset->getInt(2),        // logic_id
00134                              rset->getInt(3),        // id1
00135                              rset->getInt(4),        // id2
00136                              rset->getInt(5),        // id3
00137                              rset->getString(6));    // maps_to
00138 
00139       dat.setVDD(rset->getFloat(7), rset->getFloat(9), rset->getFloat(8),
00140                   rset->getFloat(10));
00141       dat.setVinj(rset->getFloat(11), rset->getFloat(12));
00142       dat.setVcc(rset->getFloat(13), rset->getFloat(14));
00143       dat.setDCUTemp(rset->getFloat(15), rset->getFloat(16));
00144       dat.setCCSTemp(rset->getFloat(17), rset->getFloat(18));
00145       p.second = dat;
00146       fillMap->insert(p);
00147     }
00148   } catch (SQLException &e) {
00149     throw(std::runtime_error("DCUCCSDat::fetchData():  "+e.getMessage()));
00150   }
00151 }
00152 
00153 void DCUCCSDat::writeArrayDB(const std::map< EcalLogicID, DCUCCSDat >* data, DCUIOV* iov)
00154   throw(std::runtime_error)
00155 {
00156   this->checkConnection();
00157   this->checkPrepare();
00158 
00159   int iovID = iov->fetchID();
00160   if (!iovID) { 
00161     throw(std::runtime_error("DCUCCSDat::writeArrayDB:  IOV not in DB")); 
00162   }
00163 
00164   int nrows=data->size(); 
00165   int* ids= new int[nrows];
00166   int* iovid_vec= new int[nrows];
00167   float* x1= new float[nrows];
00168   float* x2= new float[nrows];
00169   float* x3= new float[nrows];
00170   float* x4= new float[nrows];
00171   float* x5= new float[nrows];
00172   float* x6= new float[nrows];
00173   float* x7= new float[nrows];
00174   float* x8= new float[nrows];
00175   float* x9= new float[nrows];
00176   float* xa= new float[nrows];
00177   float* xb= new float[nrows];
00178   float* xc= new float[nrows];
00179 
00180   ub2* ids_len= new ub2[nrows];
00181   ub2* iov_len= new ub2[nrows];
00182   ub2* x_len  = new ub2[nrows];
00183 
00184   const EcalLogicID* channel;
00185   const DCUCCSDat* dataitem;
00186   int count=0;
00187   typedef map< EcalLogicID, DCUCCSDat >::const_iterator CI;
00188   for (CI p = data->begin(); p != data->end(); ++p) {
00189         channel = &(p->first);
00190         int logicID = channel->getLogicID();
00191         if (!logicID) { 
00192           throw(std::runtime_error("DCUCCSDat::writeArrayDB:  Bad EcalLogicID")); 
00193         }
00194         ids[count]=logicID;
00195         iovid_vec[count]=iovID;
00196         
00197         dataitem = &(p->second);
00198 
00199         x1[count] = dataitem->getM1VDD1();
00200         x2[count] = dataitem->getM2VDD1();
00201         x3[count] = dataitem->getM1VDD2();
00202         x4[count] = dataitem->getM2VDD2();
00203         x5[count] = dataitem->getM1Vinj();
00204         x6[count] = dataitem->getM2Vinj();
00205         x7[count] = dataitem->getM1Vcc();
00206         x8[count] = dataitem->getM2Vcc();
00207         x9[count] = dataitem->getM1DCUTemp();
00208         xa[count] = dataitem->getM2DCUTemp();
00209         xb[count] = dataitem->getCCSTempLow();
00210         xc[count] = dataitem->getCCSTempHigh();
00211 
00212         ids_len[count]=sizeof(ids[count]);
00213         iov_len[count]=sizeof(iovid_vec[count]);
00214         
00215         x_len[count]=sizeof(x1[count]);
00216 
00217         count++;
00218      }
00219 
00220 
00221   try {
00222     m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, 
00223                                sizeof(iovid_vec[0]),iov_len);
00224     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, 
00225                                sizeof(ids[0]), ids_len );
00226     m_writeStmt->setDataBuffer(3, (dvoid*)x1, OCCIFLOAT , 
00227                                sizeof(x1[0]), x_len );
00228     m_writeStmt->setDataBuffer(3, (dvoid*)x2, OCCIFLOAT , 
00229                                sizeof(x1[0]), x_len );
00230     m_writeStmt->setDataBuffer(3, (dvoid*)x3, OCCIFLOAT , 
00231                                sizeof(x1[0]), x_len );
00232     m_writeStmt->setDataBuffer(3, (dvoid*)x4, OCCIFLOAT , 
00233                                sizeof(x1[0]), x_len );
00234     m_writeStmt->setDataBuffer(3, (dvoid*)x5, OCCIFLOAT , 
00235                                sizeof(x1[0]), x_len );
00236     m_writeStmt->setDataBuffer(3, (dvoid*)x6, OCCIFLOAT , 
00237                                sizeof(x1[0]), x_len );
00238     m_writeStmt->setDataBuffer(3, (dvoid*)x7, OCCIFLOAT , 
00239                                sizeof(x1[0]), x_len );
00240     m_writeStmt->setDataBuffer(3, (dvoid*)x8, OCCIFLOAT , 
00241                                sizeof(x1[0]), x_len );
00242     m_writeStmt->setDataBuffer(3, (dvoid*)x9, OCCIFLOAT , 
00243                                sizeof(x1[0]), x_len );
00244     m_writeStmt->setDataBuffer(3, (dvoid*)xa, OCCIFLOAT , 
00245                                sizeof(x1[0]), x_len );
00246     m_writeStmt->setDataBuffer(3, (dvoid*)xb, OCCIFLOAT , 
00247                                sizeof(x1[0]), x_len );
00248     m_writeStmt->setDataBuffer(3, (dvoid*)xc, OCCIFLOAT , 
00249                                sizeof(x1[0]), x_len );
00250    
00251     m_writeStmt->executeArrayUpdate(nrows);
00252 
00253     delete [] ids;
00254     delete [] iovid_vec;
00255     delete [] x1;
00256     delete [] x2;
00257     delete [] x3;
00258     delete [] x4;
00259     delete [] x5;
00260     delete [] x6;
00261     delete [] x7;
00262     delete [] x8;
00263     delete [] x9;
00264     delete [] xa;
00265     delete [] xb;
00266     delete [] xc;
00267 
00268     delete [] ids_len;
00269     delete [] iov_len;
00270     delete [] x_len;
00271 
00272 
00273   } catch (SQLException &e) {
00274     throw(std::runtime_error("DCUCCSDat::writeArrayDB():  " + e.getMessage()));
00275   }
00276 }