CMS 3D CMS Logo

LMFRunIOV Class Reference

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

Inheritance diagram for LMFRunIOV:

IIOV IUniqueDBObject IDBObject

List of all members.

Public Member Functions

int fetchID () throw (std::runtime_error)
Tm getDBInsertionTime () const
int getID ()
LMFRunTag getLMFRunTag () const
RunIOV getRunIOV ()
Tm getSubRunEnd () const
run_t getSubRunNumber () const
Tm getSubRunStart () const
std::string getSubRunType () const
 LMFRunIOV ()
bool operator!= (const LMFRunIOV &m) const
bool operator== (const LMFRunIOV &m) const
void setByID (int id) throw (std::runtime_error)
void setDBInsertionTime (Tm x)
void setID (int id)
void setLMFRunTag (LMFRunTag tag)
void setRunIOV (RunIOV iov)
void setSubRunEnd (Tm end)
void setSubRunNumber (subrun_t subrun)
void setSubRunStart (Tm start)
void setSubRunType (std::string x)
 ~LMFRunIOV ()

Private Member Functions

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

Private Attributes

Tm m_dbtime
LMFRunTag m_lmfRunTag
RunIOV m_runIOV
std::string m_subrun_type
Tm m_subRunEnd
subrun_t m_subRunNum
Tm m_subRunStart

Friends

class EcalCondDBInterface


Detailed Description

Definition at line 14 of file LMFRunIOV.h.


Constructor & Destructor Documentation

LMFRunIOV::LMFRunIOV (  ) 

Definition at line 13 of file LMFRunIOV.cc.

References IDBObject::m_conn, m_dbtime, IUniqueDBObject::m_ID, m_lmfRunTag, m_runIOV, m_subrun_type, m_subRunEnd, m_subRunNum, m_subRunStart, and NULL.

00014 {
00015   m_conn = NULL;
00016   m_ID = 0;
00017   m_lmfRunTag = LMFRunTag();
00018   m_runIOV = RunIOV();
00019   m_subRunNum = 0;
00020   m_subRunStart = Tm();
00021   m_subRunEnd = Tm();
00022   m_dbtime = Tm();
00023   m_subrun_type="";
00024 }

LMFRunIOV::~LMFRunIOV (  ) 

Definition at line 28 of file LMFRunIOV.cc.

00029 {
00030 }


Member Function Documentation

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

Implements IUniqueDBObject.

Definition at line 70 of file LMFRunIOV.cc.

References IDBObject::checkConnection(), e, fetchParentIDs(), DateHandler::getPlusInfTm(), Tm::isNull(), IDBObject::m_conn, IDBObject::m_env, IUniqueDBObject::m_ID, m_subRunEnd, m_subRunNum, m_subRunStart, and DateHandler::tmToDate().

00072 {
00073   // Return from memory if available
00074   if (m_ID) {
00075     return m_ID;
00076   }
00077 
00078   this->checkConnection();
00079 
00080   // fetch the parent IDs
00081   int lmfRunTagID, runIOVID;
00082   this->fetchParentIDs(&lmfRunTagID, &runIOVID);
00083 
00084   if (!lmfRunTagID || !runIOVID) { 
00085     return 0;
00086   }
00087 
00088   DateHandler dh(m_env, m_conn);
00089 
00090   if (m_subRunEnd.isNull()) {
00091     m_subRunEnd = dh.getPlusInfTm();
00092   }
00093 
00094   try {
00095     Statement* stmt = m_conn->createStatement();
00096     stmt->setSQL("SELECT lmf_iov_id FROM lmf_run_iov "
00097                  "WHERE tag_id = :1 AND "
00098                  "run_iov_id   = :2 AND "
00099                  "subrun_num   = :3 AND "
00100                  "subrun_start = :4 AND "
00101                  "subrun_end   = :5");
00102     stmt->setInt(1, lmfRunTagID);
00103     stmt->setInt(2, runIOVID);
00104     stmt->setInt(3, m_subRunNum);
00105     stmt->setDate(4, dh.tmToDate(m_subRunStart));
00106     stmt->setDate(5, dh.tmToDate(m_subRunEnd));
00107   
00108     ResultSet* rset = stmt->executeQuery();
00109 
00110     if (rset->next()) {
00111       m_ID = rset->getInt(1);
00112     } else {
00113       m_ID = 0;
00114     }
00115     m_conn->terminateStatement(stmt);
00116   } catch (SQLException &e) {
00117     throw(runtime_error("LMFRunIOV::fetchID:  "+e.getMessage()));
00118   }
00119 
00120   return m_ID;
00121 }

void LMFRunIOV::fetchParentIDs ( int lmfRunTagID,
int runIOVID 
) throw (std::runtime_error) [private]

Definition at line 229 of file LMFRunIOV.cc.

