CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes | Friends
DCUIOV Class Reference

#include <DCUIOV.h>

Inheritance diagram for DCUIOV:
IIOV IUniqueDBObject IDBObject

Public Member Functions

 DCUIOV ()
 
int fetchID () noexcept(false) override
 
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) noexcept(false) override
 
void setDCUTag (const DCUTag &tag)
 
void setSince (const Tm &since)
 
void setTill (const Tm &till)
 
 ~DCUIOV () override
 
- Public Member Functions inherited from IDBObject
oracle::occi::Connection * getConn () const
 
oracle::occi::Environment * getEnv () const
 
void setConnection (oracle::occi::Environment *env, oracle::occi::Connection *conn)
 
virtual ~IDBObject ()
 

Private Member Functions

void setByTm (DCUTag *tag, const Tm &time) noexcept(false)
 
int writeDB () noexcept(false)
 

Private Attributes

DCUTag m_dcuTag
 
Tm m_since
 
Tm m_till
 

Friends

class EcalCondDBInterface
 

Additional Inherited Members

- Static Public Attributes inherited from IDBObject
static int const ECALDB_NROWS =1024
 
- Protected Member Functions inherited from IDBObject
void checkConnection () const noexcept(false)
 
- Protected Attributes inherited from IUniqueDBObject
int m_ID
 
- Protected Attributes inherited from IDBObject
oracle::occi::Connection * m_conn
 
oracle::occi::Environment * m_env
 

Detailed Description

Definition at line 13 of file DCUIOV.h.

Constructor & Destructor Documentation

DCUIOV::DCUIOV ( )

Definition at line 12 of file DCUIOV.cc.

