CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/OnlineDB/EcalCondDB/src/FEConfigLUTGroupDat.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/FEConfigLUTGroupDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/FEConfigLUTInfo.h"
00007 
00008 using namespace std;
00009 using namespace oracle::occi;
00010 
00011 FEConfigLUTGroupDat::FEConfigLUTGroupDat()
00012 {
00013   m_env = NULL;
00014   m_conn = NULL;
00015   m_writeStmt = NULL;
00016   m_readStmt = NULL;
00017 
00018   m_group_id=0;
00019   for(int i=0; i<1024; i++){
00020     m_lut[i] = 0;
00021   }
00022 
00023 }
00024 
00025 
00026 
00027 FEConfigLUTGroupDat::~FEConfigLUTGroupDat()
00028 {
00029 }
00030 
00031 
00032 
00033 void FEConfigLUTGroupDat::prepareWrite()
00034   throw(std::runtime_error)
00035 {
00036   this->checkConnection();
00037 
00038   try {
00039     m_writeStmt = m_conn->createStatement();
00040     m_writeStmt->setSQL("INSERT INTO fe_lut_per_group_dat (lut_conf_id, group_id, "
00041                       " lut_id, lut_value ) "
00042                       "VALUES (:lut_conf_id, :group_id, "
00043                       ":lut_id, :lut_value )" );
00044   } catch (SQLException &e) {
00045     throw(std::runtime_error("FEConfigLUTGroupDat::prepareWrite():  "+e.getMessage()));
00046   }
00047 }
00048 
00049 void FEConfigLUTGroupDat::writeDB(const EcalLogicID* ecid, const FEConfigLUTGroupDat* item, FEConfigLUTInfo* iconf)
00050   throw(std::runtime_error)
00051 {
00052   this->checkConnection();
00053   this->checkPrepare();
00054 
00055   int iconfID = iconf->fetchID();
00056 
00057   cout<< "iconf="<< iconfID << endl;
00058 
00059   if (!iconfID) { throw(std::runtime_error("FEConfigLUTGroupDat::writeArrayDB:  ICONF not in DB")); }
00060 
00061 
00062   int nrows=1024;
00063   int* iconfid_vec= new int[nrows];
00064   int* xx= new int[nrows];
00065   int* yy= new int[nrows];
00066   int* zz= new int[nrows];
00067 
00068 
00069   ub2* iconf_len= new ub2[nrows];
00070   ub2* x_len= new ub2[nrows];
00071   ub2* y_len= new ub2[nrows];
00072   ub2* z_len= new ub2[nrows];
00073 
00074 
00075 
00076     for(int count=0; count<nrows; count++){
00077 
00078         iconfid_vec[count]=iconfID;
00079         int x=item->getLUTGroupId();
00080         int y=count;
00081         int z=m_lut[count];
00082 
00083         xx[count]=x;
00084         yy[count]=y;
00085         zz[count]=z;
00086 
00087         iconf_len[count]=sizeof(iconfid_vec[count]);
00088         
00089         x_len[count]=sizeof(xx[count]);
00090         y_len[count]=sizeof(yy[count]);
00091         z_len[count]=sizeof(zz[count]);
00092 
00093      }
00094 
00095 
00096   try {
00097     m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]),iconf_len);
00098     m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len );
00099     m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT , sizeof(yy[0]), y_len );
00100     m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT , sizeof(zz[0]), z_len );
00101 
00102     m_writeStmt->executeArrayUpdate(nrows);
00103 
00104 
00105     delete [] iconfid_vec;
00106     delete [] xx;
00107     delete [] yy;
00108     delete [] zz;
00109 
00110 
00111 
00112     delete [] iconf_len;
00113     delete [] x_len;
00114     delete [] y_len;
00115     delete [] z_len;
00116 
00117 
00118   } catch (SQLException &e) {
00119     throw(std::runtime_error("FEConfigLUTGroupDat::writeArrayDB():  "+e.getMessage()));
00120   }
00121 }
00122 
00123 
00124 void FEConfigLUTGroupDat::fetchData(map< EcalLogicID, FEConfigLUTGroupDat >* fillMap, FEConfigLUTInfo* iconf)
00125   throw(std::runtime_error)
00126 {
00127   this->checkConnection();
00128   fillMap->clear();
00129 
00130   iconf->setConnection(m_env, m_conn);
00131   int iconfID = iconf->fetchID();
00132   if (!iconfID) { 
00133      throw(std::runtime_error("FEConfigLUTGroupDat::fetchData:  ICONF not in DB")); 
00134     return;
00135   }
00136   
00137   try {
00138 
00139     m_readStmt->setSQL("SELECT d.group_id, d.lut_id, d.lut_value "
00140                  "FROM fe_lut_per_group_dat d "
00141                  "WHERE lut_conf_id = :lut_conf_id order by d.group_id, d.lut_id ");
00142     m_readStmt->setInt(1, iconfID);
00143     ResultSet* rset = m_readStmt->executeQuery();
00144 
00145     FEConfigLUTGroupDat* dat(0);
00146     std::pair< EcalLogicID, FEConfigLUTGroupDat > p;
00147 
00148 
00149     int nrows=1024;
00150 
00151     int igold=-1;
00152     int ig=igold;
00153 
00154     while(rset->next()) {
00155       ig=rset->getInt(1);
00156       int il=rset->getInt(2);  
00157       int ival=rset->getInt(3);
00158       if(il==0){
00159         
00160         p.first = EcalLogicID( "Group_id",  ig );   // a dummy logic_id
00161         dat=new FEConfigLUTGroupDat();
00162         dat->setLUTGroupId( ig );
00163         dat->setLUTValue( il, ival );  
00164       } else {
00165         dat->setLUTValue( il, ival );
00166       }
00167 
00168       if(il==(nrows-1)){
00169 
00170         p.second = *dat;
00171         fillMap->insert(p);
00172          delete dat;
00173       }
00174     }
00175   } catch (SQLException &e) {
00176     throw(std::runtime_error("FEConfigLUTGroupDat::fetchData:  "+e.getMessage()));
00177   }
00178 }
00179 
00180 void FEConfigLUTGroupDat::writeArrayDB(const std::map< EcalLogicID, FEConfigLUTGroupDat >* data, FEConfigLUTInfo* iconf)
00181   throw(std::runtime_error)
00182 {
00183   this->checkConnection();
00184   this->checkPrepare();
00185 
00186   int iconfID = iconf->fetchID();
00187   if (!iconfID) { throw(std::runtime_error("FEConfigLUTGroupDat::writeArrayDB:  ICONF not in DB")); }
00188 
00189 
00190   int nrows=data->size()*1024; 
00191   
00192   int* iconfid_vec= new int[nrows];
00193   int* xx= new int[nrows];
00194   int* yy= new int[nrows];
00195   int* zz= new int[nrows];
00196 
00197 
00198 
00199   ub2* iconf_len= new ub2[nrows];
00200   ub2* x_len= new ub2[nrows];
00201   ub2* y_len= new ub2[nrows];
00202   ub2* z_len= new ub2[nrows];
00203 
00204 
00205   const FEConfigLUTGroupDat* dataitem;
00206   int count=0;
00207   typedef map< EcalLogicID, FEConfigLUTGroupDat >::const_iterator CI;
00208   for (CI p = data->begin(); p != data->end(); ++p) {
00209         
00210         
00211         dataitem = &(p->second);
00212         int x=dataitem->getLUTGroupId();
00213         
00214 
00215         for (int i=0; i<1024; i++){
00216           iconfid_vec[count]=iconfID;
00217           int y=i;
00218           int z=dataitem->getLUTValue(i);
00219 
00220           xx[count]=x;
00221           yy[count]=y;
00222           zz[count]=z;
00223           
00224           
00225           iconf_len[count]=sizeof(iconfid_vec[count]);
00226           
00227           x_len[count]=sizeof(xx[count]);
00228           y_len[count]=sizeof(yy[count]);
00229           z_len[count]=sizeof(zz[count]);
00230           
00231           count++;
00232 
00233         }
00234      }
00235 
00236 
00237   try {
00238 
00239     //    for (int i=0; i<nrows; i++){
00240 
00241     int i=0;
00242       cout << "about to insert "<< iconfid_vec[i]<<" " <<xx[i]<< " "<< yy[i]<< " "<< zz[i]<< endl;
00243      i=nrows-1;
00244       cout << "about to insert "<< iconfid_vec[i]<<" " <<xx[i]<< " "<< yy[i]<< " "<< zz[i]<< endl;
00245       // }
00246     m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]),iconf_len);
00247     m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len );
00248     m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT , sizeof(yy[0]), y_len );
00249     m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT , sizeof(zz[0]), z_len );
00250 
00251     m_writeStmt->executeArrayUpdate(nrows);
00252 
00253 
00254     delete [] iconfid_vec;
00255     delete [] xx;
00256     delete [] yy;
00257     delete [] zz;
00258 
00259 
00260 
00261     delete [] iconf_len;
00262     delete [] x_len;
00263     delete [] y_len;
00264     delete [] z_len;
00265 
00266 
00267   } catch (SQLException &e) {
00268     throw(std::runtime_error("FEConfigLUTGroupDat::writeArrayDB():  "+e.getMessage()));
00269   }
00270 }