References RunIOV::fetchID(), LMFRunTag::fetchID(), IDBObject::m_conn, IDBObject::m_env, m_lmfRunTag, m_runIOV, and IDBObject::setConnection().

Referenced by fetchID(), and writeDB().

00231 {
00232   // get the LMFRunTag
00233   m_lmfRunTag.setConnection(m_env, m_conn);
00234   *lmfRunTagID = m_lmfRunTag.fetchID();
00235 
00236   // get the RunIOV
00237   m_runIOV.setConnection(m_env, m_conn);
00238   *runIOVID = m_runIOV.fetchID();
00239 
00240   if (! *runIOVID) { 
00241     throw(runtime_error("LMFRunIOV:  Given RunIOV does not exist in DB")); 
00242   }
00243 
00244 }

Tm LMFRunIOV::getDBInsertionTime (  )  const [inline]

Definition at line 34 of file LMFRunIOV.h.

References m_dbtime.

00034 {return m_dbtime;}

int LMFRunIOV::getID (  )  [inline]

Definition at line 41 of file LMFRunIOV.h.

References IUniqueDBObject::m_ID.

00041 { return m_ID;} ;

LMFRunTag LMFRunIOV::getLMFRunTag (  )  const

Definition at line 48 of file LMFRunIOV.cc.

References m_lmfRunTag.

00049 {
00050   return m_lmfRunTag;
00051 }

RunIOV LMFRunIOV::getRunIOV (  ) 

Definition at line 53 of file LMFRunIOV.cc.

References m_runIOV.

00054 { 
00055   return m_runIOV;
00056 }

Tm LMFRunIOV::getSubRunEnd (  )  const [inline]

Definition at line 32 of file LMFRunIOV.h.

References m_subRunEnd.

00032 {return m_subRunEnd;}

run_t LMFRunIOV::getSubRunNumber (  )  const [inline]

Definition at line 28 of file LMFRunIOV.h.

References m_subRunNum.

00028 {return m_subRunNum;}

Tm LMFRunIOV::getSubRunStart (  )  const [inline]

Definition at line 30 of file LMFRunIOV.h.

References m_subRunStart.

00030 {return m_subRunStart;}

std::string LMFRunIOV::getSubRunType (  )  const [inline]

Definition at line 36 of file LMFRunIOV.h.

References m_subrun_type.

00036 {return m_subrun_type;}

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

Definition at line 55 of file LMFRunIOV.h.

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

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

Definition at line 46 of file LMFRunIOV.h.

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

00047     {
00048       return ( m_lmfRunTag   == m.m_lmfRunTag &&
00049                m_runIOV      == m.m_runIOV &&
00050                m_subRunNum   == m.m_subRunNum &&
00051                m_subRunStart == m.m_subRunStart &&
00052                m_subRunEnd   == m.m_subRunEnd );
00053     }

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

Implements IUniqueDBObject.

Definition at line 125 of file LMFRunIOV.cc.

References IDBObject::checkConnection(), DateHandler::dateToTm(), e, id, IDBObject::m_conn, m_dbtime, IDBObject::m_env, IUniqueDBObject::m_ID, m_lmfRunTag, m_runIOV, m_subrun_type, m_subRunEnd, m_subRunNum, m_subRunStart, RunIOV::setByID(), LMFRunTag::setByID(), and IDBObject::setConnection().

00127 {
00128    this->checkConnection();
00129 
00130    DateHandler dh(m_env, m_conn);
00131 
00132    try {
00133      Statement* stmt = m_conn->createStatement();
00134 
00135      stmt->setSQL("SELECT tag_id, run_iov_id, subrun_num, subrun_start, subrun_end, subrun_type, db_timestamp FROM lmf_run_iov WHERE lmf_iov_id = :1");
00136      stmt->setInt(1, id);
00137      
00138      ResultSet* rset = stmt->executeQuery();
00139      if (rset->next()) {
00140        int lmfRunTagID = rset->getInt(1);
00141        int runIOVID = rset->getInt(2);
00142        m_subRunNum = rset->getInt(3);
00143        Date startDate = rset->getDate(4);
00144        Date endDate = rset->getDate(5);
00145        m_subrun_type = rset->getString(6);
00146        Date dbtime = rset->getDate(7);
00147          
00148        m_subRunStart = dh.dateToTm( startDate );
00149        m_subRunEnd = dh.dateToTm( endDate );
00150        m_dbtime = dh.dateToTm(dbtime  );
00151 
00152        m_lmfRunTag.setConnection(m_env, m_conn);
00153        m_lmfRunTag.setByID(lmfRunTagID);
00154 
00155        m_runIOV.setConnection(m_env, m_conn);
00156        m_runIOV.setByID(runIOVID);
00157 
00158        m_ID = id;
00159      } else {
00160        throw(runtime_error("LMFRunIOV::setByID:  Given tag_id is not in the database"));
00161      }
00162      
00163      m_conn->terminateStatement(stmt);
00164    } catch (SQLException &e) {
00165      throw(runtime_error("LMFRunIOV::setByID:  "+e.getMessage()));
00166    }
00167 }

