CMS 3D CMS Logo

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

#include <CaliIOV.h>

Inheritance diagram for CaliIOV:
IIOV IUniqueDBObject IDBObject

Public Member Functions

 CaliIOV ()
 
int fetchID () noexcept(false) override
 
CaliTag getCaliTag () const
 
int getID ()
 
Tm getSince () const
 
Tm getTill () const
 
bool operator!= (const CaliIOV &m) const
 
bool operator== (const CaliIOV &m) const
 
void setByID (int id) noexcept(false) override
 
void setCaliTag (const CaliTag &tag)
 
void setSince (const Tm &since)
 
void setTill (const Tm &till)
 
 ~CaliIOV () 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 (CaliTag *tag, const Tm &time) noexcept(false)
 
int writeDB () noexcept(false)
 

Private Attributes

CaliTag m_caliTag
 
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 CaliIOV.h.

Constructor & Destructor Documentation

CaliIOV::CaliIOV ( )

Definition at line 12 of file CaliIOV.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_since
Definition: CaliIOV.h:48
Tm m_till
Definition: CaliIOV.h:49
Definition: Tm.h:13
CaliIOV::~CaliIOV ( )
override

Definition at line 22 of file CaliIOV.cc.

23 {
24 }

Member Function Documentation

int CaliIOV::fetchID ( )
overridevirtualnoexcept

Implements IUniqueDBObject.

Definition at line 79 of file CaliIOV.cc.

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

Referenced by getID().

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_caliTag.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 cali_iov "
104  "WHERE tag_id = :tag_id AND "
105  "since = :since AND "
106  "till = :till");
107  stmt->setInt(1, tagID);
108  stmt->setDate(2, dh.tmToDate(m_since));
109  stmt->setDate(3, dh.tmToDate(m_till));
110 
111  ResultSet* rset = stmt->executeQuery();
112 
113  if (rset->next()) {
114  m_ID = rset->getInt(1);
115  } else {
116  m_ID = 0;
117  }
118  m_conn->terminateStatement(stmt);
119  } catch (SQLException &e) {
120  throw(std::runtime_error(std::string("CaliIOV::fetchID: ")+getOraMessage(&e)));
121  }
122 
123  return m_ID;
124 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
Tm m_since
Definition: CaliIOV.h:48
Tm m_till
Definition: CaliIOV.h:49
int fetchID() noexcept(false) override
Definition: CaliTag.cc:114
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
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
CaliTag m_caliTag
Definition: CaliIOV.h:50
CaliTag CaliIOV::getCaliTag ( ) const

Definition at line 72 of file CaliIOV.cc.

73 {
74  return m_caliTag;
75 }
CaliTag m_caliTag
Definition: CaliIOV.h:50
int CaliIOV::getID ( )
inline

Definition at line 31 of file CaliIOV.h.

References fetchID(), IUniqueDBObject::m_ID, noexcept, and setByID().

31 { return m_ID;} ;
Tm CaliIOV::getSince ( ) const

Definition at line 38 of file CaliIOV.cc.

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

Definition at line 55 of file CaliIOV.cc.

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

Definition at line 43 of file CaliIOV.h.

References funct::m.

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

Definition at line 36 of file CaliIOV.h.

References m_caliTag, m_since, and m_till.

37  {
38  return ( m_caliTag == m.m_caliTag &&
39  m_since == m.m_since &&
40  m_till == m.m_till );
41  }
Tm m_since
Definition: CaliIOV.h:48
Tm m_till
Definition: CaliIOV.h:49
CaliTag m_caliTag
Definition: CaliIOV.h:50
void CaliIOV::setByID ( int  id)
overridevirtualnoexcept

Implements IUniqueDBObject.

Definition at line 128 of file CaliIOV.cc.

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

Referenced by getID().

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

Definition at line 215 of file CaliIOV.cc.

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

Referenced by EcalCondDBInterface::fetchCaliIOV().

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

Definition at line 62 of file CaliIOV.cc.

References GlobalPosition_Frontier_DevDB_cff::tag.

63 {
64  if (tag != m_caliTag) {
65  m_ID = 0;
66  m_caliTag = tag;
67  }
68 }
CaliTag m_caliTag
Definition: CaliIOV.h:50
void CaliIOV::setSince ( const Tm since)

Definition at line 28 of file CaliIOV.cc.

References ntuplemaker::since.

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

Definition at line 45 of file CaliIOV.cc.

References ntuplemaker::till.

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

Definition at line 165 of file CaliIOV.cc.

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

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

Friends And Related Function Documentation

friend class EcalCondDBInterface
friend

Definition at line 15 of file CaliIOV.h.

Member Data Documentation

CaliTag CaliIOV::m_caliTag
private

Definition at line 50 of file CaliIOV.h.

Referenced by operator==().

Tm CaliIOV::m_since
private

Definition at line 48 of file CaliIOV.h.

Referenced by operator==().

Tm CaliIOV::m_till
private

Definition at line 49 of file CaliIOV.h.

Referenced by operator==().