CMS 3D CMS Logo

RunIOV Class Reference

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

Inheritance diagram for RunIOV:

IIOV IUniqueDBObject IDBObject

List of all members.

Public Member Functions

int fetchID () throw (std::runtime_error)
int getID ()
Tm getRunEnd () const
run_t getRunNumber () const
Tm getRunStart () const
RunTag getRunTag () const
bool operator!= (const RunIOV &r) const
bool operator== (const RunIOV &r) const
 RunIOV ()
void setByID (int id) throw (std::runtime_error)
void setID (int id)
void setRunEnd (Tm end)
void setRunNumber (run_t run)
void setRunStart (Tm start)
void setRunTag (RunTag tag)
 ~RunIOV ()

Private Member Functions

void setByRecentData (std::string dataTable, std::string location, run_t run) throw (std::runtime_error)
void setByRecentData (std::string dataTable, RunTag *tag, run_t run=(unsigned int)-1) throw (std::runtime_error)
void setByRun (std::string location, run_t run) throw (std::runtime_error)
void setByRun (RunTag *tag, run_t run) throw (std::runtime_error)
int updateEndTimeDB () throw (std::runtime_error)
int writeDB () throw (std::runtime_error)

Private Attributes

Tm m_runEnd
run_t m_runNum
Tm m_runStart
RunTag m_runTag

Friends

class EcalCondDBInterface


Detailed Description

Definition at line 13 of file RunIOV.h.


Constructor & Destructor Documentation

RunIOV::RunIOV (  ) 

Definition at line 12 of file RunIOV.cc.

References IDBObject::m_conn, IUniqueDBObject::m_ID, m_runEnd, m_runNum, m_runStart, and NULL.

00013 {
00014   m_conn = NULL;
00015   m_ID = 0;
00016   m_runNum = 0;
00017   m_runStart = Tm();
00018   m_runEnd = Tm();
00019 }

RunIOV::~RunIOV (  ) 

Definition at line 23 of file RunIOV.cc.

00024 {
00025 }


Member Function Documentation

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

Implements IUniqueDBObject.

Definition at line 103 of file RunIOV.cc.

References IDBObject::checkConnection(), e, RunTag::fetchID(), DateHandler::getPlusInfTm(), Tm::isNull(), IDBObject::m_conn, IDBObject::m_env, IUniqueDBObject::m_ID, m_runEnd, m_runNum, m_runStart, m_runTag, IDBObject::setConnection(), and DateHandler::tmToDate().

Referenced by LMFRunIOV::fetchParentIDs(), and MonRunIOV::fetchParentIDs().

00105 {
00106   // Return from memory if available
00107   if (m_ID) {
00108     return m_ID;
00109   }
00110 
00111   this->checkConnection();
00112 
00113   m_runTag.setConnection(m_env, m_conn);
00114   int tagID = m_runTag.fetchID();
00115   if (!tagID) { 
00116     return 0;
00117   }
00118 
00119   DateHandler dh(m_env, m_conn);
00120 
00121   if (m_runEnd.isNull()) {
00122     m_runEnd = dh.getPlusInfTm();
00123   }
00124 
00125   try {
00126     Statement* stmt = m_conn->createStatement();
00127     stmt->setSQL("SELECT iov_id FROM run_iov "
00128                  "WHERE tag_id = :tag_id AND "
00129                  "run_num = :run_num AND "
00130                  "run_start = :run_start  " );
00131     stmt->setInt(1, tagID);
00132     stmt->setInt(2, m_runNum);
00133     stmt->setDate(3, dh.tmToDate(m_runStart));
00134   
00135     ResultSet* rset = stmt->executeQuery();
00136 
00137     if (rset->next()) {
00138       m_ID = rset->getInt(1);
00139     } else {
00140       m_ID = 0;
00141     }
00142     m_conn->terminateStatement(stmt);
00143   } catch (SQLException &e) {
00144     throw(runtime_error("RunIOV::fetchID:  "+e.getMessage()));
00145   }
00146 
00147   return m_ID;
00148 }

