CMS 3D CMS Logo

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

MODRunIOV Class Reference

#include <MODRunIOV.h>

Inheritance diagram for MODRunIOV:
IIOV IUniqueDBObject IDBObject

List of all members.

Public Member Functions

int fetchID () throw (std::runtime_error)
int getID ()
RunIOV getRunIOV ()
Tm getSubRunEnd () const
run_t getSubRunNumber () const
Tm getSubRunStart () const
 MODRunIOV ()
bool operator!= (const MODRunIOV &m) const
bool operator== (const MODRunIOV &m) const
void setByID (int id) throw (std::runtime_error)
void setID (int id)
void setRunIOV (RunIOV iov)
void setSubRunEnd (Tm end)
void setSubRunNumber (subrun_t subrun)
void setSubRunStart (Tm start)
 ~MODRunIOV ()

Private Member Functions

void fetchParentIDs (int *runIOVID) throw (std::runtime_error)
void setByRun (RunIOV *runiov, subrun_t subrun) throw (std::runtime_error)
int writeDB () throw (std::runtime_error)

Private Attributes

RunIOV m_runIOV
Tm m_subRunEnd
subrun_t m_subRunNum
Tm m_subRunStart

Friends

class EcalCondDBInterface

Detailed Description

Definition at line 13 of file MODRunIOV.h.


Constructor & Destructor Documentation

MODRunIOV::MODRunIOV ( )

Definition at line 12 of file MODRunIOV.cc.

References NULL.

MODRunIOV::~MODRunIOV ( )

Definition at line 24 of file MODRunIOV.cc.

{
}

Member Function Documentation

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

Implements IUniqueDBObject.

Definition at line 101 of file MODRunIOV.cc.

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

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

  this->checkConnection();

  // fetch the parent IDs
  int  runIOVID;
  this->fetchParentIDs(&runIOVID);

  if (!runIOVID) { 
    return 0;
  }

  DateHandler dh(m_env, m_conn);

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

  try {
    Statement* stmt = m_conn->createStatement();
    stmt->setSQL("SELECT iov_id FROM OD_run_iov "
                 "WHERE "
                 "run_iov_id   = :1 AND "
                 "subrun_num   = :2 AND "
                 "subrun_start = :3 AND "
                 "subrun_end   = :4");

    stmt->setInt(1, runIOVID);
    stmt->setInt(2, m_subRunNum);
    stmt->setDate(3, dh.tmToDate(m_subRunStart));
    stmt->setDate(4, dh.tmToDate(m_subRunEnd));
  
    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("MODRunIOV::fetchID:  "+e.getMessage()));
  }

  return m_ID;
}
void MODRunIOV::fetchParentIDs ( int *  runIOVID) throw (std::runtime_error) [private]

Definition at line 247 of file MODRunIOV.cc.

{
  // get the RunIOV
  m_runIOV.setConnection(m_env, m_conn);
  *runIOVID = m_runIOV.fetchID();

  if (! *runIOVID) { 
    throw(std::runtime_error("MODRunIOV:  Given RunIOV does not exist in DB")); 
  }

}
int MODRunIOV::getID ( ) [inline]

Definition at line 21 of file MODRunIOV.h.

References IUniqueDBObject::m_ID.

{ return m_ID;} ;
RunIOV MODRunIOV::getRunIOV ( )

Definition at line 44 of file MODRunIOV.cc.

{ 
  return m_runIOV;
}
Tm MODRunIOV::getSubRunEnd ( ) const

Definition at line 94 of file MODRunIOV.cc.

{
  return m_subRunEnd;
}
run_t MODRunIOV::getSubRunNumber ( ) const

Definition at line 60 of file MODRunIOV.cc.

{
  return m_subRunNum;
}
Tm MODRunIOV::getSubRunStart ( ) const

Definition at line 77 of file MODRunIOV.cc.

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

Definition at line 46 of file MODRunIOV.h.

References m.

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

Definition at line 38 of file MODRunIOV.h.

References m_runIOV, m_subRunEnd, m_subRunNum, and m_subRunStart.

void MODRunIOV::setByID ( int  id) throw (std::runtime_error) [virtual]

Implements IUniqueDBObject.

Definition at line 156 of file MODRunIOV.cc.

References DateHandler::dateToTm(), ExpressReco_HICollisions_FallBack::e, and ExpressReco_HICollisions_FallBack::id.

