CMS 3D CMS Logo

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

LocationDef Class Reference

#include <LocationDef.h>

Inheritance diagram for LocationDef:
IDef IUniqueDBObject IDBObject

List of all members.

Public Member Functions

int fetchID () throw (std::runtime_error)
std::string getLocation () const
 LocationDef ()
bool operator!= (const LocationDef &l) const
bool operator== (const LocationDef &l) const
void setByID (int id) throw (std::runtime_error)
void setLocation (std::string loc)
virtual ~LocationDef ()

Protected Member Functions

void fetchAllDefs (std::vector< LocationDef > *fillVec) throw (std::runtime_error)

Protected Attributes

std::string m_loc

Friends

class EcalCondDBInterface

Detailed Description

Def for Location information

Definition at line 12 of file LocationDef.h.


Constructor & Destructor Documentation

LocationDef::LocationDef ( )

Definition at line 10 of file LocationDef.cc.

References NULL.

{
  m_env = NULL;
  m_conn = NULL;
  m_ID = 0;
  m_loc = "";
}
LocationDef::~LocationDef ( ) [virtual]

Definition at line 20 of file LocationDef.cc.

{
}

Member Function Documentation

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

Definition at line 103 of file LocationDef.cc.

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

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

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

Implements IUniqueDBObject.

Definition at line 43 of file LocationDef.cc.

References alignCSCRings::e.

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

  this->checkConnection();
  
  try {
    Statement* stmt = m_conn->createStatement();
    stmt->setSQL("SELECT def_id FROM location_def WHERE "
                 "location = :location");
    stmt->setString(1, m_loc);

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

  return m_ID;
}
string LocationDef::getLocation ( ) const

Definition at line 26 of file LocationDef.cc.

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

{
  return m_loc;
}
bool LocationDef::operator!= ( const LocationDef l) const [inline]

Definition at line 28 of file LocationDef.h.

References m_loc.

{ return m_loc != l.m_loc; }
bool LocationDef::operator== ( const LocationDef l) const [inline]

Definition at line 27 of file LocationDef.h.

References m_loc.

{ return m_loc == l.m_loc; }
void LocationDef::setByID ( int  id) throw (std::runtime_error) [virtual]

Implements IUniqueDBObject.

Definition at line 76 of file LocationDef.cc.

References alignCSCRings::e, and errorMatrix2Lands_multiChannel::id.

Referenced by fetchAllDefs().

{
  this->checkConnection();

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

    stmt->setSQL("SELECT location FROM location_def WHERE def_id = :1");
    stmt->setInt(1, id);

    ResultSet* rset = stmt->executeQuery();
    if (rset->next()) {
      m_loc = rset->getString(1);
      m_ID = id;
    } else {
      throw(std::runtime_error("LocationDef::setByID:  Given def_id is not in the database"));
    }
    
    m_conn->terminateStatement(stmt);
  } catch (SQLException &e) {
   throw(std::runtime_error("LocationDef::setByID:  "+e.getMessage()));
  }
}
void LocationDef::setLocation ( std::string  loc)

Friends And Related Function Documentation

friend class EcalCondDBInterface [friend]

Reimplemented from IDBObject.

Definition at line 14 of file LocationDef.h.


Member Data Documentation

std::string LocationDef::m_loc [protected]

Definition at line 32 of file LocationDef.h.

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