CMS 3D CMS Logo

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

RunTag Class Reference

#include <RunTag.h>

Inheritance diagram for RunTag:
ITag IUniqueDBObject IDBObject

List of all members.

Public Member Functions

int fetchID () throw (std::runtime_error)
std::string getGeneralTag () const
LocationDef getLocationDef () const
RunTypeDef getRunTypeDef () const
bool operator!= (const RunTag &t) const
bool operator== (const RunTag &t) const
 RunTag ()
void setByID (int id) throw (std::runtime_error)
void setGeneralTag (std::string tag)
void setLocationDef (const LocationDef locDef)
void setRunTypeDef (const RunTypeDef runTypeDef)
 ~RunTag ()

Private Member Functions

void fetchAllTags (std::vector< RunTag > *fillVec) throw (std::runtime_error)
void fetchParentIDs (int *locId, int *runTypeID) throw (std::runtime_error)
int writeDB () throw (std::runtime_error)

Private Attributes

std::string m_genTag
LocationDef m_locDef
RunTypeDef m_runTypeDef

Friends

class EcalCondDBInterface
class RunIOV

Detailed Description

Tag for Run information

Definition at line 13 of file RunTag.h.


Constructor & Destructor Documentation

RunTag::RunTag ( )

Definition at line 9 of file RunTag.cc.

References NULL.

{
  m_env = NULL;
  m_conn = NULL;
  m_ID = 0;
  m_genTag = "default";
  m_locDef = LocationDef();
  m_runTypeDef = RunTypeDef();
}
RunTag::~RunTag ( )

Definition at line 21 of file RunTag.cc.

{
}

Member Function Documentation

void RunTag::fetchAllTags ( std::vector< RunTag > *  fillVec) throw (std::runtime_error) [private]

Definition at line 204 of file RunTag.cc.

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

{
  this->checkConnection();
  try {
    Statement* stmt = m_conn->createStatement();
    stmt->setSQL("SELECT tag_id FROM run_tag ORDER BY tag_id");
    ResultSet* rset = stmt->executeQuery();
    
    RunTag runtag;
    runtag.setConnection(m_env, m_conn);
    while(rset->next()) {
      runtag.setByID( rset->getInt(1) );
      fillVec->push_back( runtag );
    }
    m_conn->terminateStatement(stmt);
  } catch (SQLException &e) {
    throw(std::runtime_error("RunTag::fetchAllTags:  "+e.getMessage()));
  }
}
int RunTag::fetchID ( ) throw (std::runtime_error) [virtual]

Implements IUniqueDBObject.

Definition at line 80 of file RunTag.cc.

{



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

  
  this->checkConnection();


  // fetch the parent IDs
  int locID, runTypeID;
  this->fetchParentIDs(&locID, &runTypeID);
  
  // fetch this ID
  try {
    Statement* stmt = m_conn->createStatement();
    stmt->setSQL("SELECT tag_id FROM run_tag WHERE "
                 "gen_tag     = :1 AND "
                 "location_id = :2 AND "
                 "run_type_id = :3");
    stmt->setString(1, m_genTag);
    stmt->setInt(2, locID);
    stmt->setInt(3, runTypeID);

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

  return m_ID;
}
void RunTag::fetchParentIDs ( int *  locId,
int *  runTypeID 
) throw (std::runtime_error) [private]

Definition at line 227 of file RunTag.cc.

{
  // get the location
  m_locDef.setConnection(m_env, m_conn);
  *locID = m_locDef.fetchID();

  // get the run type
  m_runTypeDef.setConnection(m_env, m_conn);
  *runTypeID = m_runTypeDef.fetchID();
  


  if (! *locID) { 
    throw(std::runtime_error("RunTag::fetchparentids:  Given location does not exist in DB")); 
  }

  if (! *runTypeID) { 
    throw(std::runtime_error("RunTag::fetchParentIDs:  Given run type does not exist in DB")); 
  }
}
string RunTag::getGeneralTag ( ) const

Definition at line 27 of file RunTag.cc.

Referenced by EcalTPGDBApp::printTag().

{
  return m_genTag;
}
LocationDef RunTag::getLocationDef ( ) const

Definition at line 46 of file RunTag.cc.

Referenced by EcalTPGDBApp::printTag(), and EcalErrorMask::readDB().

{
  return m_locDef;
}
RunTypeDef RunTag::getRunTypeDef ( ) const

Definition at line 63 of file RunTag.cc.

Referenced by EcalTPGDBApp::printTag().

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

Definition at line 43 of file RunTag.h.

References matplotRender::t.

{ return !(*this == t); }
bool RunTag::operator== ( const RunTag t) const [inline]

Definition at line 36 of file RunTag.h.

References m_genTag, m_locDef, and m_runTypeDef.

    {
      return (m_genTag == t.m_genTag &&
              m_locDef == t.m_locDef &&
              m_runTypeDef == t.m_runTypeDef);
    }
void RunTag::setByID ( int  id) throw (std::runtime_error) [virtual]

Implements IUniqueDBObject.

Definition at line 127 of file RunTag.cc.

Referenced by fetchAllTags().

{
  this->checkConnection();

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

    stmt->setSQL("SELECT gen_tag, location_id, run_type_id FROM run_tag WHERE tag_id = :1");
    stmt->setInt(1, id);

    ResultSet* rset = stmt->executeQuery();
    if (rset->next()) {
      m_genTag = rset->getString(1);
      int locID = rset->getInt(2);
      int runTypeID = rset->getInt(3);

      m_locDef.setConnection(m_env, m_conn);
      m_locDef.setByID(locID);

      m_runTypeDef.setConnection(m_env, m_conn);
      m_runTypeDef.setByID(runTypeID);

      m_ID = id;
    } else {
      throw(std::runtime_error("RunTag::setByID:  Given tag_id is not in the database"));
    }

    m_conn->terminateStatement(stmt);
  } catch (SQLException &e) {
   throw(std::runtime_error("RunTag::setByID:  "+e.getMessage()));
  }
}
void RunTag::setGeneralTag ( std::string  tag)
void RunTag::setLocationDef ( const LocationDef  locDef)
void RunTag::setRunTypeDef ( const RunTypeDef  runTypeDef)
int RunTag::writeDB ( ) throw (std::runtime_error) [private]

Definition at line 162 of file RunTag.cc.

{
  // see if this data is already in the DB
  if (this->fetchID()) { 
    return m_ID; 
  }

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

  // fetch the parent IDs
  int locID, runTypeID;
  this->fetchParentIDs(&locID, &runTypeID);

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

    stmt->setSQL("INSERT INTO run_tag (tag_id, gen_tag, location_id, run_type_id) "
                 "VALUES (run_tag_sq.NextVal, :1, :2, :3)");
    stmt->setString(1, m_genTag);
    stmt->setInt(2, locID);
    stmt->setInt(3, runTypeID);

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

  // now get the tag_id
  if (!this->fetchID()) {
    throw(std::runtime_error("RunTag::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 RunTag.h.

friend class RunIOV [friend]

Definition at line 15 of file RunTag.h.


Member Data Documentation

std::string RunTag::m_genTag [private]

Definition at line 47 of file RunTag.h.

Referenced by operator==().

Definition at line 48 of file RunTag.h.

Referenced by operator==().

Definition at line 49 of file RunTag.h.

Referenced by operator==().