#include <OnlineDB/EcalCondDB/interface/MonPulseShapeDat.h>
Public Member Functions | |
std::vector< float > | getSamples (int gain) const throw (std::runtime_error) |
std::string | getTable () |
MonPulseShapeDat () | |
void | setSamples (std::vector< float > &samples, int gain) throw (std::runtime_error) |
~MonPulseShapeDat () | |
Private Member Functions | |
void | fetchData (std::map< EcalLogicID, MonPulseShapeDat > *fillVec, MonRunIOV *iov) throw (std::runtime_error) |
void | prepareWrite () throw (std::runtime_error) |
void | writeDB (const EcalLogicID *ecid, const MonPulseShapeDat *item, MonRunIOV *iov) throw (std::runtime_error) |
Private Attributes | |
std::vector< float > | m_samplesG1 |
std::vector< float > | m_samplesG12 |
std::vector< float > | m_samplesG6 |
Friends | |
class | EcalCondDBInterface |
Definition at line 13 of file MonPulseShapeDat.h.
MonPulseShapeDat::MonPulseShapeDat | ( | ) |
Definition at line 12 of file MonPulseShapeDat.cc.
References IDBObject::m_conn, IDBObject::m_env, IDataItem::m_readStmt, m_samplesG1, m_samplesG12, m_samplesG6, IDataItem::m_writeStmt, and NULL.
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 }
MonPulseShapeDat::~MonPulseShapeDat | ( | ) |
void MonPulseShapeDat::fetchData | ( | std::map< EcalLogicID, MonPulseShapeDat > * | fillVec, | |
MonRunIOV * | iov | |||
) | throw (std::runtime_error) [private] |
Definition at line 92 of file MonPulseShapeDat.cc.
References IDBObject::checkConnection(), e, i, j, IDBObject::m_conn, IDBObject::m_env, IDataItem::m_readStmt, p, and setSamples().
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(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 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(runtime_error("MonPulseShapeDat::fetchData: "+e.getMessage())); 00142 } 00143 }
std::vector<float> MonPulseShapeDat::getSamples | ( | int | gain | ) | const throw (std::runtime_error) [inline] |
Definition at line 40 of file MonPulseShapeDat.h.
References m_samplesG1, m_samplesG12, and m_samplesG6.
00042 { 00043 if (gain == 1) { 00044 return m_samplesG1; 00045 } else if (gain == 6) { 00046 return m_samplesG6; 00047 } else if (gain == 12) { 00048 return m_samplesG12; 00049 } else { 00050 throw(std::runtime_error("MonPulseShapeDat::getSamples: Gain should be 1, 6 or 12")); 00051 } 00052 }
std::string MonPulseShapeDat::getTable | ( | ) | [inline, virtual] |
void MonPulseShapeDat::prepareWrite | ( | ) | throw (std::runtime_error) [private, virtual] |
Implements IDataItem.
Definition at line 33 of file MonPulseShapeDat.cc.
References IDBObject::checkConnection(), e, IDBObject::m_conn, and IDataItem::m_writeStmt.
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(runtime_error("MonPulseShapeDat::prepareWrite(): "+e.getMessage())); 00052 } 00053 }
void MonPulseShapeDat::setSamples | ( | std::vector< float > & | samples, | |
int | gain | |||
) | throw (std::runtime_error) [inline] |
Definition at line 22 of file MonPulseShapeDat.h.
References m_samplesG1, m_samplesG12, and m_samplesG6.
Referenced by fetchData(), EBTestPulseClient::writeDb(), and EETestPulseClient::writeDb().
00024 { 00025 if (samples.size() != 10) { 00026 throw(std::runtime_error("MonPulseShapeDat::setSamples: There should be 10 samples.")); 00027 } 00028 00029 if (gain == 1) { 00030 m_samplesG1 = samples; 00031 } else if (gain == 6) { 00032 m_samplesG6 = samples; 00033 } else if (gain == 12) { 00034 m_samplesG12 = samples; 00035 } else { 00036 throw(std::runtime_error("MonPulseShapeDat::setSamples: Gain should be 1, 6 or 12")); 00037 } 00038 }
void MonPulseShapeDat::writeDB | ( | const EcalLogicID * | ecid, | |
const MonPulseShapeDat * | item, | |||
MonRunIOV * | iov | |||
) | throw (std::runtime_error) [private] |
Definition at line 57 of file MonPulseShapeDat.cc.
References IDBObject::checkConnection(), IDataItem::checkPrepare(), e, exception, i, j, and IDataItem::m_writeStmt.
00059 { 00060 this->checkConnection(); 00061 this->checkPrepare(); 00062 00063 int iovID = iov->fetchID(); 00064 if (!iovID) { throw(runtime_error("MonPulseShapeDat::writeDB: IOV not in DB")); } 00065 00066 int logicID = ecid->getLogicID(); 00067 if (!logicID) { throw(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 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(runtime_error("MonPulseShapeDat::writeDB: "+e.getMessage())); 00085 } catch (exception &e) { 00086 throw(runtime_error("MonPulseShapeDat::writeDB: " + string(e.what()))); 00087 } 00088 }
friend class EcalCondDBInterface [friend] |
std::vector<float> MonPulseShapeDat::m_samplesG1 [private] |
Definition at line 65 of file MonPulseShapeDat.h.
Referenced by getSamples(), MonPulseShapeDat(), and setSamples().
std::vector<float> MonPulseShapeDat::m_samplesG12 [private] |
Definition at line 67 of file MonPulseShapeDat.h.
Referenced by getSamples(), MonPulseShapeDat(), and setSamples().
std::vector<float> MonPulseShapeDat::m_samplesG6 [private] |
Definition at line 66 of file MonPulseShapeDat.h.
Referenced by getSamples(), MonPulseShapeDat(), and setSamples().