CMS 3D CMS Logo

CaliIOV Class Reference

#include <OnlineDB/EcalCondDB/interface/CaliIOV.h>

Inheritance diagram for CaliIOV:

IIOV IUniqueDBObject IDBObject

List of all members.

Public Member Functions

 CaliIOV ()
int fetchID () throw (std::runtime_error)
CaliTag getCaliTag () const
int getID ()
Tm getSince () const
Tm getTill () const
bool operator!= (const CaliIOV &m) const
bool operator== (const CaliIOV &m) const
void setByID (int id) throw (std::runtime_error)
void setCaliTag (CaliTag tag)
void setSince (Tm since)
void setTill (Tm till)
 ~CaliIOV ()

Private Member Functions

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

Private Attributes

CaliTag m_caliTag
Tm m_since
Tm m_till

Friends

class EcalCondDBInterface


Detailed Description

Definition at line 13 of file CaliIOV.h.


Constructor & Destructor Documentation

CaliIOV::CaliIOV (  ) 

Definition at line 12 of file CaliIOV.cc.

References IDBObject::m_conn, IUniqueDBObject::m_ID, m_since, m_till, and NULL.

00013 {
00014   m_conn = NULL;
00015   m_ID = 0;
00016   m_since = Tm();
00017   m_till = Tm();
00018 }

CaliIOV::~CaliIOV (  ) 

Definition at line 22 of file CaliIOV.cc.

00023 {
00024 }


Member Function Documentation

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

Implements IUniqueDBObject.

Definition at line 79 of file CaliIOV.cc.

References IDBObject::checkConnection(), e, CaliTag::fetchID(), DateHandler::getPlusInfTm(), Tm::isNull(), m_caliTag, IDBObject::m_conn, IDBObject::m_env, IUniqueDBObject::m_ID, m_since, m_till, IDBObject::setConnection(), and DateHandler::tmToDate().

00081 {
00082   // Return from memory if available
00083   if (m_ID) {
00084     return m_ID;
00085   }
00086 
00087   this->checkConnection();
00088 
00089   m_caliTag.setConnection(m_env, m_conn);
00090   int tagID = m_caliTag.fetchID();
00091   if (!tagID) { 
00092     return 0;
00093   }
00094 
00095   DateHandler dh(m_env, m_conn);
00096 
00097   if (m_till.isNull()) {
00098     m_till = dh.getPlusInfTm();
00099   }
00100 
00101   try {
00102     Statement* stmt = m_conn->createStatement();
00103     stmt->setSQL("SELECT iov_id FROM cali_iov "
00104                  "WHERE tag_id = :tag_id AND "
00105                  "since = :since AND "
00106                  "till = :till");
00107     stmt->setInt(1, tagID);
00108     stmt->setDate(2, dh.tmToDate(m_since));
00109     stmt->setDate(3, dh.tmToDate(m_till));
00110   
00111     ResultSet* rset = stmt->executeQuery();
00112 
00113     if (rset->next()) {
00114       m_ID = rset->getInt(1);
00115     } else {
00116       m_ID = 0;
00117     }
00118     m_conn->terminateStatement(stmt);
00119   } catch (SQLException &e) {
00120     throw(runtime_error("CaliIOV::fetchID:  "+e.getMessage()));
00121   }
00122 
00123   return m_ID;
00124 }

CaliTag CaliIOV::getCaliTag (  )  const

Definition at line 72 of file CaliIOV.cc.

References m_caliTag.

00073 {
00074   return m_caliTag;
00075 }

int CaliIOV::getID (  )  [inline]

Definition at line 31 of file CaliIOV.h.

References IUniqueDBObject::m_ID.

00031 { return m_ID;} ;

Tm CaliIOV::getSince (  )  const

Definition at line 38 of file CaliIOV.cc.

References m_since.

00039 {
00040   return m_since;
00041 }

Tm CaliIOV::getTill (  )  const

Definition at line 55 of file CaliIOV.cc.

References m_till.

00056 {
00057   return m_till;
00058 }