void LMFRunIOV::setByRun ( LMFRunTag lmftag,
RunIOV runiov,
subrun_t  subrun 
) throw (std::runtime_error) [private]

Definition at line 248 of file LMFRunIOV.cc.

References IDBObject::checkConnection(), DateHandler::dateToTm(), e, IDBObject::m_conn, IDBObject::m_env, IUniqueDBObject::m_ID, m_lmfRunTag, m_runIOV, m_subRunEnd, m_subRunNum, and m_subRunStart.

Referenced by EcalCondDBInterface::fetchLMFRunIOV().

00250 {
00251   this->checkConnection();
00252   
00253   runiov->setConnection(m_env, m_conn);
00254   int runIOVID = runiov->fetchID();
00255 
00256   if (!runIOVID) {
00257     throw(runtime_error("LMFRunIOV::setByRun:  Given RunIOV does not exist in DB"));
00258   }
00259 
00260   lmftag->setConnection(m_env, m_conn);
00261   int lmfTagID = lmftag->fetchID();
00262   
00263   if (!lmfTagID) {
00264     throw(runtime_error("LMFRunIOV::setByRun:  Given LMFRunTag does not exist in the DB"));
00265   }
00266 
00267   DateHandler dh(m_env, m_conn);
00268 
00269   try {
00270     Statement* stmt = m_conn->createStatement();
00271 
00272     stmt->setSQL("SELECT lmf_iov_id, subrun_start, subrun_end FROM lmf_run_iov "
00273                  "WHERE tag_id = :1 AND run_iov_id = :2 AND subrun_num = :3");
00274     stmt->setInt(1, lmfTagID);
00275     stmt->setInt(2, runIOVID);
00276     stmt->setInt(3, subrun);
00277 
00278     ResultSet* rset = stmt->executeQuery();
00279     if (rset->next()) {
00280       m_lmfRunTag = *lmftag;
00281       m_runIOV = *runiov;
00282       m_subRunNum = subrun;
00283       
00284       m_ID = rset->getInt(1);
00285       Date startDate = rset->getDate(2);
00286       Date endDate = rset->getDate(3);
00287          
00288       m_subRunStart = dh.dateToTm( startDate );
00289       m_subRunEnd = dh.dateToTm( endDate );
00290     } else {
00291       throw(runtime_error("LMFRunIOV::setByRun:  Given subrun is not in the database"));
00292     }
00293      
00294     m_conn->terminateStatement(stmt);
00295   } catch (SQLException &e) {
00296     throw(runtime_error("LMFRunIOV::setByRun:  "+e.getMessage()));
00297   }
00298   
00299 }

void LMFRunIOV::setDBInsertionTime ( Tm  x  )  [inline]

Definition at line 33 of file LMFRunIOV.h.

References m_dbtime.

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

00033 {m_dbtime=x;}

void LMFRunIOV::setID ( int  id  ) 

Definition at line 32 of file LMFRunIOV.cc.

References IUniqueDBObject::m_ID.

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

00033 {
00034     m_ID = id;
00035 }

void LMFRunIOV::setLMFRunTag ( LMFRunTag  tag  ) 

Definition at line 38 of file LMFRunIOV.cc.

References IUniqueDBObject::m_ID, and m_lmfRunTag.

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

00039 {
00040   if (tag != m_lmfRunTag) {
00041     m_ID = 0;
00042     m_lmfRunTag = tag;
00043   }
00044 }

void LMFRunIOV::setRunIOV ( RunIOV  iov  ) 

Definition at line 59 of file LMFRunIOV.cc.

References IUniqueDBObject::m_ID, and m_runIOV.

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

00060 {
00061   if (iov != m_runIOV) {
00062     m_ID = 0;
00063     m_runIOV = iov;
00064   }
00065 }

void LMFRunIOV::setSubRunEnd ( Tm  end  )  [inline]

Definition at line 31 of file LMFRunIOV.h.

References m_subRunEnd.

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

00031 {m_subRunEnd=end;}

void LMFRunIOV::setSubRunNumber ( subrun_t  subrun  )  [inline]

Definition at line 27 of file LMFRunIOV.h.

References m_subRunNum.

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

00027 {m_subRunNum=subrun;}

void LMFRunIOV::setSubRunStart ( Tm  start  )  [inline]

Definition at line 29 of file LMFRunIOV.h.

References m_subRunStart.

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

00029 {m_subRunStart=start;}

void LMFRunIOV::setSubRunType ( std::string  x  )  [inline]

