CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/OnlineDB/EcalCondDB/src/MonPulseShapeDat.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/MonPulseShapeDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/MonRunTag.h"
00007 #include "OnlineDB/EcalCondDB/interface/MonRunIOV.h"
00008 
00009 using namespace std;
00010 using namespace oracle::occi;
00011 
00012 MonPulseShapeDat::MonPulseShapeDat()
00013 {
00014   m_env = NULL;
00015   m_conn = NULL;
00016   m_writeStmt = NULL;
00017   m_readStmt = NULL;
00018 
00019   m_samplesG1.assign(10, 0);
00020   m_samplesG6.assign(10, 0);
00021   m_samplesG12.assign(10, 0);
00022   
00023 }
00024 
00025 
00026 
00027 MonPulseShapeDat::~MonPulseShapeDat()
00028 {
00029 }
00030 
00031 
00032 
00033 void MonPulseShapeDat::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 mon_pulse_shape_dat (iov_id, logic_id, "
00041                         "g1_avg_sample_01, g1_avg_sample_02, g1_avg_sample_03, g1_avg_sample_04, g1_avg_sample_05, g1_avg_sample_06, g1_avg_sample_07, g1_avg_sample_08, g1_avg_sample_09, g1_avg_sample_10, "
00042                         "g6_avg_sample_01, g6_avg_sample_02, g6_avg_sample_03, g6_avg_sample_04, g6_avg_sample_05, g6_avg_sample_06, g6_avg_sample_07, g6_avg_sample_08, g6_avg_sample_09, g6_avg_sample_10, "
00043                         "g12_avg_sample_01, g12_avg_sample_02, g12_avg_sample_03, g12_avg_sample_04, g12_avg_sample_05, g12_avg_sample_06, g12_avg_sample_07, g12_avg_sample_08, g12_avg_sample_09, g12_avg_sample_10) "
00044                         "VALUES (:iov_id, :logic_id, "
00045                         ":g1_avg_sample_01, :g1_avg_sample_02, :g1_avg_sample_03, :g1_avg_sample_04, :g1_avg_sample_05, :g1_avg_sample_06, :g1_avg_sample_07, :g1_avg_sample_08, :g1_avg_sample_09, :g1_avg_sample_10,"
00046                         ":g6_avg_sample_01, :g6_avg_sample_02, :g6_avg_sample_03, :g6_avg_sample_04, :g6_avg_sample_05, :g6_avg_sample_06, :g6_avg_sample_07, :g6_avg_sample_08, :g6_avg_sample_09, :g6_avg_sample_10,"
00047                         ":g12_avg_sample_01, :g12_avg_sample_02, :g12_avg_sample_03, :g12_avg_sample_04, :g12_avg_sample_05, :g12_avg_sample_06, :g12_avg_sample_07, :g12_avg_sample_08, :g12_avg_sample_09, :g12_avg_sample_10)"
00048                         );
00049                         
00050   } catch (SQLException &e) {
00051     throw(std::runtime_error("MonPulseShapeDat::prepareWrite():  "+e.getMessage()));
00052   }
00053 }
00054 
00055 
00056 
00057 void MonPulseShapeDat::writeDB(const EcalLogicID* ecid, const MonPulseShapeDat* item, MonRunIOV* iov)
00058   throw(std::runtime_error)
00059 {
00060   this->checkConnection();
00061   this->checkPrepare();
00062 
00063   int iovID = iov->fetchID();
00064   if (!iovID) { throw(std::runtime_error("MonPulseShapeDat::writeDB:  IOV not in DB")); }
00065 
00066   int logicID = ecid->getLogicID();
00067   if (!logicID) { throw(std::runtime_error("MonPulseShapeDat::writeDB:  Bad EcalLogicID")); }
00068   
00069   try {
00070     m_writeStmt->setInt(1, iovID);
00071     m_writeStmt->setInt(2, logicID);
00072 
00073     int gain[] = {1, 6, 12};
00074     std::vector<float> samples;
00075     for (int i=0; i<3; i++) {
00076       samples = item->getSamples(gain[i]);
00077       for (int j=0; j<10; j++) {
00078         m_writeStmt->setFloat(3+(10*i)+j, samples.at(j));
00079       }
00080     }
00081 
00082     m_writeStmt->executeUpdate();
00083   } catch (SQLException &e) {
00084     throw(std::runtime_error("MonPulseShapeDat::writeDB:  "+e.getMessage()));
00085   } catch (exception &e) {
00086     throw(std::runtime_error("MonPulseShapeDat::writeDB:  " + string(e.what())));
00087   }
00088 }
00089 
00090 
00091 
00092 void MonPulseShapeDat::fetchData(std::map< EcalLogicID, MonPulseShapeDat >* fillMap, MonRunIOV* iov)
00093   throw(std::runtime_error)
00094 {
00095   this->checkConnection();
00096   fillMap->clear();
00097 
00098   iov->setConnection(m_env, m_conn);
00099   int iovID = iov->fetchID();
00100   if (!iovID) { 
00101     //  throw(std::runtime_error("MonPulseShapeDat::writeDB:  IOV not in DB")); 
00102     return;
00103   }
00104 
00105   try {
00106 
00107     m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00108                  "d.g1_avg_sample_01, d.g1_avg_sample_02, d.g1_avg_sample_03, d.g1_avg_sample_04, d.g1_avg_sample_05, d.g1_avg_sample_06, d.g1_avg_sample_07, d.g1_avg_sample_08, d.g1_avg_sample_09, d.g1_avg_sample_10, "
00109                  "d.g6_avg_sample_01, d.g6_avg_sample_02, d.g6_avg_sample_03, d.g6_avg_sample_04, d.g6_avg_sample_05, d.g6_avg_sample_06, d.g6_avg_sample_07, d.g6_avg_sample_08, d.g6_avg_sample_09, d.g6_avg_sample_10, "
00110                  "d.g12_avg_sample_01, d.g12_avg_sample_02, d.g12_avg_sample_03, d.g12_avg_sample_04, d.g12_avg_sample_05, d.g12_avg_sample_06, d.g12_avg_sample_07, d.g12_avg_sample_08, d.g12_avg_sample_09, d.g12_avg_sample_10 "
00111                  "FROM channelview cv JOIN mon_pulse_shape_dat d "
00112                  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00113                  "WHERE d.iov_id = :iov_id");
00114     m_readStmt->setInt(1, iovID);
00115     ResultSet* rset = m_readStmt->executeQuery();
00116     
00117     std::pair< EcalLogicID, MonPulseShapeDat > p;
00118     MonPulseShapeDat dat;
00119     while(rset->next()) {
00120       p.first = EcalLogicID( rset->getString(1),     // name
00121                              rset->getInt(2),        // logic_id
00122                              rset->getInt(3),        // id1
00123                              rset->getInt(4),        // id2
00124                              rset->getInt(5),        // id3
00125                              rset->getString(6));    // maps_to
00126 
00127       int gain[] = {1, 6, 12};
00128       std::vector<float> samples(10);
00129       for (int i=0; i<3; i++) {
00130         samples.clear();
00131         for (int j=0; j<10; j++) {
00132           samples.push_back( rset->getFloat(7+(10*i)+j) );
00133         }
00134         dat.setSamples(samples, gain[i]);
00135       }
00136 
00137       p.second = dat;
00138       fillMap->insert(p);
00139     }
00140   } catch (SQLException &e) {
00141     throw(std::runtime_error("MonPulseShapeDat::fetchData:  "+e.getMessage()));
00142   }
00143 }