CMS 3D CMS Logo

MonRunIOV Class Reference

#include <OnlineDB/EcalCondDB/interface/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 IDBObject::m_conn, IUniqueDBObject::m_ID, m_monRunTag, m_runIOV, m_subRunEnd, m_subRunNum, m_subRunStart, and NULL.

00014 {
00015   m_conn = NULL;
00016   m_ID = 0;
00017   m_monRunTag = MonRunTag();
00018   m_runIOV = RunIOV();
00019   m_subRunNum = 0;
00020   m_subRunStart = Tm();
00021   m_subRunEnd = Tm();
00022 }

MonRunIOV::~MonRunIOV (  ) 

Definition at line 26 of file MonRunIOV.cc.

00027 {
00028 }


Member Function Documentation

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

Implements IUniqueDBObject.

Definition at line 118 of file MonRunIOV.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().

00120 {
00121   // Return from memory if available
00122   if (m_ID) {
00123     return m_ID;
00124   }
00125 
00126   this->checkConnection();
00127 
00128   // fetch the parent IDs
00129   int monRunTagID, runIOVID;
00130   this->fetchParentIDs(&monRunTagID, &runIOVID);
00131 
00132   if (!monRunTagID || !runIOVID) { 
00133     return 0;
00134   }
00135 
00136   DateHandler dh(m_env, m_conn);
00137 
00138   if (m_subRunEnd.isNull()) {
00139     m_subRunEnd = dh.getPlusInfTm();
00140   }
00141 
00142   try {
00143     Statement* stmt = m_conn->createStatement();
00144     stmt->setSQL("SELECT iov_id FROM mon_run_iov "
00145                  "WHERE tag_id = :1 AND "
00146                  "run_iov_id   = :2 AND "
00147                  "subrun_num   = :3 AND "
00148                  "subrun_start = :4 AND "
00149                  "subrun_end   = :5");
00150     stmt->setInt(1, monRunTagID);
00151     stmt->setInt(2, runIOVID);
00152     stmt->setInt(3, m_subRunNum);
00153     stmt->setDate(4, dh.tmToDate(m_subRunStart));
00154     stmt->setDate(5, dh.tmToDate(m_subRunEnd));
00155   
00156     ResultSet* rset = stmt->executeQuery();
00157 
00158     if (rset->next()) {
00159       m_ID = rset->getInt(1);
00160     } else {
00161       m_ID = 0;
00162     }
00163     m_conn->terminateStatement(stmt);
00164   } catch (SQLException &e) {
00165     throw(runtime_error("MonRunIOV::fetchID:  "+e.getMessage()));
00166   }
00167 
00168   return m_ID;
00169 }

void MonRunIOV::fetchParentIDs ( int monRunTagID,
int runIOVID 
) throw (std::runtime_error) [private]

Definition at line 273 of file MonRunIOV.cc.

References RunIOV::fetchID(), MonRunTag::fetchID(), IDBObject::m_conn, IDBObject::m_env, m_monRunTag, m_runIOV, and IDBObject::setConnection().

Referenced by fetchID(), and writeDB().

00275 {
00276   // get the MonRunTag
00277   m_monRunTag.setConnection(m_env, m_conn);
00278   *monRunTagID = m_monRunTag.fetchID();
00279 
00280   // get the RunIOV
00281   m_runIOV.setConnection(m_env, m_conn);
00282   *runIOVID = m_runIOV.fetchID();
00283 
00284   if (! *runIOVID) { 
00285     throw(runtime_error("MonRunIOV:  Given RunIOV does not exist in DB")); 
00286   }
00287 
00288 }

int MonRunIOV::getID (  )  [inline]

Definition at line 22 of file MonRunIOV.h.

References IUniqueDBObject::m_ID.

00022 { return m_ID;} ;

MonRunTag MonRunIOV::getMonRunTag (  )  const

Definition at line 46 of file MonRunIOV.cc.

References m_monRunTag.

Referenced by EcalEndcapMonitorClient::defaultWebPage(), EcalBarrelMonitorClient::defaultWebPage(), EcalEndcapMonitorClient::writeDb(), and EcalBarrelMonitorClient::writeDb().

00047 {
00048   return m_monRunTag;
00049 }

RunIOV MonRunIOV::getRunIOV (  ) 

Definition at line 61 of file MonRunIOV.cc.

References m_runIOV.

00062 { 
00063   return m_runIOV;
00064 }

Tm MonRunIOV::getSubRunEnd (  )  const

Definition at line 111 of file MonRunIOV.cc.

References m_subRunEnd.

Referenced by EcalEndcapMonitorClient::defaultWebPage(), EcalBarrelMonitorClient::defaultWebPage(), EcalEndcapMonitorClient::writeDb(), and EcalBarrelMonitorClient::writeDb().

00112 {
00113   return m_subRunEnd;
00114 }

run_t MonRunIOV::getSubRunNumber (  )  const

Definition at line 77 of file MonRunIOV.cc.

References m_subRunNum.

