#include <OnlineDB/EcalCondDB/interface/DCUIOV.h>
Public Member Functions | |
DCUIOV () | |
int | fetchID () throw (std::runtime_error) |
DCUTag | getDCUTag () const |
int | getID () |
Tm | getSince () const |
Tm | getTill () const |
bool | operator!= (const DCUIOV &m) const |
bool | operator== (const DCUIOV &m) const |
void | setByID (int id) throw (std::runtime_error) |
void | setDCUTag (DCUTag tag) |
void | setSince (Tm since) |
void | setTill (Tm till) |
~DCUIOV () | |
Private Member Functions | |
void | setByTm (DCUTag *tag, Tm time) throw (std::runtime_error) |
int | writeDB () throw (std::runtime_error) |
Private Attributes | |
DCUTag | m_dcuTag |
Tm | m_since |
Tm | m_till |
Friends | |
class | EcalCondDBInterface |
Definition at line 13 of file DCUIOV.h.
DCUIOV::DCUIOV | ( | ) |
int DCUIOV::fetchID | ( | ) | throw (std::runtime_error) [virtual] |
Implements IUniqueDBObject.
Definition at line 79 of file DCUIOV.cc.
References IDBObject::checkConnection(), e, DCUTag::fetchID(), DateHandler::getPlusInfTm(), Tm::isNull(), IDBObject::m_conn, m_dcuTag, 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_dcuTag.setConnection(m_env, m_conn); 00090 int tagID = m_dcuTag.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 dcu_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("DCUIOV::fetchID: "+e.getMessage())); 00121 } 00122 00123 return m_ID; 00124 }
DCUTag DCUIOV::getDCUTag | ( | ) | const |
int DCUIOV::getID | ( | ) | [inline] |
Tm DCUIOV::getSince | ( | ) | const |
Tm DCUIOV::getTill | ( | ) | const |
Implements IUniqueDBObject.
Definition at line 128 of file DCUIOV.cc.
References IDBObject::checkConnection(), DateHandler::dateToTm(), e, id, IDBObject::m_conn, m_dcuTag, IDBObject::m_env, IUniqueDBObject::m_ID, m_since, m_till, DCUTag::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 dcu_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_dcuTag.setConnection(m_env, m_conn); 00151 m_dcuTag.setByID(tagID); 00152 m_ID = id; 00153 } else { 00154 throw(runtime_error("DCUTag::setByID: Given tag_id is not in the database")); 00155 } 00156 00157 m_conn->terminateStatement(stmt); 00158 } catch (SQLException &e) { 00159 throw(runtime_error("DCUTag::setByID: "+e.getMessage())); 00160 } 00161 }
Definition at line 215 of file DCUIOV.cc.
References IDBObject::checkConnection(), DateHandler::dateToTm(), e, IDBObject::m_conn, m_dcuTag, IDBObject::m_env, IUniqueDBObject::m_ID, m_since, m_till, ecalRecalibSequence_cff::tag, and DateHandler::tmToDate().
Referenced by EcalCondDBInterface::fetchDCUIOV().
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("DCUIOV::setByTm: Given DCUTag 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 dcu_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_dcuTag = *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("DCUIOV::setByTm: Given subrun is not in the database")); 00253 } 00254 00255 m_conn->terminateStatement(stmt); 00256 } catch (SQLException &e) { 00257 throw(runtime_error("DCUIOV::setByTm: "+e.getMessage())); 00258 } 00259 }
int DCUIOV::writeDB | ( | ) | throw (std::runtime_error) [private] |
Definition at line 165 of file DCUIOV.cc.
References IDBObject::checkConnection(), e, DateHandler::getPlusInfTm(), Tm::isNull(), IDBObject::m_conn, m_dcuTag, IDBObject::m_env, IUniqueDBObject::m_ID, m_since, m_till, IDBObject::setConnection(), DateHandler::tmToDate(), and DCUTag::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_dcuTag.setConnection(m_env, m_conn); 00176 int tagID = m_dcuTag.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("DCUIOV::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 dcu_iov (iov_id, tag_id, since, till) " 00193 "VALUES (dcu_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("DCUIOV::writeDB: "+e.getMessage())); 00203 } 00204 00205 // Now get the ID 00206 if (!this->fetchID()) { 00207 throw(runtime_error("DCUIOV::writeDB: Failed to write")); 00208 } 00209 00210 return m_ID; 00211 }
friend class EcalCondDBInterface [friend] |
DCUTag DCUIOV::m_dcuTag [private] |
Definition at line 48 of file DCUIOV.h.
Referenced by fetchID(), getDCUTag(), operator==(), setByID(), setByTm(), setDCUTag(), and writeDB().
Tm DCUIOV::m_since [private] |
Definition at line 46 of file DCUIOV.h.
Referenced by DCUIOV(), fetchID(), getSince(), operator==(), setByID(), setByTm(), setSince(), and writeDB().
Tm DCUIOV::m_till [private] |