int RunIOV::getID (  )  [inline]

Definition at line 33 of file RunIOV.h.

References IUniqueDBObject::m_ID.

00033 { return m_ID;} ;

Tm RunIOV::getRunEnd (  )  const

Definition at line 79 of file RunIOV.cc.

References m_runEnd.

Referenced by EcalEndcapMonitorClient::beginRunDb(), EcalBarrelMonitorClient::beginRunDb(), EcalEndcapMonitorClient::defaultWebPage(), EcalBarrelMonitorClient::defaultWebPage(), and EcalTPGDBApp::printIOV().

00080 {
00081   return m_runEnd;
00082 }

run_t RunIOV::getRunNumber (  )  const

Definition at line 45 of file RunIOV.cc.

References m_runNum.

Referenced by EcalEndcapMonitorClient::beginRunDb(), EcalBarrelMonitorClient::beginRunDb(), EcalEndcapMonitorClient::defaultWebPage(), EcalBarrelMonitorClient::defaultWebPage(), EcalTPGDBApp::printIOV(), and EcalErrorMask::readDB().

00046 {
00047   return m_runNum;
00048 }

Tm RunIOV::getRunStart (  )  const

Definition at line 62 of file RunIOV.cc.

References m_runStart.

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

00063 {
00064   return m_runStart;
00065 }

RunTag RunIOV::getRunTag (  )  const

Definition at line 96 of file RunIOV.cc.

References m_runTag.

Referenced by EcalEndcapMonitorClient::beginRunDb(), EcalBarrelMonitorClient::beginRunDb(), EcalEndcapMonitorClient::defaultWebPage(), EcalBarrelMonitorClient::defaultWebPage(), EcalTPGDBApp::printIOV(), and EcalPedOffset::writeDb().

00097 {
00098   return m_runTag;
00099 }

bool RunIOV::operator!= ( const RunIOV r  )  const [inline]

Definition at line 47 of file RunIOV.h.

00047 { return !(*this == r); }

bool RunIOV::operator== ( const RunIOV r  )  const [inline]

Definition at line 39 of file RunIOV.h.

References m_runEnd, m_runNum, m_runStart, and m_runTag.

00040     {
00041       return (m_runNum   == r.m_runNum &&
00042               m_runStart == r.m_runStart &&
00043               m_runEnd   == r.m_runEnd &&
00044               m_runTag   == r.m_runTag);
00045     }

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

Implements IUniqueDBObject.

Definition at line 152 of file RunIOV.cc.

References IDBObject::checkConnection(), DateHandler::dateToTm(), e, id, IDBObject::m_conn, IDBObject::m_env, IUniqueDBObject::m_ID, m_runEnd, m_runNum, m_runStart, m_runTag, RunTag::setByID(), and IDBObject::setConnection().

Referenced by MonRunIOV::setByID(), LMFRunIOV::setByID(), setByRecentData(), and setByRun().

00154 {
00155    this->checkConnection();
00156 
00157    DateHandler dh(m_env, m_conn);
00158 
00159    try {
00160      Statement* stmt = m_conn->createStatement();
00161 
00162      stmt->setSQL("SELECT tag_id, run_num, run_start, run_end FROM run_iov WHERE iov_id = :1");
00163      stmt->setInt(1, id);
00164      
00165      ResultSet* rset = stmt->executeQuery();
00166      if (rset->next()) {
00167        int tagID = rset->getInt(1);
00168        m_runNum = rset->getInt(2);
00169        Date startDate = rset->getDate(3);
00170        Date endDate = rset->getDate(4);
00171          
00172        m_runStart = dh.dateToTm( startDate );
00173        m_runEnd = dh.dateToTm( endDate );
00174 
00175        m_runTag.setConnection(m_env, m_conn);
00176        m_runTag.setByID(tagID);
00177        m_ID = id;
00178      } else {
00179        throw(runtime_error("RunIOV::setByID:  Given tag_id is not in the database"));
00180      }
00181      
00182      m_conn->terminateStatement(stmt);
00183    } catch (SQLException &e) {
00184      throw(runtime_error("RunIOV::setByID:  "+e.getMessage()));
00185    }
00186 }