Referenced by EcalEndcapMonitorClient::defaultWebPage(), EcalBarrelMonitorClient::defaultWebPage(), EcalEndcapMonitorClient::writeDb(), and EcalBarrelMonitorClient::writeDb().

00078 {
00079   return m_subRunNum;
00080 }

Tm MonRunIOV::getSubRunStart (  )  const

Definition at line 94 of file MonRunIOV.cc.

References m_subRunStart.

Referenced by EcalEndcapMonitorClient::defaultWebPage(), EcalBarrelMonitorClient::defaultWebPage(), EcalEndcapMonitorClient::writeDb(), and EcalBarrelMonitorClient::writeDb().

00095 {
00096   return m_subRunStart;
00097 }

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

Definition at line 50 of file MonRunIOV.h.

00050 { 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.

00042     {
00043       return ( m_monRunTag   == m.m_monRunTag &&
00044                m_runIOV      == m.m_runIOV &&
00045                m_subRunNum   == m.m_subRunNum &&
00046                m_subRunStart == m.m_subRunStart &&
00047                m_subRunEnd   == m.m_subRunEnd );
00048     }

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

Implements IUniqueDBObject.

Definition at line 173 of file MonRunIOV.cc.

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

00175 {
00176    this->checkConnection();
00177 
00178    DateHandler dh(m_env, m_conn);
00179 
00180    try {
00181      Statement* stmt = m_conn->createStatement();
00182 
00183      stmt->setSQL("SELECT tag_id, run_iov_id, subrun_num, subrun_start, subrun_end FROM mon_run_iov WHERE iov_id = :1");
00184      stmt->setInt(1, id);
00185      
00186      ResultSet* rset = stmt->executeQuery();
00187      if (rset->next()) {
00188        int monRunTagID = rset->getInt(1);
00189        int runIOVID = rset->getInt(2);
00190        m_subRunNum = rset->getInt(3);
00191        Date startDate = rset->getDate(4);
00192        Date endDate = rset->getDate(5);
00193          
00194        m_subRunStart = dh.dateToTm( startDate );
00195        m_subRunEnd = dh.dateToTm( endDate );
00196 
00197        m_monRunTag.setConnection(m_env, m_conn);
00198        m_monRunTag.setByID(monRunTagID);
00199 
00200        m_runIOV.setConnection(m_env, m_conn);
00201        m_runIOV.setByID(runIOVID);
00202 
00203        m_ID = id;
00204      } else {
00205        throw(runtime_error("MonRunIOV::setByID:  Given tag_id is not in the database"));
00206      }
00207      
00208      m_conn->terminateStatement(stmt);
00209    } catch (SQLException &e) {
00210      throw(runtime_error("MonRunIOV::setByID:  "+e.getMessage()));
00211    }
00212 }

void MonRunIOV::setByRun ( MonRunTag montag,
RunIOV runiov,
subrun_t  subrun 
) throw (std::runtime_error) [private]

Definition at line 292 of file MonRunIOV.cc.

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

Referenced by EcalCondDBInterface::fetchMonRunIOV().

00294 {
00295   this->checkConnection();
00296   
00297   runiov->setConnection(m_env, m_conn);
00298   int runIOVID = runiov->fetchID();
00299 
00300   if (!runIOVID) {
00301     throw(runtime_error("MonRunIOV::setByRun:  Given RunIOV does not exist in DB"));
00302   }
00303 
00304   montag->setConnection(m_env, m_conn);
00305   int monTagID = montag->fetchID();
00306   
00307   if (!monTagID) {
00308     throw(runtime_error("MonRunIOV::setByRun:  Given MonRunTag does not exist in the DB"));
00309   }
00310 
00311   DateHandler dh(m_env, m_conn);
00312 
00313   try {
00314     Statement* stmt = m_conn->createStatement();
00315 
00316     stmt->setSQL("SELECT iov_id, subrun_start, subrun_end FROM mon_run_iov "
00317                  "WHERE tag_id = :1 AND run_iov_id = :2 AND subrun_num = :3");
00318     stmt->setInt(1, monTagID);
00319     stmt->setInt(2, runIOVID);
00320     stmt->setInt(3, subrun);
00321 
00322     ResultSet* rset = stmt->executeQuery();
00323     if (rset->next()) {
00324       m_monRunTag = *montag;
00325       m_runIOV = *runiov;
00326       m_subRunNum = subrun;
00327       
00328       m_ID = rset->getInt(1);
00329       Date startDate = rset->getDate(2);
00330       Date endDate = rset->getDate(3);
00331          
00332       m_subRunStart = dh.dateToTm( startDate );
00333       m_subRunEnd = dh.dateToTm( endDate );
00334     } else {
00335       throw(runtime_error("MonRunIOV::setByRun:  Given subrun is not in the database"));
00336     }
00337      
00338     m_conn->terminateStatement(stmt);
00339   } catch (SQLException &e) {
00340     throw(runtime_error("MonRunIOV::setByRun:  "+e.getMessage()));
00341   }
00342   
00343 }

void MonRunIOV::setID ( int  id  ) 

Definition at line 31 of file MonRunIOV.cc.

References IUniqueDBObject::m_ID.

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

00032 {
00033     m_ID = id;
00034 }

void MonRunIOV::setMonRunTag ( MonRunTag  tag  ) 

Definition at line 36 of file MonRunIOV.cc.

References IUniqueDBObject::m_ID, and m_monRunTag.

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

00037 {
00038   if (tag != m_monRunTag) {
00039     m_ID = 0;
00040     m_monRunTag = tag;
00041   }
00042 }

void MonRunIOV::setRunIOV ( RunIOV  iov  ) 

Definition at line 53 of file MonRunIOV.cc.

References IUniqueDBObject::m_ID, and m_runIOV.

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

00054 {
00055   if (iov != m_runIOV) {
00056     m_ID = 0;
00057     m_runIOV = iov;
00058   }
00059 }

void MonRunIOV::setSubRunEnd ( Tm  end  ) 

Definition at line 101 of file MonRunIOV.cc.

References IUniqueDBObject::m_ID, and m_subRunEnd.

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

00102 {
00103   if (end != m_subRunEnd) {
00104     m_ID = 0;
00105     m_subRunEnd = end;
00106   }
00107 }

void MonRunIOV::setSubRunNumber ( subrun_t  subrun  ) 

Definition at line 67 of file MonRunIOV.cc.

References IUniqueDBObject::m_ID, and m_subRunNum.

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

00068 {
00069   if (subrun != m_subRunNum) {
00070     m_ID = 0;
00071     m_subRunNum = subrun;
00072   }
00073 }

void MonRunIOV::setSubRunStart ( Tm  start  ) 

Definition at line 84 of file MonRunIOV.cc.

References IUniqueDBObject::m_ID, and m_subRunStart.

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

00085 {
00086   if (start != m_subRunStart) {
00087     m_ID = 0;
00088     m_subRunStart = start;
00089   }
00090 }

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

Definition at line 216 of file MonRunIOV.cc.

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

00218 {
00219   this->checkConnection();
00220 
00221   // Check if this IOV has already been written
00222   if (this->fetchID()) {
00223     return m_ID;
00224   }
00225 
00226   // fetch Parent IDs
00227   int monRunTagID, runIOVID;
00228   this->fetchParentIDs(&monRunTagID, &runIOVID);
00229                        
00230   if (!monRunTagID) {
00231     monRunTagID = m_monRunTag.writeDB();
00232   }
00233   
00234   // Validate the data, use infinity-till convention
00235   DateHandler dh(m_env, m_conn);
00236 
00237   if (m_subRunStart.isNull()) {
00238     throw(runtime_error("MonRunIOV::writeDB:  Must setSubRunStart before writing"));
00239   }
00240   
00241   if (m_subRunEnd.isNull()) {
00242     m_subRunEnd = dh.getPlusInfTm();
00243   }
00244 
00245   try {
00246     Statement* stmt = m_conn->createStatement();
00247     
00248     stmt->setSQL("INSERT INTO mon_run_iov (iov_id, tag_id, run_iov_id, subrun_num, subrun_start, subrun_end) "
00249                  "VALUES (mon_run_iov_sq.NextVal, :1, :2, :3, :4, :5)");
00250     stmt->setInt(1, monRunTagID);
00251     stmt->setInt(2, runIOVID);
00252     stmt->setInt(3, m_subRunNum);
00253     stmt->setDate(4, dh.tmToDate(m_subRunStart));
00254     stmt->setDate(5, dh.tmToDate(m_subRunEnd));
00255 
00256     stmt->executeUpdate();
00257 
00258     m_conn->terminateStatement(stmt);
00259   } catch (SQLException &e) {
00260     throw(runtime_error("MonRunIOV::writeDB:  "+e.getMessage()));
00261   }
00262 
00263   // Now get the ID
00264   if (!this->fetchID()) {
00265     throw(runtime_error("MonRunIOV::writeDB:  Failed to write"));
00266   }
00267   
00268   return m_ID;
00269 }


Friends And Related Function Documentation

friend class EcalCondDBInterface [friend]

Reimplemented from IDBObject.

Definition at line 16 of file MonRunIOV.h.


Member Data Documentation

MonRunTag MonRunIOV::m_monRunTag [private]

Definition at line 54 of file MonRunIOV.h.

Referenced by fetchParentIDs(), getMonRunTag(), MonRunIOV(), operator==(), setByID(), setByRun(), setMonRunTag(), and writeDB().

RunIOV MonRunIOV::m_runIOV [private]

Definition at line 55 of file MonRunIOV.h.

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

Tm MonRunIOV::m_subRunEnd [private]

Definition at line 58 of file MonRunIOV.h.

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

subrun_t MonRunIOV::m_subRunNum [private]

Definition at line 56 of file MonRunIOV.h.

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

Tm MonRunIOV::m_subRunStart [private]

Definition at line 57 of file MonRunIOV.h.

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


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