CMS 3D CMS Logo

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

DCUIOV Class Reference

#include <DCUIOV.h>

Inheritance diagram for DCUIOV:
IIOV IUniqueDBObject IDBObject

List of all members.

Public Member Functions

 DCUIOV ()
int fetchID () throw (std::runtime_error)
DCUTag getDCUTag () const
int getID ()
Tm getSince () const
Tm getTill () const
bool operator!= (const DCUIOV &m) const
bool operator== (const DCUIOV &m) const
void setByID (int id) throw (std::runtime_error)
void setDCUTag (DCUTag tag)
void setSince (Tm since)
void setTill (Tm till)
 ~DCUIOV ()

Private Member Functions

void setByTm (DCUTag *tag, Tm time) throw (std::runtime_error)
int writeDB () throw (std::runtime_error)

Private Attributes

DCUTag m_dcuTag
Tm m_since
Tm m_till

Friends

class EcalCondDBInterface

Detailed Description

Definition at line 13 of file DCUIOV.h.


Constructor & Destructor Documentation

DCUIOV::DCUIOV ( )

Definition at line 12 of file DCUIOV.cc.

References NULL.

{
  m_conn = NULL;
  m_ID = 0;
  m_since = Tm();
  m_till = Tm();
}
DCUIOV::~DCUIOV ( )

Definition at line 22 of file DCUIOV.cc.

{
}

Member Function Documentation

int DCUIOV::fetchID ( ) throw (std::runtime_error) [virtual]

Implements IUniqueDBObject.

Definition at line 79 of file DCUIOV.cc.

References DateHandler::getPlusInfTm(), and DateHandler::tmToDate().

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

  this->checkConnection();

  m_dcuTag.setConnection(m_env, m_conn);
  int tagID = m_dcuTag.fetchID();
  if (!tagID) { 
    return 0;
  }

  DateHandler dh(m_env, m_conn);

  if (m_till.isNull()) {
    m_till = dh.getPlusInfTm();
  }

  try {
    Statement* stmt = m_conn->createStatement();
    stmt->setSQL("SELECT iov_id FROM dcu_iov "
                 "WHERE tag_id = :tag_id AND "
                 "since = :since ");
    stmt->setInt(1, tagID);
    stmt->setDate(2, dh.tmToDate(m_since));
    //    stmt->setDate(3, dh.tmToDate(m_till));
  
    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("DCUIOV::fetchID:  "+e.getMessage()));
  }

  return m_ID;
}
DCUTag DCUIOV::getDCUTag ( ) const

Definition at line 72 of file DCUIOV.cc.

{
  return m_dcuTag;
}
int DCUIOV::getID ( ) [inline]

Definition at line 29 of file DCUIOV.h.

References IUniqueDBObject::m_ID.

{ return m_ID;} ;
Tm DCUIOV::getSince ( ) const

Definition at line 38 of file DCUIOV.cc.

{
  return m_since;
}
Tm DCUIOV::getTill ( ) const

Definition at line 55 of file DCUIOV.cc.

{
  return m_till;
}
bool DCUIOV::operator!= ( const DCUIOV m) const [inline]

Definition at line 41 of file DCUIOV.h.

References m.

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

Definition at line 34 of file DCUIOV.h.

References m_dcuTag, m_since, and m_till.

    {
      return ( m_dcuTag   == m.m_dcuTag &&
               m_since == m.m_since &&
               m_till   == m.m_till );
    }
void DCUIOV::setByID ( int  id) throw (std::runtime_error) [virtual]

Implements IUniqueDBObject.

Definition at line 127 of file DCUIOV.cc.

References DateHandler::dateToTm().

{
   this->checkConnection();

   DateHandler dh(m_env, m_conn);

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

     stmt->setSQL("SELECT tag_id, since, till FROM dcu_iov WHERE iov_id = :1");
     stmt->setInt(1, id);
     
     ResultSet* rset = stmt->executeQuery();
     if (rset->next()) {
       int tagID = rset->getInt(1);
       Date since = rset->getDate(2);
       Date till = rset->getDate(3);
         
       m_since = dh.dateToTm( since );
       m_till = dh.dateToTm( till );

       m_dcuTag.setConnection(m_env, m_conn);
       m_dcuTag.setByID(tagID);
       m_ID = id;
     } else {
       throw(std::runtime_error("DCUTag::setByID:  Given tag_id is not in the database"));
     }
     
     m_conn->terminateStatement(stmt);
   } catch (SQLException &e) {
     throw(std::runtime_error("DCUTag::setByID:  "+e.getMessage()));
   }
}
void DCUIOV::setByTm ( DCUTag tag,
Tm  time 
) throw (std::runtime_error) [private]