void RunIOV::setByRecentData ( std::string  dataTable,
std::string  location,
run_t  run 
) throw (std::runtime_error) [private]

Definition at line 416 of file RunIOV.cc.

References IDBObject::checkConnection(), e, IDBObject::m_conn, IDBObject::m_env, mergeAndRegister_online::run, and setByID().

00418 {
00419   this->checkConnection();
00420    
00421   DateHandler dh(m_env, m_conn);
00422 
00423    try {
00424      Statement* stmt = m_conn->createStatement();
00425 
00426      stmt->setSQL("SELECT * FROM (SELECT riov.iov_id, riov.run_num, riov.run_start, riov.run_end "
00427                   "FROM run_iov riov "
00428                   "JOIN "+dataTable+" dat on dat.iov_id = riov.iov_id "
00429                   "JOIN run_tag rtag ON riov.tag_id = rtag.tag_id "
00430                   "JOIN location_def loc ON rtag.location_id = loc.def_id "
00431                   "WHERE loc.location = :1 AND riov.run_num <= :2 ORDER BY riov.run_num DESC ) WHERE rownum = 1");
00432 
00433      stmt->setString(1, location);
00434      stmt->setInt(2, run);
00435      
00436      ResultSet* rset = stmt->executeQuery();
00437     
00438 
00439      if (rset->next()) {
00440        int id = rset->getInt(1);
00441        this->setByID(id);
00442      } else {
00443        throw(runtime_error("RunIOV::setByRecentData(datatable, loc, run):  Given run is not in the database"));
00444      }
00445 
00446      
00447      m_conn->terminateStatement(stmt);
00448    } catch (SQLException &e) {
00449      throw(runtime_error("RunIOV::setByRecentData:  "+e.getMessage()));
00450    }
00451 }

void RunIOV::setByRecentData ( std::string  dataTable,
RunTag tag,
run_t  run = (unsigned int)-1 
) throw (std::runtime_error) [private]

Definition at line 366 of file RunIOV.cc.

References IDBObject::checkConnection(), DateHandler::dateToTm(), e, IDBObject::m_conn, IDBObject::m_env, IUniqueDBObject::m_ID, m_runEnd, m_runNum, m_runStart, m_runTag, mergeAndRegister_online::run, and ecalRecalibSequence_cff::tag.

00368 {
00369    this->checkConnection();
00370 
00371    tag->setConnection(m_env, m_conn);
00372    int tagID = tag->fetchID();
00373    if (!tagID) {
00374      throw(runtime_error("RunIOV::setByRecentData:  Given tag is not in the database"));
00375    }
00376    
00377    DateHandler dh(m_env, m_conn);
00378 
00379    try {
00380      Statement* stmt = m_conn->createStatement();
00381 
00382      stmt->setSQL("SELECT * FROM (SELECT riov.iov_id, riov.run_num, riov.run_start, riov.run_end "
00383                   "FROM run_iov riov "
00384                   "JOIN "+dataTable+" dat on dat.iov_id = riov.iov_id "
00385                   "WHERE tag_id = :1 AND riov.run_num <= :run ORDER BY riov.run_num DESC) WHERE rownum = 1");
00386 
00387      stmt->setInt(1, tagID);
00388      stmt->setInt(2, run);
00389      
00390      ResultSet* rset = stmt->executeQuery();
00391      if (rset->next()) {
00392        m_runTag = *tag;
00393 
00394        m_ID = rset->getInt(1);
00395        m_runNum = rset->getInt(2);
00396        Date startDate = rset->getDate(3);
00397        Date endDate = rset->getDate(4);
00398          
00399        m_runStart = dh.dateToTm( startDate );
00400        m_runEnd = dh.dateToTm( endDate );
00401      } else {
00402        throw(runtime_error("RunIOV::setByRecentData:  No data exists for given tag and run"));
00403      }
00404      
00405      m_conn->terminateStatement(stmt);
00406    } catch (SQLException &e) {
00407      throw(runtime_error("RunIOV::setByRecentData:  "+e.getMessage()));
00408    }
00409 }

