CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes | Friends

MonPulseShapeDat Class Reference

#include <MonPulseShapeDat.h>

Inheritance diagram for MonPulseShapeDat:
IDataItem IDBObject

List of all members.

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

Detailed Description

Definition at line 13 of file MonPulseShapeDat.h.


Constructor & Destructor Documentation

MonPulseShapeDat::MonPulseShapeDat ( )

Definition at line 12 of file MonPulseShapeDat.cc.

References NULL.

{
  m_env = NULL;
  m_conn = NULL;
  m_writeStmt = NULL;
  m_readStmt = NULL;

  m_samplesG1.assign(10, 0);
  m_samplesG6.assign(10, 0);
  m_samplesG12.assign(10, 0);
  
}
MonPulseShapeDat::~MonPulseShapeDat ( )

Definition at line 27 of file MonPulseShapeDat.cc.

{
}

Member Function Documentation

void MonPulseShapeDat::fetchData ( std::map< EcalLogicID, MonPulseShapeDat > *  fillVec,
MonRunIOV iov 
) throw (std::runtime_error) [private]

Definition at line 92 of file MonPulseShapeDat.cc.

References alignCSCRings::e, edm::pset::fillMap(), i, o2o::iov, j, AlCaHLTBitMon_ParallelJobs::p, and setSamples().

{
  this->checkConnection();
  fillMap->clear();

  iov->setConnection(m_env, m_conn);
  int iovID = iov->fetchID();
  if (!iovID) { 
    //  throw(std::runtime_error("MonPulseShapeDat::writeDB:  IOV not in DB")); 
    return;
  }

  try {

    m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
                 "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, "
                 "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, "
                 "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 "
                 "FROM channelview cv JOIN mon_pulse_shape_dat d "
                 "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
                 "WHERE d.iov_id = :iov_id");
    m_readStmt->setInt(1, iovID);
    ResultSet* rset = m_readStmt->executeQuery();
    
    std::pair< EcalLogicID, MonPulseShapeDat > p;
    MonPulseShapeDat dat;
    while(rset->next()) {
      p.first = EcalLogicID( rset->getString(1),     // name
                             rset->getInt(2),        // logic_id
                             rset->getInt(3),        // id1
                             rset->getInt(4),        // id2
                             rset->getInt(5),        // id3
                             rset->getString(6));    // maps_to

      int gain[] = {1, 6, 12};
      std::vector<float> samples(10);
      for (int i=0; i<3; i++) {
        samples.clear();
        for (int j=0; j<10; j++) {
          samples.push_back( rset->getFloat(7+(10*i)+j) );
        }
        dat.setSamples(samples, gain[i]);
      }

      p.second = dat;
      fillMap->insert(p);
    }
  } catch (SQLException &e) {
    throw(std::runtime_error("MonPulseShapeDat::fetchData:  "+e.getMessage()));
  }
}
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.

    { 
      if (gain == 1) {
        return m_samplesG1;
      } else if (gain == 6) {
        return m_samplesG6;
      } else if (gain == 12) {
        return m_samplesG12;
      } else {
        throw(std::runtime_error("MonPulseShapeDat::getSamples:  Gain should be 1, 6 or 12"));
      }
    }
std::string MonPulseShapeDat::getTable ( ) [inline, virtual]

Implements IDataItem.

Definition at line 20 of file MonPulseShapeDat.h.

{ return "MON_PULSE_SHAPE_DAT"; }
void MonPulseShapeDat::prepareWrite ( ) throw (std::runtime_error) [private, virtual]

Implements IDataItem.

Definition at line 33 of file MonPulseShapeDat.cc.

References alignCSCRings::e.

{
  this->checkConnection();

  try {
    m_writeStmt = m_conn->createStatement();
    m_writeStmt->setSQL("INSERT INTO mon_pulse_shape_dat (iov_id, logic_id, "
                        "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, "
                        "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, "
                        "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) "
                        "VALUES (:iov_id, :logic_id, "
                        ":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,"
                        ":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,"
                        ":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)"
                        );
                        
  } catch (SQLException &e) {
    throw(std::runtime_error("MonPulseShapeDat::prepareWrite():  "+e.getMessage()));
  }
}
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().

    { 
      if (samples.size() != 10) {
        throw(std::runtime_error("MonPulseShapeDat::setSamples:  There should be 10 samples."));
      }

      if (gain == 1) {
        m_samplesG1 = samples; 
      } else if (gain == 6) {
        m_samplesG6 = samples;
      } else if (gain == 12) {
        m_samplesG12 = samples;
      } else {
        throw(std::runtime_error("MonPulseShapeDat::setSamples:  Gain should be 1, 6 or 12"));
      }
    }
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 alignCSCRings::e, exception, i, o2o::iov, and j.

{
  this->checkConnection();
  this->checkPrepare();

  int iovID = iov->fetchID();
  if (!iovID) { throw(std::runtime_error("MonPulseShapeDat::writeDB:  IOV not in DB")); }

  int logicID = ecid->getLogicID();
  if (!logicID) { throw(std::runtime_error("MonPulseShapeDat::writeDB:  Bad EcalLogicID")); }
  
  try {
    m_writeStmt->setInt(1, iovID);
    m_writeStmt->setInt(2, logicID);

    int gain[] = {1, 6, 12};
    std::vector<float> samples;
    for (int i=0; i<3; i++) {
      samples = item->getSamples(gain[i]);
      for (int j=0; j<10; j++) {
        m_writeStmt->setFloat(3+(10*i)+j, samples.at(j));
      }
    }

    m_writeStmt->executeUpdate();
  } catch (SQLException &e) {
    throw(std::runtime_error("MonPulseShapeDat::writeDB:  "+e.getMessage()));
  } catch (exception &e) {
    throw(std::runtime_error("MonPulseShapeDat::writeDB:  " + string(e.what())));
  }
}

Friends And Related Function Documentation

friend class EcalCondDBInterface [friend]

Reimplemented from IDBObject.

Definition at line 15 of file MonPulseShapeDat.h.


Member Data Documentation

std::vector<float> MonPulseShapeDat::m_samplesG1 [private]

Definition at line 65 of file MonPulseShapeDat.h.

Referenced by getSamples(), and setSamples().

std::vector<float> MonPulseShapeDat::m_samplesG12 [private]

Definition at line 67 of file MonPulseShapeDat.h.

Referenced by getSamples(), and setSamples().

std::vector<float> MonPulseShapeDat::m_samplesG6 [private]

Definition at line 66 of file MonPulseShapeDat.h.

Referenced by getSamples(), and setSamples().