CMS 3D CMS Logo

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(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(runtime_error("FEConfigLUTGroupDat::prepareWrite():  "+e.getMessage()));
00046   }
00047 }
00048 
00049 void FEConfigLUTGroupDat::writeDB(const EcalLogicID* ecid, const FEConfigLUTGroupDat* item, FEConfigLUTInfo* iconf)
00050   throw(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(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(runtime_error("FEConfigLUTGroupDat::writeArrayDB():  "+e.getMessage()));
00120   }
00121 }
00122 
00123 
00124 void FEConfigLUTGroupDat::fetchData(map< EcalLogicID, FEConfigLUTGroupDat >* fillMap, FEConfigLUTInfo* iconf)
00125   throw(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(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_config_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;
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(7);
00156       int il=rset->getInt(8);  
00157       int ival=rset->getInt(9);
00158       if(ig!=igold){
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       if(il==(nrows-1)){
00168         p.second = *dat;
00169         fillMap->insert(p);
00170         delete dat;
00171       }
00172     }
00173   } catch (SQLException &e) {
00174     throw(runtime_error("FEConfigLUTGroupDat::fetchData:  "+e.getMessage()));
00175   }
00176 }
00177 
00178 void FEConfigLUTGroupDat::writeArrayDB(const std::map< EcalLogicID, FEConfigLUTGroupDat >* data, FEConfigLUTInfo* iconf)
00179   throw(runtime_error)
00180 {
00181   this->checkConnection();
00182   this->checkPrepare();
00183 
00184   int iconfID = iconf->fetchID();
00185   if (!iconfID) { throw(runtime_error("FEConfigLUTGroupDat::writeArrayDB:  ICONF not in DB")); }
00186 
00187 
00188   int nrows=data->size()*1024; 
00189   
00190   int* iconfid_vec= new int[nrows];
00191   int* xx= new int[nrows];
00192   int* yy= new int[nrows];
00193   int* zz= new int[nrows];
00194 
00195 
00196 
00197   ub2* iconf_len= new ub2[nrows];
00198   ub2* x_len= new ub2[nrows];
00199   ub2* y_len= new ub2[nrows];
00200   ub2* z_len= new ub2[nrows];
00201 
00202 
00203   const FEConfigLUTGroupDat* dataitem;
00204   int count=0;
00205   typedef map< EcalLogicID, FEConfigLUTGroupDat >::const_iterator CI;
00206   for (CI p = data->begin(); p != data->end(); ++p) {
00207         
00208         
00209         dataitem = &(p->second);
00210         int x=dataitem->getLUTGroupId();
00211         
00212 
00213         for (int i=0; i<1024; i++){
00214           iconfid_vec[count]=iconfID;
00215           int y=i;
00216           int z=dataitem->getLUTValue(i);
00217 
00218           xx[count]=x;
00219           yy[count]=y;
00220           zz[count]=z;
00221           
00222           
00223           iconf_len[count]=sizeof(iconfid_vec[count]);
00224           
00225           x_len[count]=sizeof(xx[count]);
00226           y_len[count]=sizeof(yy[count]);
00227           z_len[count]=sizeof(zz[count]);
00228           
00229           count++;
00230 
00231         }
00232      }
00233 
00234 
00235   try {
00236 
00237     //    for (int i=0; i<nrows; i++){
00238 
00239     int i=0;
00240       cout << "about to insert "<< iconfid_vec[i]<<" " <<xx[i]<< " "<< yy[i]<< " "<< zz[i]<< endl;
00241      i=nrows-1;
00242       cout << "about to insert "<< iconfid_vec[i]<<" " <<xx[i]<< " "<< yy[i]<< " "<< zz[i]<< endl;
00243       // }
00244     m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]),iconf_len);
00245     m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len );
00246     m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT , sizeof(yy[0]), y_len );
00247     m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT , sizeof(zz[0]), z_len );
00248 
00249     m_writeStmt->executeArrayUpdate(nrows);
00250 
00251 
00252     delete [] iconfid_vec;
00253     delete [] xx;
00254     delete [] yy;
00255     delete [] zz;
00256 
00257 
00258 
00259     delete [] iconf_len;
00260     delete [] x_len;
00261     delete [] y_len;
00262     delete [] z_len;
00263 
00264 
00265   } catch (SQLException &e) {
00266     throw(runtime_error("FEConfigLUTGroupDat::writeArrayDB():  "+e.getMessage()));
00267   }
00268 }

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