void RunIOV::setByRun ( std::string  location,
run_t  run 
) throw (std::runtime_error) [private]

Definition at line 329 of file RunIOV.cc.

References IDBObject::checkConnection(), e, IDBObject::m_conn, IDBObject::m_env, mergeAndRegister_online::run, and setByID().

00331 {
00332   this->checkConnection();
00333    
00334   DateHandler dh(m_env, m_conn);
00335 
00336    try {
00337      Statement* stmt = m_conn->createStatement();
00338 
00339      stmt->setSQL("SELECT iov_id FROM run_iov riov "
00340                   "JOIN run_tag rtag ON riov.tag_id = rtag.tag_id "
00341                   "JOIN location_def loc ON rtag.location_id = loc.def_id "
00342                   "WHERE loc.location = :1 AND riov.run_num = :2");
00343      stmt->setString(1, location);
00344      stmt->setInt(2, run);
00345      
00346      ResultSet* rset = stmt->executeQuery();
00347      if (rset->next()) {
00348        int id = rset->getInt(1);
00349        this->setByID(id);
00350      } else {
00351        throw(runtime_error("RunIOV::setByRun(loc, run):  Given run is not in the database"));
00352      }
00353      
00354      // Check for uniqueness of run
00355      if (rset->next()) {
00356        throw(runtime_error("RunIOV::setByRun(loc, run):  Run is nonunique for given location."));
00357      }
00358 
00359      m_conn->terminateStatement(stmt);
00360    } catch (SQLException &e) {
00361      throw(runtime_error("RunIOV::setByRun(loc, run):  "+e.getMessage()));
00362    }
00363 }

void RunIOV::setByRun ( RunTag tag,
run_t  run 
) throw (std::runtime_error) [private]

Definition at line 286 of file RunIOV.cc.

References IDBObject::checkConnection(), DateHandler::dateToTm(), e, IDBObject::m_conn, IDBObject::m_env, IUniqueDBObject::m_ID, m_runEnd, m_runNum, m_runStart, m_runTag, mergeAndRegister_online::run, and ecalRecalibSequence_cff::tag.

Referenced by EcalCondDBInterface::fetchRunIOV().

00288 {
00289    this->checkConnection();
00290 
00291    tag->setConnection(m_env, m_conn);
00292    int tagID = tag->fetchID();
00293    if (!tagID) {
00294      throw(runtime_error("RunIOV::setByRun:  Given tag is not in the database"));
00295    }
00296    
00297    DateHandler dh(m_env, m_conn);
00298 
00299    try {
00300      Statement* stmt = m_conn->createStatement();
00301 
00302      stmt->setSQL("SELECT iov_id, run_start, run_end FROM run_iov WHERE tag_id = :1 AND run_num = :2");
00303      stmt->setInt(1, tagID);
00304      stmt->setInt(2, run);
00305      
00306      ResultSet* rset = stmt->executeQuery();
00307      if (rset->next()) {
00308        m_runTag = *tag;
00309        m_runNum = run;
00310 
00311        m_ID = rset->getInt(1);
00312        Date startDate = rset->getDate(2);
00313        Date endDate = rset->getDate(3);
00314          
00315        m_runStart = dh.dateToTm( startDate );
00316        m_runEnd = dh.dateToTm( endDate );
00317      } else {
00318        throw(runtime_error("RunIOV::setByRun:  Given run is not in the database"));
00319      }
00320      
00321      m_conn->terminateStatement(stmt);
00322    } catch (SQLException &e) {
00323      throw(runtime_error("RunIOV::setByRun:  "+e.getMessage()));
00324    }
00325 }

