CMS 3D CMS Logo

LMFLaserPrimDat.cc

Go to the documentation of this file.
00001 #include <stdexcept>
00002 #include <string>
00003 #include <cassert>
00004 
00005 #include "OnlineDB/Oracle/interface/Oracle.h"
00006 
00007 #include "OnlineDB/EcalCondDB/interface/LMFLaserPrimDat.h"
00008 #include "OnlineDB/EcalCondDB/interface/RunTag.h"
00009 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
00010 #include "OnlineDB/EcalCondDB/interface/IDBObject.h"
00011 
00012 using namespace std;
00013 using namespace oracle::occi;
00014 
00015 int LMFLaserPrimDat::_color = LMFLaserPrimDat::iBlue; //GHM
00016 
00017 LMFLaserPrimDat::LMFLaserPrimDat()
00018 {
00019   assert( _color>=iBlue && _color<=iIRed ); // GHM
00020 
00021   m_env = NULL;
00022   m_conn = NULL;
00023   m_writeStmt = NULL;
00024   m_readStmt = NULL;
00025 
00026 
00027    m_Mean=0;
00028    m_RMS=0;
00029    m_Peak=0;
00030    m_Flag=0;
00031    m_apdOverPNAMean=0;
00032    m_apdOverPNARMS=0;
00033    m_apdOverPNAPeak=0;
00034    m_apdOverPNBMean=0;
00035    m_apdOverPNBRMS=0;
00036    m_apdOverPNBPeak=0;
00037    m_apdOverPNMean=0;
00038    m_apdOverPNRMS=0;
00039    m_apdOverPNPeak=0;
00040    m_Alpha=0;
00041    m_Beta=0;
00042    m_ShapeCor=0;
00043 }
00044 
00045 LMFLaserPrimDat::LMFLaserPrimDat( const LMFLaserPrimDat& o ) :  // GHM
00046   m_Mean(o.m_Mean), m_RMS(o.m_RMS), 
00047   m_Peak(o.m_Peak), m_Flag(o.m_Flag),
00048   m_apdOverPNAMean(o.m_apdOverPNAMean),
00049   m_apdOverPNARMS(o.m_apdOverPNARMS),
00050   m_apdOverPNAPeak(o.m_apdOverPNAPeak),
00051   m_apdOverPNBMean(o.m_apdOverPNBMean),
00052   m_apdOverPNBRMS(o.m_apdOverPNBRMS),
00053   m_apdOverPNBPeak(o.m_apdOverPNBPeak),
00054   m_apdOverPNMean(o.m_apdOverPNMean),
00055   m_apdOverPNRMS(o.m_apdOverPNRMS),
00056   m_apdOverPNPeak(o.m_apdOverPNPeak),
00057   m_Alpha(o.m_Alpha),
00058   m_Beta(o.m_Beta),
00059   m_ShapeCor(o.m_ShapeCor)
00060 {
00061   assert( _color>=iBlue && _color<=iIRed );
00062   
00063   m_env = NULL;
00064   m_conn = NULL;
00065   m_writeStmt = NULL;
00066   m_readStmt = NULL;
00067 }
00068 
00069 
00070 LMFLaserPrimDat::~LMFLaserPrimDat()
00071 {
00072 }
00073 
00074 
00075 
00076 void LMFLaserPrimDat::prepareWrite()
00077   throw(runtime_error)
00078 {
00079   this->checkConnection();
00080 
00081   // GHM
00082   std::string command_ = "INSERT INTO XXXXXX (lmf_iov_id, logic_id, flag, mean, rms, peak,  apd_over_pnA_mean, apd_over_pnA_rms, apd_over_pnA_peak, apd_over_pnB_mean, apd_over_pnB_rms, apd_over_pnB_peak, apd_over_pn_mean, apd_over_pn_rms, apd_over_pn_peak, alpha, beta, shape_cor ) VALUES (:1, :2, :3, :4, :5, :6, :7, :8, :9, :10, :11, :12, :13, :14, :15, :16, :17, :18 )";
00083   command_.replace( command_.find("XXXXXX",0), 6, getTable() );
00084   //   cout << "In prepareWrite: command_" << command_ << endl;
00085   
00086   try {
00087     m_writeStmt = m_conn->createStatement();
00088     m_writeStmt->setSQL( command_.c_str() ); // GHM
00089   } catch (SQLException &e) {
00090     throw(runtime_error("LMFLaserPrimDat::prepareWrite():  "+e.getMessage()));
00091   }
00092 }
00093 
00094 
00095 
00096 void LMFLaserPrimDat::writeDB(const EcalLogicID* ecid, const LMFLaserPrimDat* item, LMFRunIOV* iov)
00097   throw(runtime_error)
00098 {
00099   this->checkConnection();
00100   this->checkPrepare();
00101 
00102   int iovID = iov->fetchID();
00103   if (!iovID) { throw(runtime_error("LMFLaserPrimDat::writeDB:  IOV not in DB")); }
00104 
00105   int logicID = ecid->getLogicID();
00106   if (!logicID) { throw(runtime_error("LMFLaserPrimDat::writeDB:  Bad EcalLogicID")); }
00107   
00108   try {
00109     m_writeStmt->setInt(1, iovID);
00110     m_writeStmt->setInt(2, logicID);
00111 
00112     m_writeStmt->setInt(3, item->getFlag() );
00113     m_writeStmt->setFloat(4, item->getMean() );
00114     m_writeStmt->setFloat(5, item->getRMS() );
00115     m_writeStmt->setFloat(6, item->getPeak() );
00116     m_writeStmt->setFloat(7, item->getAPDOverPNAMean() );
00117     m_writeStmt->setFloat(8, item->getAPDOverPNARMS() );
00118     m_writeStmt->setFloat(9, item->getAPDOverPNAPeak() );
00119     m_writeStmt->setFloat(10, item->getAPDOverPNBMean() );
00120     m_writeStmt->setFloat(11, item->getAPDOverPNBRMS() );
00121     m_writeStmt->setFloat(12, item->getAPDOverPNBPeak() );
00122     m_writeStmt->setFloat(13, item->getAPDOverPNMean() );
00123     m_writeStmt->setFloat(14, item->getAPDOverPNRMS() );
00124     m_writeStmt->setFloat(15, item->getAPDOverPNPeak() );
00125     m_writeStmt->setFloat(16, item->getAlpha() );
00126     m_writeStmt->setFloat(17, item->getBeta() );
00127     m_writeStmt->setFloat(18, item->getShapeCor() );
00128   
00129     m_writeStmt->executeUpdate();
00130   } catch (SQLException &e) {
00131     throw(runtime_error("LMFLaserPrimDat::writeDB():  "+e.getMessage()));
00132   }
00133 }
00134 
00135 
00136 void LMFLaserPrimDat::writeArrayDB(const std::map< EcalLogicID, LMFLaserPrimDat >* data, LMFRunIOV* iov)
00137   throw(runtime_error)
00138 {
00139   this->checkConnection();
00140   this->checkPrepare();
00141 
00142   int iovID = iov->fetchID();
00143   if (!iovID) { throw(runtime_error("LMFLaserPrimDat::writeArrayDB:  IOV not in DB")); }
00144 
00145 
00146   int nrows=data->size(); 
00147   int* ids= new int[nrows];
00148   int* iovid_vec= new int[nrows];
00149   int* aa= new int[nrows];
00150   float* xx= new float[nrows];
00151   float* yy= new float[nrows];
00152   float* zz= new float[nrows];
00153   float* wwa= new float[nrows];
00154   float* uua= new float[nrows];
00155   float* tta= new float[nrows];
00156   float* wwb= new float[nrows];
00157   float* uub= new float[nrows];
00158   float* ttb= new float[nrows];
00159   float* ww= new float[nrows];
00160   float* uu= new float[nrows];
00161   float* tt= new float[nrows];
00162   float* ualpha= new float[nrows];
00163   float* ubeta= new float[nrows];
00164   float* ushapecor= new float[nrows];
00165 
00166   ub2* ids_len= new ub2[nrows];
00167   ub2* iov_len= new ub2[nrows];
00168   ub2* a_len= new ub2[nrows];
00169   ub2* x_len= new ub2[nrows];
00170   ub2* y_len= new ub2[nrows];
00171   ub2* z_len= new ub2[nrows];
00172   ub2* wa_len= new ub2[nrows];
00173   ub2* ua_len= new ub2[nrows];
00174   ub2* ta_len= new ub2[nrows];
00175   ub2* wb_len= new ub2[nrows];
00176   ub2* ub_len= new ub2[nrows];
00177   ub2* tb_len= new ub2[nrows];
00178   ub2* w_len= new ub2[nrows];
00179   ub2* u_len= new ub2[nrows];
00180   ub2* t_len= new ub2[nrows];
00181   ub2* ualpha_len= new ub2[nrows];
00182   ub2* ubeta_len= new ub2[nrows];
00183   ub2* ushapecor_len= new ub2[nrows];
00184 
00185   const EcalLogicID* channel;
00186   const LMFLaserPrimDat* dataitem;
00187   int count=0;
00188   typedef map< EcalLogicID, LMFLaserPrimDat >::const_iterator CI;
00189   for (CI p = data->begin(); p != data->end(); ++p) {
00190         channel = &(p->first);
00191         int logicID = channel->getLogicID();
00192         if (!logicID) { throw(runtime_error("LMFLaserPrimDat::writeArrayDB:  Bad EcalLogicID")); }
00193         ids[count]=logicID;
00194         iovid_vec[count]=iovID;
00195 
00196         dataitem = &(p->second);
00197         // dataIface.writeDB( channel, dataitem, iov);
00198         int a=dataitem->getFlag();
00199         float x=dataitem->getMean();
00200         float y=dataitem->getRMS();
00201         float z=dataitem->getPeak();
00202         float wa=dataitem->getAPDOverPNAMean();
00203         float ua=dataitem->getAPDOverPNARMS();
00204         float ta=dataitem->getAPDOverPNAPeak();
00205         float wb=dataitem->getAPDOverPNBMean();
00206         float ub=dataitem->getAPDOverPNBRMS();
00207         float tb=dataitem->getAPDOverPNBPeak();
00208         float w=dataitem->getAPDOverPNMean();
00209         float u=dataitem->getAPDOverPNRMS();
00210         float t=dataitem->getAPDOverPNPeak();
00211         float alpha=dataitem->getAlpha();
00212         float beta=dataitem->getBeta();
00213         float shapecor=dataitem->getShapeCor();
00214 
00215 
00216         aa[count]=a;
00217         xx[count]=x;
00218         yy[count]=y;
00219         zz[count]=z;
00220         wwa[count]=wa;
00221         uua[count]=ua;
00222         tta[count]=ta;
00223         wwb[count]=wb;
00224         uub[count]=ub;
00225         ttb[count]=tb;
00226         ww[count]=w;
00227         uu[count]=u;
00228         tt[count]=t;
00229         ualpha[count]=alpha;
00230         ubeta[count]=beta;
00231         ushapecor[count]=shapecor;
00232 
00233         ids_len[count]=sizeof(ids[count]);
00234         iov_len[count]=sizeof(iovid_vec[count]);
00235         
00236         a_len[count]=sizeof(aa[count]);
00237         x_len[count]=sizeof(xx[count]);
00238         y_len[count]=sizeof(yy[count]);
00239         z_len[count]=sizeof(zz[count]);
00240         wa_len[count]=sizeof(wwa[count]);
00241         ua_len[count]=sizeof(uua[count]);
00242         ta_len[count]=sizeof(tta[count]);
00243         wb_len[count]=sizeof(wwb[count]);
00244         ub_len[count]=sizeof(uub[count]);
00245         tb_len[count]=sizeof(ttb[count]);
00246         w_len[count]=sizeof(ww[count]);
00247         u_len[count]=sizeof(uu[count]);
00248         t_len[count]=sizeof(tt[count]);
00249         ualpha_len[count]=sizeof(ualpha[count]);
00250         ubeta_len[count]=sizeof(ubeta[count]);
00251         ushapecor_len[count]=sizeof(ushapecor[count]);
00252 
00253         count++;
00254      }
00255 
00256 
00257   try {
00258     m_writeStmt->setDataBuffer(1,  (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
00259     m_writeStmt->setDataBuffer(2,  (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
00260     m_writeStmt->setDataBuffer(3,  (dvoid*)aa,  OCCIINT , sizeof(aa[0]), a_len );
00261     m_writeStmt->setDataBuffer(4,  (dvoid*)xx,  OCCIFLOAT , sizeof(xx[0]), x_len );
00262     m_writeStmt->setDataBuffer(5,  (dvoid*)yy,  OCCIFLOAT , sizeof(yy[0]), y_len );
00263     m_writeStmt->setDataBuffer(6,  (dvoid*)zz,  OCCIFLOAT , sizeof(zz[0]), z_len );
00264     m_writeStmt->setDataBuffer(7,  (dvoid*)wwa, OCCIFLOAT , sizeof(wwa[0]), wa_len );
00265     m_writeStmt->setDataBuffer(8,  (dvoid*)uua, OCCIFLOAT , sizeof(uua[0]), ua_len );
00266     m_writeStmt->setDataBuffer(9,  (dvoid*)tta, OCCIFLOAT , sizeof(tta[0]), ta_len );
00267     m_writeStmt->setDataBuffer(10, (dvoid*)wwb, OCCIFLOAT , sizeof(wwb[0]), wb_len );
00268     m_writeStmt->setDataBuffer(11, (dvoid*)uub, OCCIFLOAT , sizeof(uub[0]), ub_len );
00269     m_writeStmt->setDataBuffer(12, (dvoid*)ttb, OCCIFLOAT , sizeof(ttb[0]), tb_len );
00270     m_writeStmt->setDataBuffer(13, (dvoid*)ww,  OCCIFLOAT , sizeof(ww[0]),   w_len );
00271     m_writeStmt->setDataBuffer(14, (dvoid*)uu,  OCCIFLOAT , sizeof(uu[0]),   u_len );
00272     m_writeStmt->setDataBuffer(15, (dvoid*)tt,  OCCIFLOAT , sizeof(tt[0]),   t_len );
00273     m_writeStmt->setDataBuffer(16, (dvoid*)ualpha, OCCIFLOAT , sizeof(ualpha[0]), ualpha_len );
00274     m_writeStmt->setDataBuffer(17, (dvoid*)ubeta,  OCCIFLOAT , sizeof(ubeta[0]),  ubeta_len );
00275     m_writeStmt->setDataBuffer(18, (dvoid*)ushapecor,  OCCIFLOAT , sizeof(ushapecor[0]),  ushapecor_len );
00276 
00277     m_writeStmt->executeArrayUpdate(nrows);
00278 
00279     delete [] ids;
00280     delete [] iovid_vec;
00281     delete [] aa;
00282     delete [] xx;
00283     delete [] yy;
00284     delete [] zz;
00285     delete [] ww;
00286     delete [] uu;
00287     delete [] tt;
00288     delete [] wwa;
00289     delete [] uua;
00290     delete [] tta;
00291     delete [] wwb;
00292     delete [] uub;
00293     delete [] ttb;
00294     delete [] ualpha;
00295     delete [] ubeta;
00296     delete [] ushapecor;
00297 
00298     delete [] ids_len;
00299     delete [] iov_len;
00300     delete [] a_len;
00301     delete [] x_len;
00302     delete [] y_len;
00303     delete [] z_len;
00304     delete [] w_len;
00305     delete [] u_len;
00306     delete [] t_len;
00307     delete [] wa_len;
00308     delete [] ua_len;
00309     delete [] ta_len;
00310     delete [] wb_len;
00311     delete [] ub_len;
00312     delete [] tb_len;
00313     delete [] ualpha_len;
00314     delete [] ubeta_len;
00315     delete [] ushapecor_len;
00316    
00317 
00318 
00319 
00320   } catch (SQLException &e) {
00321     throw(runtime_error("LMFLaserPrimDat::writeArrayDB():  "+e.getMessage()));
00322   }
00323 }
00324 
00325 void LMFLaserPrimDat::fetchData(std::map< EcalLogicID, LMFLaserPrimDat >* fillMap, LMFRunIOV* iov)
00326   throw(runtime_error)
00327 {
00328   this->checkConnection();
00329   fillMap->clear();
00330 
00331   iov->setConnection(m_env, m_conn);
00332   int iovID = iov->fetchID();
00333   if (!iovID) { 
00334     //  throw(runtime_error("LMFLaserPrimDat::writeDB:  IOV not in DB")); 
00335     return;
00336   }
00337 
00338   // GHM
00339   std::string command_ = "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, d.flag, d.mean, d.rms, d.peak, d.apd_over_pnA_mean, d.apd_over_pnA_rms, d.apd_over_pnA_peak, d.apd_over_pnB_mean, d.apd_over_pnB_rms,d.apd_over_pnB_peak, d.apd_over_pn_mean, d.apd_over_pn_rms, d.apd_over_pn_peak, d.alpha, d.beta, d.shape_cor FROM channelview cv JOIN XXXXXX d ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to WHERE d.lmf_iov_id = :iov_id";
00340   command_.replace( command_.find("XXXXXX",0), 6, getTable() );
00341 
00342   //  cout << "in fetchData: command_=" << command_ << endl;
00343 
00344   try {
00345   
00346 
00347     m_readStmt->setSQL( command_.c_str() );  // GHM
00348  
00349     m_readStmt->setInt(1, iovID);
00350     
00351     ResultSet* rset = m_readStmt->executeQuery();
00352      
00353     std::pair< EcalLogicID, LMFLaserPrimDat > p;
00354     LMFLaserPrimDat dat;
00355     while(rset->next()) {
00356       p.first = EcalLogicID( rset->getString(1),     // name
00357                              rset->getInt(2),        // logic_id
00358                              rset->getInt(3),        // id1
00359                              rset->getInt(4),        // id2
00360                              rset->getInt(5),        // id3
00361                              rset->getString(6));    // maps_to
00362 
00363 
00364       dat.setFlag( rset->getInt(7) );
00365       dat.setMean( rset->getFloat(8) );
00366       dat.setRMS( rset->getFloat(9) );
00367       dat.setPeak( rset->getFloat(10) );
00368 
00369       dat.setAPDOverPNAMean( rset->getFloat(11) );
00370       dat.setAPDOverPNARMS( rset->getFloat(12) );
00371       dat.setAPDOverPNAPeak( rset->getFloat(13) );
00372 
00373       dat.setAPDOverPNBMean( rset->getFloat(14) );
00374       dat.setAPDOverPNBRMS( rset->getFloat(15) );
00375       dat.setAPDOverPNBPeak( rset->getFloat(16) );
00376 
00377       dat.setAPDOverPNMean( rset->getFloat(17) );
00378       dat.setAPDOverPNRMS( rset->getFloat(18) );
00379       dat.setAPDOverPNPeak( rset->getFloat(19) );
00380 
00381       dat.setAlpha( rset->getFloat(20) );
00382       dat.setBeta( rset->getFloat(21) );
00383       dat.setShapeCor( rset->getFloat(22) );
00384       p.second = dat;
00385       fillMap->insert(p);
00386     }
00387 
00388   } catch (SQLException &e) {
00389     throw(runtime_error("LMFLaserPrimDat::fetchData():  "+e.getMessage()));
00390   }
00391 }
00392 
00393 void
00394 LMFLaserPrimDat::setColor( int color ) { _color = color; }

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