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 const int 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::DCUIOV ( )

Definition at line 12 of file DCUIOV.cc.

12  {
13  m_conn = nullptr;
14  m_ID = 0;
15  m_since = Tm();
16  m_till = Tm();
17 }

◆ ~DCUIOV()

DCUIOV::~DCUIOV ( )
override

Definition at line 19 of file DCUIOV.cc.

19 {}

Member Function Documentation

◆ fetchID()

int DCUIOV::fetchID ( )
overridevirtualnoexcept

Implements IUniqueDBObject.

Definition at line 48 of file DCUIOV.cc.

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_dcuTag.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 dcu_iov "
72  "WHERE tag_id = :tag_id AND "
73  "since = :since ");
74  stmt->setInt(1, tagID);
75  stmt->setDate(2, dh.tmToDate(m_since));
76  // stmt->setDate(3, dh.tmToDate(m_till));
77 
78  ResultSet* rset = stmt->executeQuery();
79 
80  if (rset->next()) {
81  m_ID = rset->getInt(1);
82  } else {
83  m_ID = 0;
84  }
85  m_conn->terminateStatement(stmt);
86  } catch (SQLException& e) {
87  throw(std::runtime_error("DCUIOV::fetchID: " + e.getMessage()));
88  }
89 
90  return m_ID;
91 }

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

◆ getDCUTag()

DCUTag DCUIOV::getDCUTag ( ) const

Definition at line 46 of file DCUIOV.cc.

46 { return m_dcuTag; }

◆ getID()

int DCUIOV::getID ( )
inline

Definition at line 29 of file DCUIOV.h.

29 { return m_ID; };

References IUniqueDBObject::m_ID.

◆ getSince()

Tm DCUIOV::getSince ( ) const

Definition at line 28 of file DCUIOV.cc.

28 { return m_since; }

◆ getTill()

Tm DCUIOV::getTill ( ) const

Definition at line 37 of file DCUIOV.cc.

37 { return m_till; }

◆ operator!=()

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

Definition at line 38 of file DCUIOV.h.

38 { return !(*this == m); }

References visualization-live-secondInstance_cfg::m.

◆ operator==()

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

Definition at line 34 of file DCUIOV.h.

34  {
35  return (m_dcuTag == m.m_dcuTag && m_since == m.m_since && m_till == m.m_till);
36  }

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

◆ setByID()

void DCUIOV::setByID ( int  id)
overridevirtualnoexcept

Implements IUniqueDBObject.

Definition at line 93 of file DCUIOV.cc.

93  {
94  this->checkConnection();
95 
97 
98  try {
99  Statement* stmt = m_conn->createStatement();
100 
101  stmt->setSQL("SELECT tag_id, since, till FROM dcu_iov WHERE iov_id = :1");
102  stmt->setInt(1, id);
103 
104  ResultSet* rset = stmt->executeQuery();
105  if (rset->next()) {
106  int tagID = rset->getInt(1);
107  Date since = rset->getDate(2);
108  Date till = rset->getDate(3);
109 
110  m_since = dh.dateToTm(since);
111  m_till = dh.dateToTm(till);
112 
114  m_dcuTag.setByID(tagID);
115  m_ID = id;
116  } else {
117  throw(std::runtime_error("DCUTag::setByID: Given tag_id is not in the database"));
118  }
119 
120  m_conn->terminateStatement(stmt);
121  } catch (SQLException& e) {
122  throw(std::runtime_error("DCUTag::setByID: " + e.getMessage()));
123  }
124 }

References cuy::dh, MillePedeFileConverter_cfg::e, triggerObjects_cff::id, writeEcalDQMStatus::since, and ntuplemaker::till.

◆ setByTm()

void DCUIOV::setByTm ( DCUTag tag,
const Tm time 
)
privatenoexcept

Definition at line 173 of file DCUIOV.cc.

173  {
174  this->checkConnection();
175 
176  tag->setConnection(m_env, m_conn);
177  int tagID = tag->fetchID();
178 
179  if (!tagID) {
180  throw(std::runtime_error("DCUIOV::setByTm: Given DCUTag does not exist in the DB"));
181  }
182 
184 
185  Date eventDate = dh.tmToDate(eventTm);
186 
187  try {
188  Statement* stmt = m_conn->createStatement();
189 
190  stmt->setSQL(
191  "SELECT iov_id, since, till FROM dcu_iov "
192  "WHERE tag_id = :1 AND since <= :2 AND till > :3");
193  stmt->setInt(1, tagID);
194  stmt->setDate(2, eventDate);
195  stmt->setDate(3, eventDate);
196 
197  ResultSet* rset = stmt->executeQuery();
198  if (rset->next()) {
199  m_dcuTag = *tag;
200 
201  m_ID = rset->getInt(1);
202  Date sinceDate = rset->getDate(2);
203  Date tillDate = rset->getDate(3);
204 
205  m_since = dh.dateToTm(sinceDate);
206  m_till = dh.dateToTm(tillDate);
207  } else {
208  throw(std::runtime_error("DCUIOV::setByTm: Given subrun is not in the database"));
209  }
210 
211  m_conn->terminateStatement(stmt);
212  } catch (SQLException& e) {
213  throw(std::runtime_error("DCUIOV::setByTm: " + e.getMessage()));
214  }
215 }

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