void RunIOV::setID ( int  id  ) 

Definition at line 37 of file RunIOV.cc.

References IUniqueDBObject::m_ID.

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

00038 {
00039      m_ID = id;
00040    }

void RunIOV::setRunEnd ( Tm  end  ) 

Definition at line 69 of file RunIOV.cc.

References IUniqueDBObject::m_ID, and m_runEnd.

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

00070 {
00071   if (end != m_runEnd) {
00072     m_ID = 0;
00073     m_runEnd = end;
00074   }
00075 }

void RunIOV::setRunNumber ( run_t  run  ) 

Definition at line 29 of file RunIOV.cc.

References IUniqueDBObject::m_ID, and m_runNum.

Referenced by EcalEndcapMonitorClient::beginRunDb(), EcalBarrelMonitorClient::beginRunDb(), MonRunList::fetchLastNRuns(), LMFRunList::fetchLastNRuns(), MonRunList::fetchRuns(), RunList::fetchRuns(), and LMFRunList::fetchRuns().

00030 {
00031   if ( run != m_runNum) {
00032     m_ID = 0;
00033     m_runNum = run;
00034   }
00035 }

void RunIOV::setRunStart ( Tm  start  ) 

Definition at line 52 of file RunIOV.cc.

References IUniqueDBObject::m_ID, and m_runStart.

Referenced by EcalEndcapMonitorClient::beginRunDb(), EcalBarrelMonitorClient::beginRunDb(), MonRunList::fetchLastNRuns(), LMFRunList::fetchLastNRuns(), MonRunList::fetchRuns(), RunList::fetchRuns(), and LMFRunList::fetchRuns().

00053 {
00054   if (start != m_runStart) {
00055     m_ID = 0;
00056     m_runStart = start;
00057   }
00058 }

void RunIOV::setRunTag ( RunTag  tag  ) 

Definition at line 86 of file RunIOV.cc.

References IUniqueDBObject::m_ID, and m_runTag.

Referenced by EcalEndcapMonitorClient::beginRunDb(), EcalBarrelMonitorClient::beginRunDb(), MonRunList::fetchLastNRuns(), LMFRunList::fetchLastNRuns(), MonRunList::fetchRuns(), RunList::fetchRuns(), and LMFRunList::fetchRuns().

00087 {
00088   if (tag != m_runTag) {
00089     m_ID = 0;
00090     m_runTag = tag;
00091   }
00092 }

int RunIOV::updateEndTimeDB (  )  throw (std::runtime_error) [private]

Definition at line 240 of file RunIOV.cc.

References IDBObject::checkConnection(), e, DateHandler::getPlusInfTm(), Tm::isNull(), IDBObject::m_conn, IDBObject::m_env, IUniqueDBObject::m_ID, m_runEnd, m_runTag, IDBObject::setConnection(), DateHandler::tmToDate(), writeDB(), and RunTag::writeDB().

00242 {
00243   this->checkConnection();
00244 
00245   // Check if this IOV has already been written
00246   if(!this->fetchID()){
00247     this->writeDB();
00248   }
00249 
00250 
00251   m_runTag.setConnection(m_env, m_conn);
00252   int tagID = m_runTag.writeDB();
00253   
00254   // Validate the data, use infinity-till convention
00255   DateHandler dh(m_env, m_conn);
00256 
00257   // we only update the run end here   
00258   if (m_runEnd.isNull()) {
00259     m_runEnd = dh.getPlusInfTm();
00260   }
00261 
00262   try {
00263     Statement* stmt = m_conn->createStatement();
00264     
00265     stmt->setSQL("UPDATE run_iov set run_end=:1 where iov_id=:2 " );
00266     stmt->setDate(1, dh.tmToDate(m_runEnd));
00267     stmt->setInt(2, m_ID);
00268 
00269     stmt->executeUpdate();
00270 
00271     m_conn->terminateStatement(stmt);
00272   } catch (SQLException &e) {
00273     throw(runtime_error("RunIOV::writeDB:  "+e.getMessage()));
00274   }
00275 
00276   // Now get the ID
00277   if (!this->fetchID()) {
00278     throw(runtime_error("RunIOV::writeDB:  Failed to write"));
00279   }
00280   
00281   return m_ID;
00282 }

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

