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::CaliIOV ( )

Definition at line 12 of file CaliIOV.cc.

12  {
13  m_conn = nullptr;
14  m_ID = 0;
15  m_since = Tm();
16  m_till = Tm();
17 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
Tm m_since
Definition: CaliIOV.h:43
Tm m_till
Definition: CaliIOV.h:44
Definition: Tm.h:13

◆ ~CaliIOV()

CaliIOV::~CaliIOV ( )
override

Definition at line 19 of file CaliIOV.cc.

19 {}

Member Function Documentation

◆ fetchID()

int CaliIOV::fetchID ( )
overridevirtualnoexcept

Implements IUniqueDBObject.

Definition at line 48 of file CaliIOV.cc.

References cuy::dh, and MillePedeFileConverter_cfg::e.

48  {
49  // Return from memory if available
50  if (m_ID) {
51  return m_ID;
52  }
53 
54  this->checkConnection();
55 
57  int tagID = m_caliTag.fetchID();
58  if (!tagID) {
59  return 0;
60  }
61 
63 
64  if (m_till.isNull()) {
65  m_till = dh.getPlusInfTm();
66  }
67 
68  try {
69  Statement* stmt = m_conn->createStatement();
70  stmt->setSQL(
71  "SELECT iov_id FROM cali_iov "
72  "WHERE tag_id = :tag_id AND "
73  "since = :since AND "
74  "till = :till");
75  stmt->setInt(1, tagID);
76  stmt->setDate(2, dh.tmToDate(m_since));
77  stmt->setDate(3, dh.tmToDate(m_till));
78 
79  ResultSet* rset = stmt->executeQuery();
80 
81  if (rset->next()) {
82  m_ID = rset->getInt(1);
83  } else {
84  m_ID = 0;
85  }
86  m_conn->terminateStatement(stmt);
87  } catch (SQLException& e) {
88  throw(std::runtime_error("CaliIOV::fetchID: " + e.getMessage()));
89  }
90 
91  return m_ID;
92 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:33
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
void checkConnection() const noexcept(false)
Definition: IDBObject.h:36
Tm m_since
Definition: CaliIOV.h:43
Tm m_till
Definition: CaliIOV.h:44
int fetchID() noexcept(false) override
Definition: CaliTag.cc:67
int isNull() const
Definition: Tm.cc:46
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
dh
Definition: cuy.py:354
CaliTag m_caliTag
Definition: CaliIOV.h:45

◆ getCaliTag()

CaliTag CaliIOV::getCaliTag ( ) const

Definition at line 46 of file CaliIOV.cc.

46 { return m_caliTag; }
CaliTag m_caliTag
Definition: CaliIOV.h:45

◆ getID()

int CaliIOV::getID ( )
inline

Definition at line 30 of file CaliIOV.h.

References IUniqueDBObject::m_ID.

30 { return m_ID; };

◆ getSince()

Tm CaliIOV::getSince ( ) const

Definition at line 28 of file CaliIOV.cc.

28 { return m_since; }
Tm m_since
Definition: CaliIOV.h:43

◆ getTill()

Tm CaliIOV::getTill ( ) const

Definition at line 37 of file CaliIOV.cc.

37 { return m_till; }
Tm m_till
Definition: CaliIOV.h:44

◆ operator!=()

bool CaliIOV::operator!= ( const CaliIOV m) const
inline

◆ operator==()

bool CaliIOV::operator== ( const CaliIOV m) const
inline

Definition at line 35 of file CaliIOV.h.

References visualization-live-secondInstance_cfg::m, m_caliTag, m_since, and m_till.

35  {
36  return (m_caliTag == m.m_caliTag && m_since == m.m_since && m_till == m.m_till);
37  }
Tm m_since
Definition: CaliIOV.h:43
Tm m_till
Definition: CaliIOV.h:44
CaliTag m_caliTag
Definition: CaliIOV.h:45

◆ setByID()

void CaliIOV::setByID ( int  id)
overridevirtualnoexcept

Implements IUniqueDBObject.

Definition at line 94 of file CaliIOV.cc.

References cuy::dh, MillePedeFileConverter_cfg::e, l1ctLayer2EG_cff::id, SiStripBadComponentsDQMServiceTemplate_cfg::since, and ntuplemaker::till.

94  {
95  this->checkConnection();
96 
98 
99  try {
100  Statement* stmt = m_conn->createStatement();
101 
102  stmt->setSQL("SELECT tag_id, since, till FROM cali_iov WHERE iov_id = :1");
103  stmt->setInt(1, id);
104 
105  ResultSet* rset = stmt->executeQuery();
106  if (rset->next()) {
107  int tagID = rset->getInt(1);
108  Date since = rset->getDate(2);
109  Date till = rset->getDate(3);
110 
111  m_since = dh.dateToTm(since);
112  m_till = dh.dateToTm(till);
113 
115  m_caliTag.setByID(tagID);
116  m_ID = id;
117  } else {
118  throw(std::runtime_error("CaliTag::setByID: Given tag_id is not in the database"));
119  }
120 
121  m_conn->terminateStatement(stmt);
122  } catch (SQLException& e) {
123  throw(std::runtime_error("CaliTag::setByID: " + e.getMessage()));
124  }
125 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:33
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
void checkConnection() const noexcept(false)
Definition: IDBObject.h:36
Tm m_since
Definition: CaliIOV.h:43
void setByID(int id) noexcept(false) override
Definition: CaliTag.cc:110
Tm m_till
Definition: CaliIOV.h:44
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
dh
Definition: cuy.py:354
CaliTag m_caliTag
Definition: CaliIOV.h:45

◆ setByTm()

void CaliIOV::setByTm ( CaliTag tag,
const Tm time 
)
privatenoexcept

Definition at line 174 of file CaliIOV.cc.

References cuy::dh, MillePedeFileConverter_cfg::e, and makeGlobalPositionRcd_cfg::tag.

Referenced by EcalCondDBInterface::fetchCaliIOV().

174  {
175  this->checkConnection();
176 
177  tag->setConnection(m_env, m_conn);
178  int tagID = tag->fetchID();
179 
180  if (!tagID) {
181  throw(std::runtime_error("CaliIOV::setByTm: Given CaliTag does not exist in the DB"));
182  }
183 
185 
186  Date eventDate = dh.tmToDate(eventTm);
187 
188  try {
189  Statement* stmt = m_conn->createStatement();
190 
191  stmt->setSQL(
192  "SELECT iov_id, since, till FROM cali_iov "
193  "WHERE tag_id = :1 AND since <= :2 AND till > :3");
194  stmt->setInt(1, tagID);
195  stmt->setDate(2, eventDate);
196  stmt->setDate(3, eventDate);
197 
198  ResultSet* rset = stmt->executeQuery();
199  if (rset->next()) {
200  m_caliTag = *tag;
201 
202  m_ID = rset->getInt(1);
203  Date sinceDate = rset->getDate(2);
204  Date tillDate = rset->getDate(3);
205 
206  m_since = dh.dateToTm(sinceDate);
207  m_till = dh.dateToTm(tillDate);
208  } else {
209  throw(std::runtime_error("CaliIOV::setByTm: Given subrun is not in the database"));
210  }
211 
212  m_conn->terminateStatement(stmt);
213  } catch (SQLException& e) {
214  throw(std::runtime_error("CaliIOV::setByTm: " + e.getMessage()));
215  }
216 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:33
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
void checkConnection() const noexcept(false)
Definition: IDBObject.h:36
Tm m_since
Definition: CaliIOV.h:43
Tm m_till
Definition: CaliIOV.h:44
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
dh
Definition: cuy.py:354
CaliTag m_caliTag
Definition: CaliIOV.h:45

◆ setCaliTag()

void CaliIOV::setCaliTag ( const CaliTag tag)

Definition at line 39 of file CaliIOV.cc.

References makeGlobalPositionRcd_cfg::tag.

39  {
40  if (tag != m_caliTag) {
41  m_ID = 0;
42  m_caliTag = tag;
43  }
44 }
CaliTag m_caliTag
Definition: CaliIOV.h:45

◆ setSince()

void CaliIOV::setSince ( const Tm since)

◆ setTill()

void CaliIOV::setTill ( const Tm till)

Definition at line 30 of file CaliIOV.cc.

References ntuplemaker::till.

30  {
31  if (till != m_till) {
32  m_ID = 0;
33  m_till = till;
34  }
35 }
Tm m_till
Definition: CaliIOV.h:44

◆ writeDB()

int CaliIOV::writeDB ( )
privatenoexcept

Definition at line 127 of file CaliIOV.cc.

References cuy::dh, and MillePedeFileConverter_cfg::e.

127  {
128  this->checkConnection();
129 
130  // Check if this IOV has already been written
131  if (this->fetchID()) {
132  return m_ID;
133  }
134 
136  int tagID = m_caliTag.writeDB();
137 
138  // Validate the data, use infinity-till convention
140 
141  if (m_since.isNull()) {
142  throw(std::runtime_error("CaliIOV::writeDB: Must setSince before writing"));
143  }
144 
145  if (m_till.isNull()) {
146  m_till = dh.getPlusInfTm();
147  }
148 
149  try {
150  Statement* stmt = m_conn->createStatement();
151 
152  stmt->setSQL(
153  "INSERT INTO cali_iov (iov_id, tag_id, since, till) "
154  "VALUES (cali_iov_sq.NextVal, :1, :2, :3)");
155  stmt->setInt(1, tagID);
156  stmt->setDate(2, dh.tmToDate(m_since));
157  stmt->setDate(3, dh.tmToDate(m_till));
158 
159  stmt->executeUpdate();
160 
161  m_conn->terminateStatement(stmt);
162  } catch (SQLException& e) {
163  throw(std::runtime_error("CaliIOV::writeDB: " + e.getMessage()));
164  }
165 
166  // Now get the ID
167  if (!this->fetchID()) {
168  throw(std::runtime_error("CaliIOV::writeDB: Failed to write"));
169  }
170 
171  return m_ID;
172 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:33
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
void checkConnection() const noexcept(false)
Definition: IDBObject.h:36
Tm m_since
Definition: CaliIOV.h:43
Tm m_till
Definition: CaliIOV.h:44
int writeDB() noexcept(false)
Definition: CaliTag.cc:142
int isNull() const
Definition: Tm.cc:46
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
int fetchID() noexcept(false) override
Definition: CaliIOV.cc:48
dh
Definition: cuy.py:354
CaliTag m_caliTag
Definition: CaliIOV.h:45

Friends And Related Function Documentation

◆ EcalCondDBInterface

friend class EcalCondDBInterface
friend

Definition at line 15 of file CaliIOV.h.

Member Data Documentation

◆ m_caliTag

CaliTag CaliIOV::m_caliTag
private

Definition at line 45 of file CaliIOV.h.

Referenced by operator==().

◆ m_since

Tm CaliIOV::m_since
private

Definition at line 43 of file CaliIOV.h.

Referenced by operator==().

◆ m_till

Tm CaliIOV::m_till
private

Definition at line 44 of file CaliIOV.h.

Referenced by operator==().