CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Protected Attributes | Friends

RunSeqDef Class Reference

#include <RunSeqDef.h>

Inheritance diagram for RunSeqDef:
IDef IUniqueDBObject IDBObject

List of all members.

Public Member Functions

int fetchID () throw (std::runtime_error)
std::string getRunSeq () const
RunTypeDef getRunTypeDef () const
bool operator!= (const RunSeqDef &t) const
bool operator== (const RunSeqDef &t) const
 RunSeqDef ()
void setByID (int id) throw (std::runtime_error)
void setRunSeq (std::string runseq)
void setRunTypeDef (const RunTypeDef runTypeDef)
virtual ~RunSeqDef ()

Protected Member Functions

void fetchAllDefs (std::vector< RunSeqDef > *fillVec) throw (std::runtime_error)
int writeDB () throw (std::runtime_error)

Protected Attributes

std::string m_runSeq
RunTypeDef m_runType

Friends

class EcalCondDBInterface
class ODRunConfigSeqInfo

Detailed Description

Def for Location information

Definition at line 13 of file RunSeqDef.h.


Constructor & Destructor Documentation

RunSeqDef::RunSeqDef ( )

Definition at line 9 of file RunSeqDef.cc.

References NULL.

{
  m_env = NULL;
  m_conn = NULL;
  m_ID = 0;
  m_runSeq = "";
  m_runType = RunTypeDef();
}
RunSeqDef::~RunSeqDef ( ) [virtual]

Definition at line 20 of file RunSeqDef.cc.

{
}

Member Function Documentation

void RunSeqDef::fetchAllDefs ( std::vector< RunSeqDef > *  fillVec) throw (std::runtime_error) [protected]

Definition at line 118 of file RunSeqDef.cc.

References setByID(), and IDBObject::setConnection().

{
  this->checkConnection();
  try {
    Statement* stmt = m_conn->createStatement();
    stmt->setSQL("SELECT def_id FROM ecal_sequence_type_def ORDER BY def_id");
    ResultSet* rset = stmt->executeQuery();
    
    RunSeqDef runSeqDef;
    runSeqDef.setConnection(m_env, m_conn);

    while(rset->next()) {
      runSeqDef.setByID( rset->getInt(1) );
      fillVec->push_back( runSeqDef );
    }
  } catch (SQLException &e) {
    throw(std::runtime_error("RunSeqDef::fetchAllDefs:  "+e.getMessage()));
  }
}
int RunSeqDef::fetchID ( ) throw (std::runtime_error) [virtual]

Implements IUniqueDBObject.

Definition at line 44 of file RunSeqDef.cc.

{
  // Return def from memory if available
  if (m_ID) {
    return m_ID;
  }

  this->checkConnection();
  

  // get the run type
  m_runType.setConnection(m_env, m_conn);
  int run_type_id = m_runType.fetchID();


  try {
    Statement* stmt = m_conn->createStatement();
    stmt->setSQL("SELECT def_id FROM ecal_sequence_type_def WHERE "
                 " run_type_def_id   = :1 and sequence_type_string = :2 "
                 );

    stmt->setInt(1, run_type_id);
    stmt->setString(2, m_runSeq);

    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("RunSeqDef::fetchID:  "+e.getMessage()));
  }

  return m_ID;
}
string RunSeqDef::getRunSeq ( ) const

Definition at line 26 of file RunSeqDef.cc.

{  return m_runSeq;}
RunTypeDef RunSeqDef::getRunTypeDef ( ) const

Definition at line 32 of file RunSeqDef.cc.

{
  return m_runType;
}
bool RunSeqDef::operator!= ( const RunSeqDef t) const [inline]

Definition at line 38 of file RunSeqDef.h.

References m_runSeq.

{ return m_runSeq != t.m_runSeq; }
bool RunSeqDef::operator== ( const RunSeqDef t) const [inline]

Definition at line 37 of file RunSeqDef.h.

References m_runSeq.

{ return m_runSeq == t.m_runSeq; }
void RunSeqDef::setByID ( int  id) throw (std::runtime_error) [virtual]

Implements IUniqueDBObject.

Definition at line 86 of file RunSeqDef.cc.

Referenced by fetchAllDefs().

{
  this->checkConnection();

  try {
    Statement* stmt = m_conn->createStatement();

    stmt->setSQL("SELECT run_type_def_id, sequence_type_string FROM ecal_sequence_type_def WHERE def_id = :1");
    stmt->setInt(1, id);
    
    int idruntype=0;
    ResultSet* rset = stmt->executeQuery();
    if (rset->next()) {
      idruntype = rset->getInt(1);
      m_runSeq = rset->getString(2);
    } else {
      throw(std::runtime_error("RunSeqDef::setByID:  Given def_id is not in the database"));
    }

    m_conn->terminateStatement(stmt);

    m_runType.setConnection(m_env, m_conn);
    m_runType.setByID(idruntype);

  } catch (SQLException &e) {
   throw(std::runtime_error("RunSeqDef::setByID:  "+e.getMessage()));
  }
}
void RunSeqDef::setRunSeq ( std::string  runseq)

Definition at line 30 of file RunSeqDef.cc.

{    m_runSeq = runseq;}
void RunSeqDef::setRunTypeDef ( const RunTypeDef  runTypeDef)

Definition at line 37 of file RunSeqDef.cc.

{
    m_runType = runTypeDef;
}
int RunSeqDef::writeDB ( ) throw (std::runtime_error) [protected]

Definition at line 139 of file RunSeqDef.cc.

{
  // see if this data is already in the DB
  try {
    if (this->fetchID()) { 
      return m_ID; 
    }
  } catch (SQLException &e) {
    // it does not exist yet 
  }

  // check the connectioin
  this->checkConnection();

  // get the run type
  m_runType.setConnection(m_env, m_conn);
  int run_type_id = m_runType.fetchID();

  // write new seq def to the DB
  try {
    Statement* stmt = m_conn->createStatement();

    stmt->setSQL("insert into ecal_sequence_type_def(RUN_TYPE_DEF_ID, SEQUENCE_TYPE_STRING) values "
                 " ( :1, :2 )");
    stmt->setInt(1, run_type_id);
    stmt->setString(2, m_runSeq);
   

    stmt->executeUpdate();
    
    m_conn->terminateStatement(stmt);
  } catch (SQLException &e) {
   throw(std::runtime_error("RunSeqDef::writeDB:  "+e.getMessage()));
  }

  // now get the tag_id
  if (!this->fetchID()) {
    throw(std::runtime_error("RunSeqDef::writeDB:  Failed to write"));
  }

  return m_ID;
}

Friends And Related Function Documentation

friend class EcalCondDBInterface [friend]

Reimplemented from IDBObject.

Definition at line 16 of file RunSeqDef.h.

friend class ODRunConfigSeqInfo [friend]

Definition at line 15 of file RunSeqDef.h.


Member Data Documentation

std::string RunSeqDef::m_runSeq [protected]

Definition at line 42 of file RunSeqDef.h.

Referenced by operator!=(), and operator==().

Definition at line 43 of file RunSeqDef.h.