CMS 3D CMS Logo

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

#include <MonRunIOV.h>

Inheritance diagram for MonRunIOV:
IIOV IUniqueDBObject IDBObject

Public Member Functions

int fetchID () noexcept(false)
 
int getID ()
 
MonRunTag getMonRunTag () const
 
RunIOV getRunIOV ()
 
Tm getSubRunEnd () const
 
run_t getSubRunNumber () const
 
Tm getSubRunStart () const
 
 MonRunIOV ()
 
bool operator!= (const MonRunIOV &m) const
 
bool operator== (const MonRunIOV &m) const
 
void setByID (int id) noexcept(false)
 
void setID (int id)
 
void setMonRunTag (const MonRunTag &tag)
 
void setRunIOV (const RunIOV &iov)
 
void setSubRunEnd (const Tm &end)
 
void setSubRunNumber (subrun_t subrun)
 
void setSubRunStart (const Tm &start)
 
 ~MonRunIOV ()
 
- 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 fetchParentIDs (int *monRunTagID, int *runIOVID) noexcept(false)
 
void setByRun (MonRunTag *montag, RunIOV *runiov, subrun_t subrun) noexcept(false)
 
int writeDB () noexcept(false)
 

Private Attributes

MonRunTag m_monRunTag
 
RunIOV m_runIOV
 
Tm m_subRunEnd
 
subrun_t m_subRunNum
 
Tm m_subRunStart
 

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 14 of file MonRunIOV.h.

Constructor & Destructor Documentation

MonRunIOV::MonRunIOV ( )

Definition at line 13 of file MonRunIOV.cc.

References NULL.