13 {
14  m_conn = nullptr;
15  m_ID = 0;
16  m_since = Tm();
17  m_till = Tm();
18 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
Tm m_till
Definition: DCUIOV.h:47
Tm m_since
Definition: DCUIOV.h:46
Definition: Tm.h:13
DCUIOV::~DCUIOV ( )
override

Definition at line 22 of file DCUIOV.cc.

23 {
24 }

Member Function Documentation

int DCUIOV::fetchID ( )
overridevirtualnoexcept

Implements IUniqueDBObject.

Definition at line 79 of file DCUIOV.cc.

References cuy::dh, MillePedeFileConverter_cfg::e, DateHandler::getPlusInfTm(), AlCaHLTBitMon_QueryRunRegistry::string, and DateHandler::tmToDate().

Referenced by getID(), EcalCondDBInterface::insertDataArraySet(), and EcalCondDBInterface::insertDataSet().

81 {
82  // Return from memory if available
83  if (m_ID) {
84  return m_ID;
85  }
86 
87  this->checkConnection();
88 
90  int tagID = m_dcuTag.fetchID();
91  if (!tagID) {
92  return 0;
93  }
94 
96 
97  if (m_till.isNull()) {
98  m_till = dh.getPlusInfTm();
99  }
100 
101  try {
102  Statement* stmt = m_conn->createStatement();
103  stmt->setSQL("SELECT iov_id FROM dcu_iov "
104  "WHERE tag_id = :tag_id AND "
105  "since = :since ");
106  stmt->setInt(1, tagID);
107  stmt->setDate(2, dh.tmToDate(m_since));
108  // stmt->setDate(3, dh.tmToDate(m_till));
109 
110  ResultSet* rset = stmt->executeQuery();
111 
112  if (rset->next()) {
113  m_ID = rset->getInt(1);
114  } else {
115  m_ID = 0;
116  }
117  m_conn->terminateStatement(stmt);
118  } catch (SQLException &e) {
119  throw(std::runtime_error(std::string("DCUIOV::fetchID: ")+getOraMessage(&e)));
120  }
121 
122  return m_ID;
123 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
Tm m_till
Definition: DCUIOV.h:47
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
Tm m_since
Definition: DCUIOV.h:46
int fetchID() noexcept(false) override
Definition: DCUTag.cc:62
int isNull() const
Definition: Tm.cc:63
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
dh
Definition: cuy.py:353
DCUTag m_dcuTag
Definition: DCUIOV.h:48
DCUTag DCUIOV::getDCUTag ( ) const

Definition at line 72 of file DCUIOV.cc.

73 {
74  return m_dcuTag;
75 }
DCUTag m_dcuTag
Definition: DCUIOV.h:48
int DCUIOV::getID ( )
inline
Tm DCUIOV::getSince ( ) const

Definition at line 38 of file DCUIOV.cc.

39 {
40  return m_since;
41 }
Tm m_since
Definition: DCUIOV.h:46
Tm DCUIOV::getTill ( ) const

Definition at line 55 of file DCUIOV.cc.

56 {
57  return m_till;
58 }
Tm m_till
Definition: DCUIOV.h:47
bool DCUIOV::operator!= ( const DCUIOV m) const
inline

Definition at line 41 of file DCUIOV.h.

References funct::m.

41 { return !(*this == m); }
bool DCUIOV::operator== ( const DCUIOV m) const
inline

Definition at line 34 of file DCUIOV.h.

References m_dcuTag, m_since, and m_till.

35  {
36  return ( m_dcuTag == m.m_dcuTag &&
37  m_since == m.m_since &&
38  m_till == m.m_till );
39  }
Tm m_till
Definition: DCUIOV.h:47
Tm m_since
Definition: DCUIOV.h:46
DCUTag m_dcuTag
Definition: DCUIOV.h:48
void DCUIOV::setByID ( int  id)
overridevirtualnoexcept

Implements IUniqueDBObject.

Definition at line 127 of file DCUIOV.cc.

References DateHandler::dateToTm(), cuy::dh, MillePedeFileConverter_cfg::e, triggerObjects_cff::id, ntuplemaker::since, AlCaHLTBitMon_QueryRunRegistry::string, and ntuplemaker::till.

Referenced by getID().

129 {
130  this->checkConnection();
131 
133 
134  try {
135  Statement* stmt = m_conn->createStatement();
136 
137  stmt->setSQL("SELECT tag_id, since, till FROM dcu_iov WHERE iov_id = :1");
138  stmt->setInt(1, id);
139 
140  ResultSet* rset = stmt->executeQuery();
141  if (rset->next()) {
142  int tagID = rset->getInt(1);
143  Date since = rset->getDate(2);
144  Date till = rset->getDate(3);
145 
146  m_since = dh.dateToTm( since );
147  m_till = dh.dateToTm( till );
148 
150  m_dcuTag.setByID(tagID);
151  m_ID = id;
152  } else {
153  throw(std::runtime_error("DCUTag::setByID: Given tag_id is not in the database"));
154  }
155 
156  m_conn->terminateStatement(stmt);
157  } catch (SQLException &e) {
158  throw(std::runtime_error(std::string("DCUTag::setByID: ")+getOraMessage(&e)));
159  }
160 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
Tm m_till
Definition: DCUIOV.h:47
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
Tm m_since
Definition: DCUIOV.h:46
void setByID(int id) noexcept(false) override
Definition: DCUTag.cc:102
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
dh
Definition: cuy.py:353
DCUTag m_dcuTag
Definition: DCUIOV.h:48
void DCUIOV::setByTm ( DCUTag tag,
const Tm time 
)
privatenoexcept

Definition at line 214 of file DCUIOV.cc.

References DateHandler::dateToTm(), cuy::dh, MillePedeFileConverter_cfg::e, AlCaHLTBitMon_QueryRunRegistry::string, GlobalPosition_Frontier_DevDB_cff::tag, and DateHandler::tmToDate().

Referenced by EcalCondDBInterface::fetchDCUIOV().

216 {
217  this->checkConnection();
218 
219  tag->setConnection(m_env, m_conn);
220  int tagID = tag->fetchID();
221 
222  if (!tagID) {
223  throw(std::runtime_error("DCUIOV::setByTm: Given DCUTag does not exist in the DB"));
224  }
225 
227 
228  Date eventDate = dh.tmToDate(eventTm);
229 
230  try {
231  Statement* stmt = m_conn->createStatement();
232 
233 
234  stmt->setSQL("SELECT iov_id, since, till FROM dcu_iov "
235  "WHERE tag_id = :1 AND since <= :2 AND till > :3");
236  stmt->setInt(1, tagID);
237  stmt->setDate(2, eventDate);
238  stmt->setDate(3, eventDate);
239 
240  ResultSet* rset = stmt->executeQuery();
241  if (rset->next()) {
242  m_dcuTag = *tag;
243 
244  m_ID = rset->getInt(1);
245  Date sinceDate = rset->getDate(2);
246  Date tillDate = rset->getDate(3);
247 
248  m_since = dh.dateToTm( sinceDate );
249  m_till = dh.dateToTm( tillDate );
250  } else {
251  throw(std::runtime_error("DCUIOV::setByTm: Given subrun is not in the database"));
252  }
253 
254  m_conn->terminateStatement(stmt);
255  } catch (SQLException &e) {
256  throw(std::runtime_error(std::string("DCUIOV::setByTm: ")+getOraMessage(&e)));
257  }
258 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
Tm m_till
Definition: DCUIOV.h:47
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
Tm m_since
Definition: DCUIOV.h:46
int fetchID() noexcept(false) override
Definition: DCUTag.cc:62
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
dh
Definition: cuy.py:353
DCUTag m_dcuTag
Definition: DCUIOV.h:48
void DCUIOV::setDCUTag ( const DCUTag tag)

Definition at line 62 of file DCUIOV.cc.

References GlobalPosition_Frontier_DevDB_cff::tag.

63 {
64  if (tag != m_dcuTag) {
65  m_ID = 0;
66  m_dcuTag = tag;
67  }
68 }
DCUTag m_dcuTag
Definition: DCUIOV.h:48
void DCUIOV::setSince ( const Tm since)

Definition at line 28 of file DCUIOV.cc.

References ntuplemaker::since.

29 {
30  if (since != m_since) {
31  m_ID = 0;
32  m_since = since;
33  }
34 }
Tm m_since
Definition: DCUIOV.h:46
void DCUIOV::setTill ( const Tm till)

Definition at line 45 of file DCUIOV.cc.

References ntuplemaker::till.

46 {
47  if (till != m_till) {
48  m_ID = 0;
49  m_till = till;
50  }
51 }
Tm m_till
Definition: DCUIOV.h:47
int DCUIOV::writeDB ( )
privatenoexcept

Definition at line 164 of file DCUIOV.cc.

References cuy::dh, MillePedeFileConverter_cfg::e, DateHandler::getPlusInfTm(), AlCaHLTBitMon_QueryRunRegistry::string, and DateHandler::tmToDate().

Referenced by EcalCondDBInterface::insertDataArraySet(), and EcalCondDBInterface::insertDataSet().

166 {
167  this->checkConnection();
168 
169  // Check if this IOV has already been written
170  if (this->fetchID()) {
171  return m_ID;
172  }
173 
175  int tagID = m_dcuTag.writeDB();
176 
177  // Validate the data, use infinity-till convention
179 
180  if (m_since.isNull()) {
181  throw(std::runtime_error("DCUIOV::writeDB: Must setSince before writing"));
182  }
183 
184  if (m_till.isNull()) {
185  m_till = dh.getPlusInfTm();
186  }
187 
188  try {
189  Statement* stmt = m_conn->createStatement();
190 
191  stmt->setSQL("INSERT INTO dcu_iov (iov_id, tag_id, since, till) "
192  "VALUES (dcu_iov_sq.NextVal, :1, :2, :3)");
193  stmt->setInt(1, tagID);
194  stmt->setDate(2, dh.tmToDate(m_since));
195  stmt->setDate(3, dh.tmToDate(m_till));
196 
197  stmt->executeUpdate();
198 
199  m_conn->terminateStatement(stmt);
200  } catch (SQLException &e) {
201  throw(std::runtime_error(std::string("DCUIOV::writeDB: ")+getOraMessage(&e)));
202  }
203 
204  // Now get the ID
205  if (!this->fetchID()) {
206  throw(std::runtime_error("DCUIOV::writeDB: Failed to write"));
207  }
208 
209  return m_ID;
210 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
Tm m_till
Definition: DCUIOV.h:47
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
Tm m_since
Definition: DCUIOV.h:46
int writeDB() noexcept(false)
Definition: DCUTag.cc:133
int fetchID() noexcept(false) override
Definition: DCUIOV.cc:79
int isNull() const
Definition: Tm.cc:63
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
dh
Definition: cuy.py:353
DCUTag m_dcuTag
Definition: DCUIOV.h:48

Friends And Related Function Documentation

friend class EcalCondDBInterface
friend

Definition at line 15 of file DCUIOV.h.

Member Data Documentation

DCUTag DCUIOV::m_dcuTag
private

Definition at line 48 of file DCUIOV.h.

Referenced by operator==().

Tm DCUIOV::m_since
private

Definition at line 46 of file DCUIOV.h.

Referenced by operator==().

Tm DCUIOV::m_till
private

Definition at line 47 of file DCUIOV.h.

Referenced by operator==().