Referenced by EcalCondDBInterface::fetchDCUIOV().

◆ setDCUTag()

void DCUIOV::setDCUTag ( const DCUTag tag)

Definition at line 39 of file DCUIOV.cc.

39  {
40  if (tag != m_dcuTag) {
41  m_ID = 0;
42  m_dcuTag = tag;
43  }
44 }

References makeGlobalPositionRcd_cfg::tag.

◆ setSince()

void DCUIOV::setSince ( const Tm since)

Definition at line 21 of file DCUIOV.cc.

21  {
22  if (since != m_since) {
23  m_ID = 0;
24  m_since = since;
25  }
26 }

References writeEcalDQMStatus::since.

◆ setTill()

void DCUIOV::setTill ( const Tm till)

Definition at line 30 of file DCUIOV.cc.

30  {
31  if (till != m_till) {
32  m_ID = 0;
33  m_till = till;
34  }
35 }

References ntuplemaker::till.

◆ writeDB()

int DCUIOV::writeDB ( )
privatenoexcept

Definition at line 126 of file DCUIOV.cc.

126  {
127  this->checkConnection();
128 
129  // Check if this IOV has already been written
130  if (this->fetchID()) {
131  return m_ID;
132  }
133 
135  int tagID = m_dcuTag.writeDB();
136 
137  // Validate the data, use infinity-till convention
139 
140  if (m_since.isNull()) {
141  throw(std::runtime_error("DCUIOV::writeDB: Must setSince before writing"));
142  }
143 
144  if (m_till.isNull()) {
145  m_till = dh.getPlusInfTm();
146  }
147 
148  try {
149  Statement* stmt = m_conn->createStatement();
150 
151  stmt->setSQL(
152  "INSERT INTO dcu_iov (iov_id, tag_id, since, till) "
153  "VALUES (dcu_iov_sq.NextVal, :1, :2, :3)");
154  stmt->setInt(1, tagID);
155  stmt->setDate(2, dh.tmToDate(m_since));
156  stmt->setDate(3, dh.tmToDate(m_till));
157 
158  stmt->executeUpdate();
159 
160  m_conn->terminateStatement(stmt);
161  } catch (SQLException& e) {
162  throw(std::runtime_error("DCUIOV::writeDB: " + e.getMessage()));
163  }
164 
165  // Now get the ID
166  if (!this->fetchID()) {
167  throw(std::runtime_error("DCUIOV::writeDB: Failed to write"));
168  }
169 
170  return m_ID;
171 }

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

Friends And Related Function Documentation

◆ EcalCondDBInterface

friend class EcalCondDBInterface
friend

Definition at line 15 of file DCUIOV.h.

Member Data Documentation

◆ m_dcuTag

DCUTag DCUIOV::m_dcuTag
private

Definition at line 44 of file DCUIOV.h.

Referenced by operator==().

◆ m_since

Tm DCUIOV::m_since
private

Definition at line 42 of file DCUIOV.h.

Referenced by operator==().

◆ m_till

Tm DCUIOV::m_till
private

Definition at line 43 of file DCUIOV.h.

Referenced by operator==().

IUniqueDBObject::m_ID
int m_ID
Definition: IUniqueDBObject.h:18
DCUIOV::m_dcuTag
DCUTag m_dcuTag
Definition: DCUIOV.h:44
Tm::isNull
int isNull() const
Definition: Tm.cc:46
DCUIOV::fetchID
int fetchID() noexcept(false) override
Definition: DCUIOV.cc:48
DCUIOV::m_since
Tm m_since
Definition: DCUIOV.h:42
IDBObject::m_conn
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:79
writeEcalDQMStatus.since
since
Definition: writeEcalDQMStatus.py:53
Tm
Definition: Tm.h:13
ntuplemaker.till
till
Definition: ntuplemaker.py:198
IDBObject::checkConnection
void checkConnection() const noexcept(false)
Definition: IDBObject.h:36
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
IDBObject::setConnection
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
DCUTag::writeDB
int writeDB() noexcept(false)
Definition: DCUTag.cc:104
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
DCUTag::fetchID
int fetchID() noexcept(false) override
Definition: DCUTag.cc:39
DCUIOV::m_till
Tm m_till
Definition: DCUIOV.h:43
IDBObject::m_env
oracle::occi::Environment * m_env
Definition: IDBObject.h:33
DCUTag::setByID
void setByID(int id) noexcept(false) override
Definition: DCUTag.cc:76
DateHandler
Definition: DateHandler.h:7
cuy.dh
dh
Definition: cuy.py:354
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37