bool CaliIOV::operator!= ( const CaliIOV m  )  const [inline]

Definition at line 43 of file CaliIOV.h.

00043 { return !(*this == m); }

bool CaliIOV::operator== ( const CaliIOV m  )  const [inline]

Definition at line 36 of file CaliIOV.h.

References m_caliTag, m_since, and m_till.

00037     {
00038       return ( m_caliTag   == m.m_caliTag &&
00039                m_since == m.m_since &&
00040                m_till   == m.m_till );
00041     }

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

Implements IUniqueDBObject.

Definition at line 128 of file CaliIOV.cc.

References IDBObject::checkConnection(), DateHandler::dateToTm(), e, id, m_caliTag, IDBObject::m_conn, IDBObject::m_env, IUniqueDBObject::m_ID, m_since, m_till, CaliTag::setByID(), and IDBObject::setConnection().

00130 {
00131    this->checkConnection();
00132 
00133    DateHandler dh(m_env, m_conn);
00134 
00135    try {
00136      Statement* stmt = m_conn->createStatement();
00137 
00138      stmt->setSQL("SELECT tag_id, since, till FROM cali_iov WHERE iov_id = :1");
00139      stmt->setInt(1, id);
00140      
00141      ResultSet* rset = stmt->executeQuery();
00142      if (rset->next()) {
00143        int tagID = rset->getInt(1);
00144        Date since = rset->getDate(2);
00145        Date till = rset->getDate(3);
00146          
00147        m_since = dh.dateToTm( since );
00148        m_till = dh.dateToTm( till );
00149 
00150        m_caliTag.setConnection(m_env, m_conn);
00151        m_caliTag.setByID(tagID);
00152        m_ID = id;
00153      } else {
00154        throw(runtime_error("CaliTag::setByID:  Given tag_id is not in the database"));
00155      }
00156      
00157      m_conn->terminateStatement(stmt);
00158    } catch (SQLException &e) {
00159      throw(runtime_error("CaliTag::setByID:  "+e.getMessage()));
00160    }
00161 }

void CaliIOV::setByTm ( CaliTag tag,
Tm  time 
) throw (std::runtime_error) [private]

Definition at line 215 of file CaliIOV.cc.

References IDBObject::checkConnection(), DateHandler::dateToTm(), e, m_caliTag, IDBObject::m_conn, IDBObject::m_env, IUniqueDBObject::m_ID, m_since, m_till, ecalRecalibSequence_cff::tag, and DateHandler::tmToDate().

Referenced by EcalCondDBInterface::fetchCaliIOV().

00217 {
00218   this->checkConnection();
00219   
00220   tag->setConnection(m_env, m_conn);
00221   int tagID = tag->fetchID();
00222   
00223   if (!tagID) {
00224     throw(runtime_error("CaliIOV::setByTm:  Given CaliTag does not exist in the DB"));
00225   }
00226 
00227   DateHandler dh(m_env, m_conn);
00228 
00229   Date eventDate = dh.tmToDate(eventTm);
00230 
00231   try {
00232     Statement* stmt = m_conn->createStatement();
00233 
00234 
00235     stmt->setSQL("SELECT iov_id, since, till FROM cali_iov "
00236                  "WHERE tag_id = :1 AND since <= :2 AND till > :3");
00237     stmt->setInt(1, tagID);
00238     stmt->setDate(2, eventDate);
00239     stmt->setDate(3, eventDate);
00240 
00241     ResultSet* rset = stmt->executeQuery();
00242     if (rset->next()) {
00243       m_caliTag = *tag;
00244       
00245       m_ID = rset->getInt(1);
00246       Date sinceDate = rset->getDate(2);
00247       Date tillDate = rset->getDate(3);
00248          
00249       m_since = dh.dateToTm( sinceDate );
00250       m_till = dh.dateToTm( tillDate );
00251     } else {
00252       throw(runtime_error("CaliIOV::setByTm:  Given subrun is not in the database"));
00253     }
00254      
00255     m_conn->terminateStatement(stmt);
00256   } catch (SQLException &e) {
00257     throw(runtime_error("CaliIOV::setByTm:  "+e.getMessage()));
00258   }
00259 }