Definition at line 214 of file DCUIOV.cc.

References DateHandler::dateToTm(), GlobalPosition_Frontier_DevDB_cff::tag, and DateHandler::tmToDate().

Referenced by EcalCondDBInterface::fetchDCUIOV().

{
  this->checkConnection();
  
  tag->setConnection(m_env, m_conn);
  int tagID = tag->fetchID();
  
  if (!tagID) {
    throw(std::runtime_error("DCUIOV::setByTm:  Given DCUTag does not exist in the DB"));
  }

  DateHandler dh(m_env, m_conn);

  Date eventDate = dh.tmToDate(eventTm);

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


    stmt->setSQL("SELECT iov_id, since, till FROM dcu_iov "
                 "WHERE tag_id = :1 AND since <= :2 AND till > :3");
    stmt->setInt(1, tagID);
    stmt->setDate(2, eventDate);
    stmt->setDate(3, eventDate);

    ResultSet* rset = stmt->executeQuery();
    if (rset->next()) {
      m_dcuTag = *tag;
      
      m_ID = rset->getInt(1);
      Date sinceDate = rset->getDate(2);
      Date tillDate = rset->getDate(3);
         
      m_since = dh.dateToTm( sinceDate );
      m_till = dh.dateToTm( tillDate );
    } else {
      throw(std::runtime_error("DCUIOV::setByTm:  Given subrun is not in the database"));
    }
     
    m_conn->terminateStatement(stmt);
  } catch (SQLException &e) {
    throw(std::runtime_error("DCUIOV::setByTm:  "+e.getMessage()));
  }
}
void DCUIOV::setDCUTag ( DCUTag  tag)

Definition at line 62 of file DCUIOV.cc.

References GlobalPosition_Frontier_DevDB_cff::tag.

{
  if (tag != m_dcuTag) {
    m_ID = 0;
    m_dcuTag = tag;
  }
}
void DCUIOV::setSince ( Tm  since)

Definition at line 28 of file DCUIOV.cc.

{
  if (since != m_since) {
    m_ID = 0;
    m_since = since;
  }
}
void DCUIOV::setTill ( Tm  till)

Definition at line 45 of file DCUIOV.cc.

{
  if (till != m_till) {
    m_ID = 0;
    m_till = till;
  }
}
int DCUIOV::writeDB ( ) throw (std::runtime_error) [private]

Definition at line 164 of file DCUIOV.cc.

References DateHandler::getPlusInfTm(), and DateHandler::tmToDate().

{
  this->checkConnection();

  // Check if this IOV has already been written
  if (this->fetchID()) {
    return m_ID;
  }

  m_dcuTag.setConnection(m_env, m_conn);
  int tagID = m_dcuTag.writeDB();
  
  // Validate the data, use infinity-till convention
  DateHandler dh(m_env, m_conn);

  if (m_since.isNull()) {
    throw(std::runtime_error("DCUIOV::writeDB:  Must setSince before writing"));
  }
  
  if (m_till.isNull()) {
    m_till = dh.getPlusInfTm();
  }

  try {
    Statement* stmt = m_conn->createStatement();
    
    stmt->setSQL("INSERT INTO dcu_iov (iov_id, tag_id, since, till) "
                 "VALUES (dcu_iov_sq.NextVal, :1, :2, :3)");
    stmt->setInt(1, tagID);
    stmt->setDate(2, dh.tmToDate(m_since));
    stmt->setDate(3, dh.tmToDate(m_till));

    stmt->executeUpdate();

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

  // Now get the ID
  if (!this->fetchID()) {
    throw(std::runtime_error("DCUIOV::writeDB:  Failed to write"));
  }
  
  return m_ID;
}

Friends And Related Function Documentation

friend class EcalCondDBInterface [friend]

Reimplemented from IDBObject.

Definition at line 15 of file DCUIOV.h.


Member Data Documentation

Definition at line 48 of file DCUIOV.h.

Referenced by operator==().

Tm DCUIOV::m_since [private]

Definition at line 46 of file DCUIOV.h.

Referenced by operator==().

Tm DCUIOV::m_till [private]

Definition at line 47 of file DCUIOV.h.

Referenced by operator==().