CMS 3D CMS Logo

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

MonRunIOV Class Reference

#include <MonRunIOV.h>

Inheritance diagram for MonRunIOV:
IIOV IUniqueDBObject IDBObject

List of all members.

Public Member Functions

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

Private Member Functions

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

Private Attributes

MonRunTag m_monRunTag
RunIOV m_runIOV
Tm m_subRunEnd
subrun_t m_subRunNum
Tm m_subRunStart

Friends

class EcalCondDBInterface

Detailed Description

Definition at line 14 of file MonRunIOV.h.


Constructor & Destructor Documentation

MonRunIOV::MonRunIOV ( )

Definition at line 13 of file MonRunIOV.cc.

References NULL.

MonRunIOV::~MonRunIOV ( )

Definition at line 26 of file MonRunIOV.cc.

{
}

Member Function Documentation

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

Implements IUniqueDBObject.

Definition at line 118 of file MonRunIOV.cc.

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

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

  this->checkConnection();

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

  if (!monRunTagID || !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 mon_run_iov "
                 "WHERE tag_id = :1 AND "
                 "run_iov_id   = :2 AND "
                 "subrun_num   = :3 AND "
                 "subrun_start = :4 AND "
                 "subrun_end   = :5");
    stmt->setInt(1, monRunTagID);
    stmt->setInt(2, runIOVID);
    stmt->setInt(3, m_subRunNum);
    stmt->setDate(4, dh.tmToDate(m_subRunStart));
    stmt->setDate(5, 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("MonRunIOV::fetchID:  "+e.getMessage()));
  }

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

Definition at line 273 of file MonRunIOV.cc.

{
  // get the MonRunTag
  m_monRunTag.setConnection(m_env, m_conn);
  *monRunTagID = m_monRunTag.fetchID();

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

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

}
int MonRunIOV::getID ( ) [inline]

Definition at line 22 of file MonRunIOV.h.

References IUniqueDBObject::m_ID.

{ return m_ID;} ;
MonRunTag MonRunIOV::getMonRunTag ( ) const

Definition at line 46 of file MonRunIOV.cc.

{
  return m_monRunTag;
}
RunIOV MonRunIOV::getRunIOV ( )

Definition at line 61 of file MonRunIOV.cc.

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

Definition at line 111 of file MonRunIOV.cc.

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

Definition at line 77 of file MonRunIOV.cc.

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

Definition at line 94 of file MonRunIOV.cc.

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

Definition at line 50 of file MonRunIOV.h.

References m.

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

Definition at line 41 of file MonRunIOV.h.

References m_monRunTag, m_runIOV, m_subRunEnd, m_subRunNum, and m_subRunStart.

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

Implements IUniqueDBObject.

Definition at line 173 of file MonRunIOV.cc.

References DateHandler::dateToTm().

{
   this->checkConnection();

   DateHandler dh(m_env, m_conn);

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

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

       m_monRunTag.setConnection(m_env, m_conn);
       m_monRunTag.setByID(monRunTagID);

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

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

Definition at line 292 of file MonRunIOV.cc.

References DateHandler::dateToTm().

Referenced by EcalCondDBInterface::fetchMonRunIOV().

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

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

  montag->setConnection(m_env, m_conn);
  int monTagID = montag->fetchID();
  
  if (!monTagID) {
    throw(std::runtime_error("MonRunIOV::setByRun:  Given MonRunTag does not exist in the DB"));
  }

  DateHandler dh(m_env, m_conn);

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

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

    ResultSet* rset = stmt->executeQuery();
    if (rset->next()) {
      m_monRunTag = *montag;
      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("MonRunIOV::setByRun:  Given subrun is not in the database"));
    }
     
    m_conn->terminateStatement(stmt);
  } catch (SQLException &e) {
    throw(std::runtime_error("MonRunIOV::setByRun:  "+e.getMessage()));
  }
  
}
void MonRunIOV::setID ( int  id)

Definition at line 31 of file MonRunIOV.cc.

Referenced by MonRunList::fetchLastNRuns(), and MonRunList::fetchRuns().

{
    m_ID = id;
}
void MonRunIOV::setMonRunTag ( MonRunTag  tag)
void MonRunIOV::setRunIOV ( RunIOV  iov)

Definition at line 53 of file MonRunIOV.cc.

References o2o::iov.

Referenced by MonRunList::fetchLastNRuns(), MonRunList::fetchRuns(), and EcalPedOffset::writeDb().

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

Definition at line 101 of file MonRunIOV.cc.

References end.

Referenced by MonRunList::fetchLastNRuns(), and MonRunList::fetchRuns().

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

Definition at line 67 of file MonRunIOV.cc.

Referenced by MonRunList::fetchLastNRuns(), MonRunList::fetchRuns(), and EcalPedOffset::writeDb().

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

Definition at line 84 of file MonRunIOV.cc.

Referenced by MonRunList::fetchLastNRuns(), MonRunList::fetchRuns(), and EcalPedOffset::writeDb().

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

Definition at line 216 of file MonRunIOV.cc.

References 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 monRunTagID, runIOVID;
  this->fetchParentIDs(&monRunTagID, &runIOVID);
                       
  if (!monRunTagID) {
    monRunTagID = m_monRunTag.writeDB();
  }
  
  // Validate the data, use infinity-till convention
  DateHandler dh(m_env, m_conn);

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

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

    stmt->executeUpdate();

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

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


Member Data Documentation

Definition at line 54 of file MonRunIOV.h.

Referenced by operator==().

Definition at line 55 of file MonRunIOV.h.

Referenced by operator==().

Definition at line 58 of file MonRunIOV.h.

Referenced by operator==().

Definition at line 56 of file MonRunIOV.h.

Referenced by operator==().

Definition at line 57 of file MonRunIOV.h.

Referenced by operator==().