CMS 3D CMS Logo

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

ODFEDelaysInfo Class Reference

#include <ODFEDelaysInfo.h>

Inheritance diagram for ODFEDelaysInfo:
IODConfig IDBObject

List of all members.

Public Member Functions

int fetchID () throw (std::runtime_error)
int fetchNextId () throw (std::runtime_error)
int getId () const
std::string getTable ()
int getVersion () const
 ODFEDelaysInfo ()
void setId (int id)
void setParameters (std::map< std::string, std::string > my_keys_map)
void setVersion (int id)
 ~ODFEDelaysInfo ()

Private Member Functions

void clear ()
void fetchData (ODFEDelaysInfo *result) throw (std::runtime_error)
void prepareWrite () throw (std::runtime_error)
void writeDB () throw (std::runtime_error)

Private Attributes

int m_ID
int m_version

Friends

class EcalCondDBInterface

Detailed Description

Definition at line 9 of file ODFEDelaysInfo.h.


Constructor & Destructor Documentation

ODFEDelaysInfo::ODFEDelaysInfo ( )

Definition at line 12 of file ODFEDelaysInfo.cc.

References hitfit::clear(), and NULL.

ODFEDelaysInfo::~ODFEDelaysInfo ( )

Definition at line 31 of file ODFEDelaysInfo.cc.

{
}

Member Function Documentation

void ODFEDelaysInfo::clear ( void  ) [private]

Definition at line 25 of file ODFEDelaysInfo.cc.

                          {

}
void ODFEDelaysInfo::fetchData ( ODFEDelaysInfo result) throw (std::runtime_error) [private]

Definition at line 131 of file ODFEDelaysInfo.cc.

References alignCSCRings::e, and query::result.

{

  this->checkConnection();

  result->clear();
  if(result->getId()==0 && (result->getConfigTag()=="") ){
    throw(std::runtime_error("ODFEDelaysInfo::fetchData(): no Id defined for this ODFEDelaysInfo "));
  }

  try {
    if(result->getId()!=0) { 
      m_readStmt->setSQL("SELECT * FROM " + getTable() +   
                         " where  rec_id = :1 ");
      m_readStmt->setInt(1, result->getId());
    } else if (result->getConfigTag()!="") {
      m_readStmt->setSQL("SELECT * FROM " + getTable() +   
                         " where  tag=:1 AND version=:2 " );
      m_readStmt->setString(1, result->getConfigTag());
      m_readStmt->setInt(2, result->getVersion());
    } else {
      // we should never pass here 
      throw(std::runtime_error("ODFEDelaysInfo::fetchData(): no Id defined for this ODFEDelaysInfo "));
    }

    ResultSet* rset = m_readStmt->executeQuery();
    rset->next();

    // 1 is the id and 2 is the config tag and 3 is the version

    result->setId(rset->getInt(1));
    result->setConfigTag(rset->getString(2));
    result->setVersion(rset->getInt(3));

  } catch (SQLException &e) {
    throw(std::runtime_error("ODFEDelaysInfo::fetchData():  "+e.getMessage()));
  }
}
int ODFEDelaysInfo::fetchID ( ) throw (std::runtime_error)

Definition at line 171 of file ODFEDelaysInfo.cc.

References alignCSCRings::e.

{
  // Return from memory if available
  if (m_ID!=0) {
    return m_ID;
  }

  this->checkConnection();

  try {
    Statement* stmt = m_conn->createStatement();
    stmt->setSQL("SELECT rec_id FROM "+ getTable()+
                 "WHERE  tag=:1 and version=:2 " );

    stmt->setString(1, getConfigTag() );
    stmt->setInt(2, getVersion() );

    ResultSet* rset = stmt->executeQuery();

    if (rset->next()) {
      m_ID = rset->getInt(1);
    } else {
      m_ID = 0;
    }
    m_conn->terminateStatement(stmt);
  } catch (SQLException &e) {
    throw(std::runtime_error("ODFEDelaysInfo::fetchID:  "+e.getMessage()));
  }

  return m_ID;
}
int ODFEDelaysInfo::fetchNextId ( ) throw (std::runtime_error)

Definition at line 37 of file ODFEDelaysInfo.cc.