{
   this->checkConnection();

   DateHandler dh(m_env, m_conn);

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

     stmt->setSQL("SELECT run_iov_id, subrun_num, subrun_start, subrun_end FROM OD_run_iov WHERE iov_id = :1");
     stmt->setInt(1, id);
     
     ResultSet* rset = stmt->executeQuery();
     if (rset->next()) {
       int runIOVID = rset->getInt(1);
       m_subRunNum = rset->getInt(2);
       Date startDate = rset->getDate(3);
       Date endDate = rset->getDate(4);
         
       m_subRunStart = dh.dateToTm( startDate );
       m_subRunEnd = dh.dateToTm( endDate );

       m_runIOV.setConnection(m_env, m_conn);
       m_runIOV.setByID(runIOVID);

       m_ID = id;
     } else {
       throw(std::runtime_error("MODRunIOV::setByID:  Given id is not in the database"));
     }
     
     m_conn->terminateStatement(stmt);
   } catch (SQLException &e) {
     throw(std::runtime_error("MODRunIOV::setByID:  "+e.getMessage()));
   }
}
void MODRunIOV::setByRun ( RunIOV runiov,
subrun_t  subrun 
) throw (std::runtime_error) [private]

Definition at line 262 of file MODRunIOV.cc.

References DateHandler::dateToTm(), and ExpressReco_HICollisions_FallBack::e.

{
  this->checkConnection();
  
  runiov->setConnection(m_env, m_conn);
  int runIOVID = runiov->fetchID();

  if (!runIOVID) {
    throw(std::runtime_error("MODRunIOV::setByRun:  Given RunIOV does not exist in DB"));
  }

  DateHandler dh(m_env, m_conn);

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

    stmt->setSQL("SELECT iov_id, subrun_start, subrun_end FROM OD_run_iov "
                 "WHERE run_iov_id = :1 AND subrun_num = :2");
    stmt->setInt(1, runIOVID);
    stmt->setInt(2, subrun);

    ResultSet* rset = stmt->executeQuery();
    if (rset->next()) {
      m_runIOV = *runiov;
      m_subRunNum = subrun;
      
      m_ID = rset->getInt(1);
      Date startDate = rset->getDate(2);
      Date endDate = rset->getDate(3);
         
      m_subRunStart = dh.dateToTm( startDate );
      m_subRunEnd = dh.dateToTm( endDate );
    } else {
      throw(std::runtime_error("MODRunIOV::setByRun:  Given subrun is not in the database"));
    }
     
    m_conn->terminateStatement(stmt);
  } catch (SQLException &e) {
    throw(std::runtime_error("MODRunIOV::setByRun:  "+e.getMessage()));
  }
  
}
void MODRunIOV::setID ( int  id)

Definition at line 29 of file MODRunIOV.cc.

References ExpressReco_HICollisions_FallBack::id.

{
    m_ID = id;
}
void MODRunIOV::setRunIOV ( RunIOV  iov)

Definition at line 36 of file MODRunIOV.cc.

References o2o::iov.

{
  if (iov != m_runIOV) {
    m_ID = 0;
    m_runIOV = iov;
  }
}
void MODRunIOV::setSubRunEnd ( Tm  end)

Definition at line 84 of file MODRunIOV.cc.

References end.

{
  if (end != m_subRunEnd) {
    m_ID = 0;
    m_subRunEnd = end;
  }
}
void MODRunIOV::setSubRunNumber ( subrun_t  subrun)

Definition at line 50 of file MODRunIOV.cc.

{
  if (subrun != m_subRunNum) {
    m_ID = 0;
    m_subRunNum = subrun;
  }
}
void MODRunIOV::setSubRunStart ( Tm  start)

Definition at line 67 of file MODRunIOV.cc.

{
  if (start != m_subRunStart) {
    m_ID = 0;
    m_subRunStart = start;
  }
}
int MODRunIOV::writeDB ( ) throw (std::runtime_error) [private]

Definition at line 195 of file MODRunIOV.cc.

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

{
  this->checkConnection();

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

  // fetch Parent IDs
  int runIOVID;
  this->fetchParentIDs(&runIOVID);
                       
  // Validate the data, use infinity-till convention
  DateHandler dh(m_env, m_conn);

  if (m_subRunStart.isNull()) {
    throw(std::runtime_error("MODRunIOV::writeDB:  Must setSubRunStart before writing"));
  }
  
  if (m_subRunEnd.isNull()) {
    m_subRunEnd = dh.getPlusInfTm();
  }

  try {
    Statement* stmt = m_conn->createStatement();
    
    stmt->setSQL("INSERT INTO od_run_iov (iov_id,  run_iov_id, subrun_num, subrun_start, subrun_end) "
                 "VALUES (OD_run_iov_sq.NextVal, :1, :2, :3, :4)");
    stmt->setInt(1, runIOVID);
    stmt->setInt(2, m_subRunNum);
    stmt->setDate(3, dh.tmToDate(m_subRunStart));
    stmt->setDate(4, dh.tmToDate(m_subRunEnd));

    stmt->executeUpdate();

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

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


Member Data Documentation

Definition at line 50 of file MODRunIOV.h.

Referenced by operator==().

Definition at line 53 of file MODRunIOV.h.

Referenced by operator==().

Definition at line 51 of file MODRunIOV.h.

Referenced by operator==().

Definition at line 52 of file MODRunIOV.h.

Referenced by operator==().