Definition at line 190 of file RunIOV.cc.

References IDBObject::checkConnection(), e, DateHandler::getPlusInfTm(), Tm::isNull(), IDBObject::m_conn, IDBObject::m_env, IUniqueDBObject::m_ID, m_runEnd, m_runNum, m_runStart, m_runTag, IDBObject::setConnection(), DateHandler::tmToDate(), and RunTag::writeDB().

Referenced by updateEndTimeDB().

00192 {
00193   this->checkConnection();
00194 
00195   // Check if this IOV has already been written
00196   if (this->fetchID()) {
00197     return m_ID;
00198   }
00199   
00200   m_runTag.setConnection(m_env, m_conn);
00201   int tagID = m_runTag.writeDB();
00202   
00203   // Validate the data, use infinity-till convention
00204   DateHandler dh(m_env, m_conn);
00205 
00206   if (m_runStart.isNull()) {
00207     throw(runtime_error("RunIOV::writeDB:  Must setRunStart before writing"));
00208   }
00209   
00210   if (m_runEnd.isNull()) {
00211     m_runEnd = dh.getPlusInfTm();
00212   }
00213 
00214   try {
00215     Statement* stmt = m_conn->createStatement();
00216     
00217     stmt->setSQL("INSERT INTO run_iov (iov_id, tag_id, run_num, run_start, run_end) "
00218                  "VALUES (run_iov_sq.NextVal, :1, :2, :3, :4)");
00219     stmt->setInt(1, tagID);
00220     stmt->setInt(2, m_runNum);
00221     stmt->setDate(3, dh.tmToDate(m_runStart));
00222     stmt->setDate(4, dh.tmToDate(m_runEnd));
00223 
00224     stmt->executeUpdate();
00225 
00226     m_conn->terminateStatement(stmt);
00227   } catch (SQLException &e) {
00228     throw(runtime_error("RunIOV::writeDB:  "+e.getMessage()));
00229   }
00230 
00231   // Now get the ID
00232   if (!this->fetchID()) {
00233     throw(runtime_error("RunIOV::writeDB:  Failed to write"));
00234   }
00235   
00236   return m_ID;
00237 }


Friends And Related Function Documentation

friend class EcalCondDBInterface [friend]

Reimplemented from IDBObject.

Definition at line 15 of file RunIOV.h.


Member Data Documentation

Tm RunIOV::m_runEnd [private]

Definition at line 53 of file RunIOV.h.

Referenced by fetchID(), getRunEnd(), operator==(), RunIOV(), setByID(), setByRecentData(), setByRun(), setRunEnd(), updateEndTimeDB(), and writeDB().

run_t RunIOV::m_runNum [private]

Definition at line 51 of file RunIOV.h.

Referenced by fetchID(), getRunNumber(), operator==(), RunIOV(), setByID(), setByRecentData(), setByRun(), setRunNumber(), and writeDB().

Tm RunIOV::m_runStart [private]

Definition at line 52 of file RunIOV.h.

Referenced by fetchID(), getRunStart(), operator==(), RunIOV(), setByID(), setByRecentData(), setByRun(), setRunStart(), and writeDB().

RunTag RunIOV::m_runTag [private]

Definition at line 54 of file RunIOV.h.

Referenced by fetchID(), getRunTag(), operator==(), setByID(), setByRecentData(), setByRun(), setRunTag(), updateEndTimeDB(), and writeDB().


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