void CaliIOV::setCaliTag ( CaliTag  tag  ) 

Definition at line 62 of file CaliIOV.cc.

References m_caliTag, and IUniqueDBObject::m_ID.

00063 {
00064   if (tag != m_caliTag) {
00065     m_ID = 0;
00066     m_caliTag = tag;
00067   }
00068 }

void CaliIOV::setSince ( Tm  since  ) 

Definition at line 28 of file CaliIOV.cc.

References IUniqueDBObject::m_ID, and m_since.

00029 {
00030   if (since != m_since) {
00031     m_ID = 0;
00032     m_since = since;
00033   }
00034 }

void CaliIOV::setTill ( Tm  till  ) 

Definition at line 45 of file CaliIOV.cc.

References IUniqueDBObject::m_ID, and m_till.

00046 {
00047   if (till != m_till) {
00048     m_ID = 0;
00049     m_till = till;
00050   }
00051 }

int CaliIOV::writeDB (  )  throw (std::runtime_error) [private]

Definition at line 165 of file CaliIOV.cc.

References IDBObject::checkConnection(), e, DateHandler::getPlusInfTm(), Tm::isNull(), m_caliTag, IDBObject::m_conn, IDBObject::m_env, IUniqueDBObject::m_ID, m_since, m_till, IDBObject::setConnection(), DateHandler::tmToDate(), and CaliTag::writeDB().

00167 {
00168   this->checkConnection();
00169 
00170   // Check if this IOV has already been written
00171   if (this->fetchID()) {
00172     return m_ID;
00173   }
00174 
00175   m_caliTag.setConnection(m_env, m_conn);
00176   int tagID = m_caliTag.writeDB();
00177   
00178   // Validate the data, use infinity-till convention
00179   DateHandler dh(m_env, m_conn);
00180 
00181   if (m_since.isNull()) {
00182     throw(runtime_error("CaliIOV::writeDB:  Must setSince before writing"));
00183   }
00184   
00185   if (m_till.isNull()) {
00186     m_till = dh.getPlusInfTm();
00187   }
00188 
00189   try {
00190     Statement* stmt = m_conn->createStatement();
00191     
00192     stmt->setSQL("INSERT INTO cali_iov (iov_id, tag_id, since, till) "
00193                  "VALUES (cali_iov_sq.NextVal, :1, :2, :3)");
00194     stmt->setInt(1, tagID);
00195     stmt->setDate(2, dh.tmToDate(m_since));
00196     stmt->setDate(3, dh.tmToDate(m_till));
00197 
00198     stmt->executeUpdate();
00199 
00200     m_conn->terminateStatement(stmt);
00201   } catch (SQLException &e) {
00202     throw(runtime_error("CaliIOV::writeDB:  "+e.getMessage()));
00203   }
00204 
00205   // Now get the ID
00206   if (!this->fetchID()) {
00207     throw(runtime_error("CaliIOV::writeDB:  Failed to write"));
00208   }
00209   
00210   return m_ID;
00211 }


Friends And Related Function Documentation

friend class EcalCondDBInterface [friend]

Reimplemented from IDBObject.

Definition at line 15 of file CaliIOV.h.


Member Data Documentation

CaliTag CaliIOV::m_caliTag [private]

Definition at line 50 of file CaliIOV.h.

Referenced by fetchID(), getCaliTag(), operator==(), setByID(), setByTm(), setCaliTag(), and writeDB().

Tm CaliIOV::m_since [private]

Definition at line 48 of file CaliIOV.h.

Referenced by CaliIOV(), fetchID(), getSince(), operator==(), setByID(), setByTm(), setSince(), and writeDB().

Tm CaliIOV::m_till [private]

Definition at line 49 of file CaliIOV.h.

Referenced by CaliIOV(), fetchID(), getTill(), operator==(), setByID(), setByTm(), setTill(), and writeDB().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:15:39 2009 for CMSSW by  doxygen 1.5.4