14 {
15  m_conn = NULL;
16  m_ID = 0;
18  m_runIOV = RunIOV();
19  m_subRunNum = 0;
20  m_subRunStart = Tm();
21  m_subRunEnd = Tm();
22 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
RunIOV m_runIOV
Definition: MonRunIOV.h:55
Tm m_subRunStart
Definition: MonRunIOV.h:57
#define NULL
Definition: scimark2.h:8
MonRunTag m_monRunTag
Definition: MonRunIOV.h:54
subrun_t m_subRunNum
Definition: MonRunIOV.h:56
Tm m_subRunEnd
Definition: MonRunIOV.h:58
Definition: RunIOV.h:13
Definition: Tm.h:13
MonRunIOV::~MonRunIOV ( )

Definition at line 26 of file MonRunIOV.cc.

27 {
28 }

Member Function Documentation

int MonRunIOV::fetchID ( )
virtualnoexcept

Implements IUniqueDBObject.

Definition at line 118 of file MonRunIOV.cc.

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

Referenced by getID().

120 {
121  // Return from memory if available
122  if (m_ID) {
123  return m_ID;
124  }
125 
126  this->checkConnection();
127 
128  // fetch the parent IDs
129  int monRunTagID, runIOVID;
130  this->fetchParentIDs(&monRunTagID, &runIOVID);
131 
132  if (!monRunTagID || !runIOVID) {
133  return 0;
134  }
135 
137 
138  if (m_subRunEnd.isNull()) {
139  m_subRunEnd = dh.getPlusInfTm();
140  }
141 
142  try {
143  Statement* stmt = m_conn->createStatement();
144  stmt->setSQL("SELECT iov_id FROM mon_run_iov "
145  "WHERE tag_id = :1 AND "
146  "run_iov_id = :2 AND "
147  "subrun_num = :3 AND "
148  "subrun_start = :4 AND "
149  "subrun_end = :5");
150  stmt->setInt(1, monRunTagID);
151  stmt->setInt(2, runIOVID);
152  stmt->setInt(3, m_subRunNum);
153  stmt->setDate(4, dh.tmToDate(m_subRunStart));
154  stmt->setDate(5, dh.tmToDate(m_subRunEnd));
155 
156  ResultSet* rset = stmt->executeQuery();
157 
158  if (rset->next()) {
159  m_ID = rset->getInt(1);
160  } else {
161  m_ID = 0;
162  }
163  m_conn->terminateStatement(stmt);
164  } catch (SQLException &e) {
165  throw(std::runtime_error("MonRunIOV::fetchID: "+e.getMessage()));
166  }
167 
168  return m_ID;
169 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
void fetchParentIDs(int *monRunTagID, int *runIOVID) noexcept(false)
Definition: MonRunIOV.cc:273
Tm m_subRunStart
Definition: MonRunIOV.h:57
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
subrun_t m_subRunNum
Definition: MonRunIOV.h:56
int isNull() const
Definition: Tm.cc:63
Tm m_subRunEnd
Definition: MonRunIOV.h:58
dh
Definition: cuy.py:353
void MonRunIOV::fetchParentIDs ( int *  monRunTagID,
int *  runIOVID 
)
privatenoexcept

Definition at line 273 of file MonRunIOV.cc.

275 {
276  // get the MonRunTag
278  *monRunTagID = m_monRunTag.fetchID();
279 
280  // get the RunIOV
282  *runIOVID = m_runIOV.fetchID();
283 
284  if (! *runIOVID) {
285  throw(std::runtime_error("MonRunIOV: Given RunIOV does not exist in DB"));
286  }
287 
288 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
RunIOV m_runIOV
Definition: MonRunIOV.h:55
int fetchID() noexcept(false)
Definition: MonRunTag.cc:59
MonRunTag m_monRunTag
Definition: MonRunIOV.h:54
int fetchID() noexcept(false)
Definition: RunIOV.cc:103
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
int MonRunIOV::getID ( )
inline
MonRunTag MonRunIOV::getMonRunTag ( ) const

Definition at line 46 of file MonRunIOV.cc.

Referenced by getID().

47 {
48  return m_monRunTag;
49 }
MonRunTag m_monRunTag
Definition: MonRunIOV.h:54
RunIOV MonRunIOV::getRunIOV ( )

Definition at line 61 of file MonRunIOV.cc.

Referenced by getID().

62 {
63  return m_runIOV;
64 }
RunIOV m_runIOV
Definition: MonRunIOV.h:55
Tm MonRunIOV::getSubRunEnd ( ) const

Definition at line 111 of file MonRunIOV.cc.

Referenced by getID().

112 {
113  return m_subRunEnd;
114 }
Tm m_subRunEnd
Definition: MonRunIOV.h:58
run_t MonRunIOV::getSubRunNumber ( ) const

Definition at line 77 of file MonRunIOV.cc.

Referenced by getID().

78 {
79  return m_subRunNum;
80 }
subrun_t m_subRunNum
Definition: MonRunIOV.h:56
Tm MonRunIOV::getSubRunStart ( ) const

Definition at line 94 of file MonRunIOV.cc.

Referenced by getID().

95 {
96  return m_subRunStart;
97 }
Tm m_subRunStart
Definition: MonRunIOV.h:57
bool MonRunIOV::operator!= ( const MonRunIOV m) const
inline

Definition at line 50 of file MonRunIOV.h.

References funct::m.

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

Definition at line 41 of file MonRunIOV.h.

References m_monRunTag, m_runIOV, m_subRunEnd, m_subRunNum, and m_subRunStart.

42  {
43  return ( m_monRunTag == m.m_monRunTag &&
44  m_runIOV == m.m_runIOV &&
45  m_subRunNum == m.m_subRunNum &&
47  m_subRunEnd == m.m_subRunEnd );
48  }
RunIOV m_runIOV
Definition: MonRunIOV.h:55
Tm m_subRunStart
Definition: MonRunIOV.h:57
MonRunTag m_monRunTag
Definition: MonRunIOV.h:54
subrun_t m_subRunNum
Definition: MonRunIOV.h:56
Tm m_subRunEnd
Definition: MonRunIOV.h:58
void MonRunIOV::setByID ( int  id)
virtualnoexcept

Implements IUniqueDBObject.

Definition at line 173 of file MonRunIOV.cc.

References DateHandler::dateToTm(), cuy::dh, MillePedeFileConverter_cfg::e, and triggerObjects_cff::id.

Referenced by getID().

175 {
176  this->checkConnection();
177 
179 
180  try {
181  Statement* stmt = m_conn->createStatement();
182 
183  stmt->setSQL("SELECT tag_id, run_iov_id, subrun_num, subrun_start, subrun_end FROM mon_run_iov WHERE iov_id = :1");
184  stmt->setInt(1, id);
185 
186  ResultSet* rset = stmt->executeQuery();
187  if (rset->next()) {
188  int monRunTagID = rset->getInt(1);
189  int runIOVID = rset->getInt(2);
190  m_subRunNum = rset->getInt(3);
191  Date startDate = rset->getDate(4);
192  Date endDate = rset->getDate(5);
193 
194  m_subRunStart = dh.dateToTm( startDate );
195  m_subRunEnd = dh.dateToTm( endDate );
196 
198  m_monRunTag.setByID(monRunTagID);
199 
201  m_runIOV.setByID(runIOVID);
202 
203  m_ID = id;
204  } else {
205  throw(std::runtime_error("MonRunIOV::setByID: Given tag_id is not in the database"));
206  }
207 
208  m_conn->terminateStatement(stmt);
209  } catch (SQLException &e) {
210  throw(std::runtime_error("MonRunIOV::setByID: "+e.getMessage()));
211  }
212 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
RunIOV m_runIOV
Definition: MonRunIOV.h:55
Tm m_subRunStart
Definition: MonRunIOV.h:57
void setByID(int id) noexcept(false)
Definition: MonRunTag.cc:100
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
MonRunTag m_monRunTag
Definition: MonRunIOV.h:54
subrun_t m_subRunNum
Definition: MonRunIOV.h:56
void setByID(int id) noexcept(false)
Definition: RunIOV.cc:152
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
Tm m_subRunEnd
Definition: MonRunIOV.h:58
dh
Definition: cuy.py:353
void MonRunIOV::setByRun ( MonRunTag montag,
RunIOV runiov,
subrun_t  subrun 
)
privatenoexcept

Definition at line 292 of file MonRunIOV.cc.

References DateHandler::dateToTm(), cuy::dh, and MillePedeFileConverter_cfg::e.

Referenced by EcalCondDBInterface::fetchMonRunIOV().

294 {
295  this->checkConnection();
296 
297  runiov->setConnection(m_env, m_conn);
298  int runIOVID = runiov->fetchID();
299 
300  if (!runIOVID) {
301  throw(std::runtime_error("MonRunIOV::setByRun: Given RunIOV does not exist in DB"));
302  }
303 
304  montag->setConnection(m_env, m_conn);
305  int monTagID = montag->fetchID();
306 
307  if (!monTagID) {
308  throw(std::runtime_error("MonRunIOV::setByRun: Given MonRunTag does not exist in the DB"));
309  }
310 
312 
313  try {
314  Statement* stmt = m_conn->createStatement();
315 
316  stmt->setSQL("SELECT iov_id, subrun_start, subrun_end FROM mon_run_iov "
317  "WHERE tag_id = :1 AND run_iov_id = :2 AND subrun_num = :3");
318  stmt->setInt(1, monTagID);
319  stmt->setInt(2, runIOVID);
320  stmt->setInt(3, subrun);
321 
322  ResultSet* rset = stmt->executeQuery();
323  if (rset->next()) {
324  m_monRunTag = *montag;
325  m_runIOV = *runiov;
326  m_subRunNum = subrun;
327 
328  m_ID = rset->getInt(1);
329  Date startDate = rset->getDate(2);
330  Date endDate = rset->getDate(3);
331 
332  m_subRunStart = dh.dateToTm( startDate );
333  m_subRunEnd = dh.dateToTm( endDate );
334  } else {
335  throw(std::runtime_error("MonRunIOV::setByRun: Given subrun is not in the database"));
336  }
337 
338  m_conn->terminateStatement(stmt);
339  } catch (SQLException &e) {
340  throw(std::runtime_error("MonRunIOV::setByRun: "+e.getMessage()));
341  }
342 
343 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
RunIOV m_runIOV
Definition: MonRunIOV.h:55
Tm m_subRunStart
Definition: MonRunIOV.h:57
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
int fetchID() noexcept(false)
Definition: MonRunTag.cc:59
MonRunTag m_monRunTag
Definition: MonRunIOV.h:54
int fetchID() noexcept(false)
Definition: RunIOV.cc:103
subrun_t m_subRunNum
Definition: MonRunIOV.h:56
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
Tm m_subRunEnd
Definition: MonRunIOV.h:58
dh
Definition: cuy.py:353
void MonRunIOV::setID ( int  id)

Definition at line 31 of file MonRunIOV.cc.

References triggerObjects_cff::id.

Referenced by MonRunList::fetchLastNRuns(), and MonRunList::fetchRuns().

void MonRunIOV::setMonRunTag ( const MonRunTag tag)
void MonRunIOV::setRunIOV ( const RunIOV iov)

Definition at line 53 of file MonRunIOV.cc.

Referenced by EcalCondDBWriter::dqmEndJob(), MonRunList::fetchLastNRuns(), MonRunList::fetchRuns(), getID(), and EcalPedOffset::writeDb().

54 {
55  if (iov != m_runIOV) {
56  m_ID = 0;
57  m_runIOV = iov;
58  }
59 }
RunIOV m_runIOV
Definition: MonRunIOV.h:55
void MonRunIOV::setSubRunEnd ( const Tm end)

Definition at line 101 of file MonRunIOV.cc.

References end.

Referenced by EcalCondDBWriter::dqmEndJob(), MonRunList::fetchLastNRuns(), MonRunList::fetchRuns(), and getID().

102 {
103  if (end != m_subRunEnd) {
104  m_ID = 0;
105  m_subRunEnd = end;
106  }
107 }
#define end
Definition: vmac.h:37
Tm m_subRunEnd
Definition: MonRunIOV.h:58
void MonRunIOV::setSubRunNumber ( subrun_t  subrun)

Definition at line 67 of file MonRunIOV.cc.

Referenced by EcalCondDBWriter::dqmEndJob(), MonRunList::fetchLastNRuns(), MonRunList::fetchRuns(), getID(), and EcalPedOffset::writeDb().

68 {
69  if (subrun != m_subRunNum) {
70  m_ID = 0;
71  m_subRunNum = subrun;
72  }
73 }
subrun_t m_subRunNum
Definition: MonRunIOV.h:56
void MonRunIOV::setSubRunStart ( const Tm start)

Definition at line 84 of file MonRunIOV.cc.

References command_line::start.

Referenced by EcalCondDBWriter::dqmEndJob(), MonRunList::fetchLastNRuns(), MonRunList::fetchRuns(), getID(), and EcalPedOffset::writeDb().

85 {
86  if (start != m_subRunStart) {
87  m_ID = 0;
89  }
90 }
Tm m_subRunStart
Definition: MonRunIOV.h:57
int MonRunIOV::writeDB ( )
privatenoexcept

Definition at line 216 of file MonRunIOV.cc.

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

218 {
219  this->checkConnection();
220 
221  // Check if this IOV has already been written
222  if (this->fetchID()) {
223  return m_ID;
224  }
225 
226  // fetch Parent IDs
227  int monRunTagID, runIOVID;
228  this->fetchParentIDs(&monRunTagID, &runIOVID);
229 
230  if (!monRunTagID) {
231  monRunTagID = m_monRunTag.writeDB();
232  }
233 
234  // Validate the data, use infinity-till convention
236 
237  if (m_subRunStart.isNull()) {
238  throw(std::runtime_error("MonRunIOV::writeDB: Must setSubRunStart before writing"));
239  }
240 
241  if (m_subRunEnd.isNull()) {
242  m_subRunEnd = dh.getPlusInfTm();
243  }
244 
245  try {
246  Statement* stmt = m_conn->createStatement();
247 
248  stmt->setSQL("INSERT INTO mon_run_iov (iov_id, tag_id, run_iov_id, subrun_num, subrun_start, subrun_end) "
249  "VALUES (mon_run_iov_sq.NextVal, :1, :2, :3, :4, :5)");
250  stmt->setInt(1, monRunTagID);
251  stmt->setInt(2, runIOVID);
252  stmt->setInt(3, m_subRunNum);
253  stmt->setDate(4, dh.tmToDate(m_subRunStart));
254  stmt->setDate(5, dh.tmToDate(m_subRunEnd));
255 
256  stmt->executeUpdate();
257 
258  m_conn->terminateStatement(stmt);
259  } catch (SQLException &e) {
260  throw(std::runtime_error("MonRunIOV::writeDB: "+e.getMessage()));
261  }
262 
263  // Now get the ID
264  if (!this->fetchID()) {
265  throw(std::runtime_error("MonRunIOV::writeDB: Failed to write"));
266  }
267 
268  return m_ID;
269 }
int fetchID() noexcept(false)
Definition: MonRunIOV.cc:118
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
void fetchParentIDs(int *monRunTagID, int *runIOVID) noexcept(false)
Definition: MonRunIOV.cc:273
Tm m_subRunStart
Definition: MonRunIOV.h:57
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
MonRunTag m_monRunTag
Definition: MonRunIOV.h:54
subrun_t m_subRunNum
Definition: MonRunIOV.h:56
int isNull() const
Definition: Tm.cc:63
Tm m_subRunEnd
Definition: MonRunIOV.h:58
dh
Definition: cuy.py:353
int writeDB() noexcept(false)
Definition: MonRunTag.cc:128

Friends And Related Function Documentation

friend class EcalCondDBInterface
friend

Definition at line 16 of file MonRunIOV.h.

Member Data Documentation

MonRunTag MonRunIOV::m_monRunTag
private

Definition at line 54 of file MonRunIOV.h.

Referenced by operator==().

RunIOV MonRunIOV::m_runIOV
private

Definition at line 55 of file MonRunIOV.h.

Referenced by operator==().

Tm MonRunIOV::m_subRunEnd
private

Definition at line 58 of file MonRunIOV.h.

Referenced by operator==().

subrun_t MonRunIOV::m_subRunNum
private

Definition at line 56 of file MonRunIOV.h.

Referenced by operator==().

Tm MonRunIOV::m_subRunStart
private

Definition at line 57 of file MonRunIOV.h.

Referenced by operator==().