References gather_cfg::cout, alignCSCRings::e, and query::result.

                                                         {

  int result=0;
  try {
    this->checkConnection();

    m_readStmt = m_conn->createStatement(); 
    m_readStmt->setSQL("select COND2CONF_INFO_SQ.NextVal from DUAL ");
    ResultSet* rset = m_readStmt->executeQuery();
    while (rset->next ()){
      result= rset->getInt(1);
    }
    result++;
    m_conn->terminateStatement(m_readStmt);
    std::cout << " the id is going to be : "<< result<< endl;
    return result; 

  } catch (SQLException &e) {
    throw(std::runtime_error("ODFEDelaysInfo::fetchNextId():  "+e.getMessage()));
  }

}
int ODFEDelaysInfo::getId ( ) const [inline]

Definition at line 19 of file ODFEDelaysInfo.h.

References m_ID.

{ return m_ID; }
std::string ODFEDelaysInfo::getTable ( ) [inline, virtual]

Implements IODConfig.

Definition at line 16 of file ODFEDelaysInfo.h.

{ return "DELAYS_INFO"; }
int ODFEDelaysInfo::getVersion ( ) const [inline]

Definition at line 24 of file ODFEDelaysInfo.h.

References m_version.

{ return m_version; }
void ODFEDelaysInfo::prepareWrite ( ) throw (std::runtime_error) [private, virtual]

Implements IODConfig.

Definition at line 60 of file ODFEDelaysInfo.cc.

References alignCSCRings::e, and getId().

{
  this->checkConnection();

  int next_id=0;
  if(getId()==0){
    next_id=fetchNextId();
  } 

  try {
    m_writeStmt = m_conn->createStatement();
    m_writeStmt->setSQL("INSERT INTO "+getTable()+" ( rec_id, tag, version) " 
                        " VALUES ( :1, :2, :3 ) " );

    m_writeStmt->setInt(1, next_id);
    m_ID=next_id;

  } catch (SQLException &e) {
    throw(std::runtime_error("ODFEDelaysInfo::prepareWrite():  "+e.getMessage()));
  }

}
void ODFEDelaysInfo::setId ( int  id) [inline]

Definition at line 18 of file ODFEDelaysInfo.h.

References errorMatrix2Lands_multiChannel::id, and m_ID.

{ m_ID = id; }
void ODFEDelaysInfo::setParameters ( std::map< std::string, std::string >  my_keys_map)
void ODFEDelaysInfo::setVersion ( int  id) [inline]

Definition at line 23 of file ODFEDelaysInfo.h.

References errorMatrix2Lands_multiChannel::id, and m_version.

{ m_version = id; }
void ODFEDelaysInfo::writeDB ( ) throw (std::runtime_error) [private]

Definition at line 99 of file ODFEDelaysInfo.cc.

References gather_cfg::cout, and alignCSCRings::e.

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

  try {

    // number 1 is the id 
    m_writeStmt->setString(2, this->getConfigTag());
    m_writeStmt->setInt(3, this->getVersion());

    m_writeStmt->executeUpdate();


  } catch (SQLException &e) {
    throw(std::runtime_error("ODFEDelaysInfo::writeDB():  "+e.getMessage()));
  }

  // Now get the ID
  if (!this->fetchID()) {
    throw(std::runtime_error("ODFEDelaysInfo::writeDB:  Failed to write"));
  } else {
    int old_version=this->getVersion();
    m_readStmt = m_conn->createStatement(); 
    this->fetchData (this);
    m_conn->terminateStatement(m_readStmt);
    if(this->getVersion()!=old_version) std::cout << "ODFEDelaysInfo>>WARNING version is "<< getVersion()<< endl; 
  }
}

Friends And Related Function Documentation

friend class EcalCondDBInterface [friend]

Reimplemented from IDBObject.

Definition at line 11 of file ODFEDelaysInfo.h.


Member Data Documentation

int ODFEDelaysInfo::m_ID [private]

Definition at line 42 of file ODFEDelaysInfo.h.

Referenced by getId(), and setId().

Definition at line 43 of file ODFEDelaysInfo.h.

Referenced by getVersion(), and setVersion().