Definition at line 35 of file LMFRunIOV.h.

References m_subrun_type.

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

00035 {m_subrun_type=x;}

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

Definition at line 171 of file LMFRunIOV.cc.

References IDBObject::checkConnection(), e, fetchParentIDs(), DateHandler::getPlusInfTm(), Tm::isNull(), IDBObject::m_conn, IDBObject::m_env, IUniqueDBObject::m_ID, m_lmfRunTag, m_subrun_type, m_subRunEnd, m_subRunNum, m_subRunStart, DateHandler::tmToDate(), and LMFRunTag::writeDB().

00173 {
00174   this->checkConnection();
00175 
00176   // Check if this IOV has already been written
00177   if (this->fetchID()) {
00178     return m_ID;
00179   }
00180 
00181   // fetch Parent IDs
00182   int lmfRunTagID, runIOVID;
00183   this->fetchParentIDs(&lmfRunTagID, &runIOVID);
00184                        
00185   if (!lmfRunTagID) {
00186     lmfRunTagID = m_lmfRunTag.writeDB();
00187   }
00188   
00189   // Validate the data, use infinity-till convention
00190   DateHandler dh(m_env, m_conn);
00191 
00192   if (m_subRunStart.isNull()) {
00193     throw(runtime_error("LMFRunIOV::writeDB:  Must setSubRunStart before writing"));
00194   }
00195   
00196   if (m_subRunEnd.isNull()) {
00197     m_subRunEnd = dh.getPlusInfTm();
00198   }
00199 
00200   try {
00201     Statement* stmt = m_conn->createStatement();
00202     
00203     stmt->setSQL("INSERT INTO lmf_run_iov (lmf_iov_id, tag_id, run_iov_id, subrun_num, subrun_start, subrun_end, subrun_type) "
00204                  "VALUES (lmf_run_iov_sq.NextVal, :1, :2, :3, :4, :5, :6)");
00205     stmt->setInt(1, lmfRunTagID);
00206     stmt->setInt(2, runIOVID);
00207     stmt->setInt(3, m_subRunNum);
00208     stmt->setDate(4, dh.tmToDate(m_subRunStart));
00209     stmt->setDate(5, dh.tmToDate(m_subRunEnd));
00210     stmt->setString(6, m_subrun_type);
00211 
00212     stmt->executeUpdate();
00213 
00214     m_conn->terminateStatement(stmt);
00215   } catch (SQLException &e) {
00216     throw(runtime_error("LMFRunIOV::writeDB:  "+e.getMessage()));
00217   }
00218 
00219   // Now get the ID
00220   if (!this->fetchID()) {
00221     throw(runtime_error("LMFRunIOV::writeDB:  Failed to write"));
00222   }
00223   
00224   return m_ID;
00225 }


Friends And Related Function Documentation

friend class EcalCondDBInterface [friend]

Reimplemented from IDBObject.

Definition at line 16 of file LMFRunIOV.h.


Member Data Documentation

Tm LMFRunIOV::m_dbtime [private]

Definition at line 64 of file LMFRunIOV.h.

Referenced by getDBInsertionTime(), LMFRunIOV(), setByID(), and setDBInsertionTime().

LMFRunTag LMFRunIOV::m_lmfRunTag [private]

Definition at line 59 of file LMFRunIOV.h.

Referenced by fetchParentIDs(), getLMFRunTag(), LMFRunIOV(), operator==(), setByID(), setByRun(), setLMFRunTag(), and writeDB().

RunIOV LMFRunIOV::m_runIOV [private]

Definition at line 60 of file LMFRunIOV.h.

Referenced by fetchParentIDs(), getRunIOV(), LMFRunIOV(), operator==(), setByID(), setByRun(), and setRunIOV().

std::string LMFRunIOV::m_subrun_type [private]

Definition at line 65 of file LMFRunIOV.h.

Referenced by getSubRunType(), LMFRunIOV(), setByID(), setSubRunType(), and writeDB().

Tm LMFRunIOV::m_subRunEnd [private]

Definition at line 63 of file LMFRunIOV.h.

Referenced by fetchID(), getSubRunEnd(), LMFRunIOV(), operator==(), setByID(), setByRun(), setSubRunEnd(), and writeDB().

subrun_t LMFRunIOV::m_subRunNum [private]

Definition at line 61 of file LMFRunIOV.h.

Referenced by fetchID(), getSubRunNumber(), LMFRunIOV(), operator==(), setByID(), setByRun(), setSubRunNumber(), and writeDB().

Tm LMFRunIOV::m_subRunStart [private]

Definition at line 62 of file LMFRunIOV.h.

Referenced by fetchID(), getSubRunStart(), LMFRunIOV(), operator==(), setByID(), setByRun(), setSubRunStart(), and writeDB().


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