CMS 3D CMS Logo

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

#include <MODRunIOV.h>

Inheritance diagram for MODRunIOV:
IIOV IUniqueDBObject IDBObject

Public Member Functions

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

Private Attributes

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 13 of file MODRunIOV.h.

Constructor & Destructor Documentation

MODRunIOV::MODRunIOV ( )

Definition at line 12 of file MODRunIOV.cc.

13 {
14  m_conn = nullptr;
15  m_ID = 0;
16  m_runIOV = RunIOV();
17  m_subRunNum = 0;
18  m_subRunStart = Tm();
19  m_subRunEnd = Tm();
20 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
subrun_t m_subRunNum
Definition: MODRunIOV.h:51
Tm m_subRunStart
Definition: MODRunIOV.h:52
Tm m_subRunEnd
Definition: MODRunIOV.h:53
Definition: RunIOV.h:13
Definition: Tm.h:13
RunIOV m_runIOV
Definition: MODRunIOV.h:50
MODRunIOV::~MODRunIOV ( )
override

Definition at line 24 of file MODRunIOV.cc.

25 {
26 }

Member Function Documentation

int MODRunIOV::fetchID ( )
overridevirtualnoexcept

Implements IUniqueDBObject.

Definition at line 101 of file MODRunIOV.cc.

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

Referenced by getID().

103 {
104  // Return from memory if available
105  if (m_ID) {
106  return m_ID;
107  }
108 
109  this->checkConnection();
110 
111  // fetch the parent IDs
112  int runIOVID;
113  this->fetchParentIDs(&runIOVID);
114 
115  if (!runIOVID) {
116  return 0;
117  }
118 
120 
121  if (m_subRunEnd.isNull()) {
122  m_subRunEnd = dh.getPlusInfTm();
123  }
124 
125  try {
126  Statement* stmt = m_conn->createStatement();
127  stmt->setSQL("SELECT iov_id FROM OD_run_iov "
128  "WHERE "
129  "run_iov_id = :1 AND "
130  "subrun_num = :2 AND "
131  "subrun_start = :3 AND "
132  "subrun_end = :4");
133 
134  stmt->setInt(1, runIOVID);
135  stmt->setInt(2, m_subRunNum);
136  stmt->setDate(3, dh.tmToDate(m_subRunStart));
137  stmt->setDate(4, dh.tmToDate(m_subRunEnd));
138 
139  ResultSet* rset = stmt->executeQuery();
140 
141  if (rset->next()) {
142  m_ID = rset->getInt(1);
143  } else {
144  m_ID = 0;
145  }
146  m_conn->terminateStatement(stmt);
147  } catch (SQLException &e) {
148  throw(std::runtime_error(std::string("MODRunIOV::fetchID: ")+getOraMessage(&e)));
149  }
150 
151  return m_ID;
152 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
subrun_t m_subRunNum
Definition: MODRunIOV.h:51
Tm m_subRunStart
Definition: MODRunIOV.h:52
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
Tm m_subRunEnd
Definition: MODRunIOV.h:53
void fetchParentIDs(int *runIOVID) noexcept(false)
Definition: MODRunIOV.cc:247
int isNull() const
Definition: Tm.cc:63
dh
Definition: cuy.py:353
void MODRunIOV::fetchParentIDs ( int *  runIOVID)
privatenoexcept

Definition at line 247 of file MODRunIOV.cc.

249 {
250  // get the RunIOV
252  *runIOVID = m_runIOV.fetchID();
253 
254  if (! *runIOVID) {
255  throw(std::runtime_error("MODRunIOV: Given RunIOV does not exist in DB"));
256  }
257 
258 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
int fetchID() noexcept(false) override
Definition: RunIOV.cc:103
RunIOV m_runIOV
Definition: MODRunIOV.h:50
int MODRunIOV::getID ( )
inline
RunIOV MODRunIOV::getRunIOV ( )

Definition at line 44 of file MODRunIOV.cc.

Referenced by getID().

45 {
46  return m_runIOV;
47 }
RunIOV m_runIOV
Definition: MODRunIOV.h:50
Tm MODRunIOV::getSubRunEnd ( ) const

Definition at line 94 of file MODRunIOV.cc.

Referenced by getID().

95 {
96  return m_subRunEnd;
97 }
Tm m_subRunEnd
Definition: MODRunIOV.h:53
run_t MODRunIOV::getSubRunNumber ( ) const

Definition at line 60 of file MODRunIOV.cc.

Referenced by getID().

61 {
62  return m_subRunNum;
63 }
subrun_t m_subRunNum
Definition: MODRunIOV.h:51
Tm MODRunIOV::getSubRunStart ( ) const

Definition at line 77 of file MODRunIOV.cc.

Referenced by getID().

78 {
79  return m_subRunStart;
80 }
Tm m_subRunStart
Definition: MODRunIOV.h:52
bool MODRunIOV::operator!= ( const MODRunIOV m) const
inline

Definition at line 46 of file MODRunIOV.h.

References funct::m.

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

Definition at line 38 of file MODRunIOV.h.

References m_runIOV, m_subRunEnd, m_subRunNum, and m_subRunStart.

39  {
40  return ( m_runIOV == m.m_runIOV &&
41  m_subRunNum == m.m_subRunNum &&
43  m_subRunEnd == m.m_subRunEnd );
44  }
subrun_t m_subRunNum
Definition: MODRunIOV.h:51
Tm m_subRunStart
Definition: MODRunIOV.h:52
Tm m_subRunEnd
Definition: MODRunIOV.h:53
RunIOV m_runIOV
Definition: MODRunIOV.h:50
void MODRunIOV::setByID ( int  id)
overridevirtualnoexcept

Implements IUniqueDBObject.

Definition at line 156 of file MODRunIOV.cc.

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

Referenced by getID().

158 {
159  this->checkConnection();
160 
162 
163  try {
164  Statement* stmt = m_conn->createStatement();
165 
166  stmt->setSQL("SELECT run_iov_id, subrun_num, subrun_start, subrun_end FROM OD_run_iov WHERE iov_id = :1");
167  stmt->setInt(1, id);
168 
169  ResultSet* rset = stmt->executeQuery();
170  if (rset->next()) {
171  int runIOVID = rset->getInt(1);
172  m_subRunNum = rset->getInt(2);
173  Date startDate = rset->getDate(3);
174  Date endDate = rset->getDate(4);
175 
176  m_subRunStart = dh.dateToTm( startDate );
177  m_subRunEnd = dh.dateToTm( endDate );
178 
180  m_runIOV.setByID(runIOVID);
181 
182  m_ID = id;
183  } else {
184  throw(std::runtime_error("MODRunIOV::setByID: Given id is not in the database"));
185  }
186 
187  m_conn->terminateStatement(stmt);
188  } catch (SQLException &e) {
189  throw(std::runtime_error(std::string("MODRunIOV::setByID: ")+getOraMessage(&e)));
190  }
191 }
void setByID(int id) noexcept(false) override
Definition: RunIOV.cc:152
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
subrun_t m_subRunNum
Definition: MODRunIOV.h:51
Tm m_subRunStart
Definition: MODRunIOV.h:52
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
Tm m_subRunEnd
Definition: MODRunIOV.h:53
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
dh
Definition: cuy.py:353
RunIOV m_runIOV
Definition: MODRunIOV.h:50
void MODRunIOV::setByRun ( RunIOV runiov,
subrun_t  subrun 
)
privatenoexcept

Definition at line 262 of file MODRunIOV.cc.

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

264 {
265  this->checkConnection();
266 
267  runiov->setConnection(m_env, m_conn);
268  int runIOVID = runiov->fetchID();
269 
270  if (!runIOVID) {
271  throw(std::runtime_error("MODRunIOV::setByRun: Given RunIOV does not exist in DB"));
272  }
273 
275 
276  try {
277  Statement* stmt = m_conn->createStatement();
278 
279  stmt->setSQL("SELECT iov_id, subrun_start, subrun_end FROM OD_run_iov "
280  "WHERE run_iov_id = :1 AND subrun_num = :2");
281  stmt->setInt(1, runIOVID);
282  stmt->setInt(2, subrun);
283 
284  ResultSet* rset = stmt->executeQuery();
285  if (rset->next()) {
286  m_runIOV = *runiov;
287  m_subRunNum = subrun;
288 
289  m_ID = rset->getInt(1);
290  Date startDate = rset->getDate(2);
291  Date endDate = rset->getDate(3);
292 
293  m_subRunStart = dh.dateToTm( startDate );
294  m_subRunEnd = dh.dateToTm( endDate );
295  } else {
296  throw(std::runtime_error("MODRunIOV::setByRun: Given subrun is not in the database"));
297  }
298 
299  m_conn->terminateStatement(stmt);
300  } catch (SQLException &e) {
301  throw(std::runtime_error(std::string("MODRunIOV::setByRun: ")+getOraMessage(&e)));
302  }
303 
304 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
subrun_t m_subRunNum
Definition: MODRunIOV.h:51
Tm m_subRunStart
Definition: MODRunIOV.h:52
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
Tm m_subRunEnd
Definition: MODRunIOV.h:53
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
dh
Definition: cuy.py:353
int fetchID() noexcept(false) override
Definition: RunIOV.cc:103
RunIOV m_runIOV
Definition: MODRunIOV.h:50
void MODRunIOV::setID ( int  id)

Definition at line 29 of file MODRunIOV.cc.

References triggerObjects_cff::id.

void MODRunIOV::setRunIOV ( const RunIOV iov)

Definition at line 36 of file MODRunIOV.cc.

Referenced by getID().

37 {
38  if (iov != m_runIOV) {
39  m_ID = 0;
40  m_runIOV = iov;
41  }
42 }
RunIOV m_runIOV
Definition: MODRunIOV.h:50
void MODRunIOV::setSubRunEnd ( const Tm end)

Definition at line 84 of file MODRunIOV.cc.

References end.

Referenced by getID().

85 {
86  if (end != m_subRunEnd) {
87  m_ID = 0;
88  m_subRunEnd = end;
89  }
90 }
Tm m_subRunEnd
Definition: MODRunIOV.h:53
#define end
Definition: vmac.h:39
void MODRunIOV::setSubRunNumber ( subrun_t  subrun)

Definition at line 50 of file MODRunIOV.cc.

Referenced by getID().

51 {
52  if (subrun != m_subRunNum) {
53  m_ID = 0;
54  m_subRunNum = subrun;
55  }
56 }
subrun_t m_subRunNum
Definition: MODRunIOV.h:51
void MODRunIOV::setSubRunStart ( const Tm start)

Definition at line 67 of file MODRunIOV.cc.

References command_line::start.

Referenced by getID().

68 {
69  if (start != m_subRunStart) {
70  m_ID = 0;
72  }
73 }
Tm m_subRunStart
Definition: MODRunIOV.h:52
int MODRunIOV::writeDB ( )
privatenoexcept

Definition at line 195 of file MODRunIOV.cc.

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

197 {
198  this->checkConnection();
199 
200  // Check if this IOV has already been written
201  if (this->fetchID()) {
202  return m_ID;
203  }
204 
205  // fetch Parent IDs
206  int runIOVID;
207  this->fetchParentIDs(&runIOVID);
208 
209  // Validate the data, use infinity-till convention
211 
212  if (m_subRunStart.isNull()) {
213  throw(std::runtime_error("MODRunIOV::writeDB: Must setSubRunStart before writing"));
214  }
215 
216  if (m_subRunEnd.isNull()) {
217  m_subRunEnd = dh.getPlusInfTm();
218  }
219 
220  try {
221  Statement* stmt = m_conn->createStatement();
222 
223  stmt->setSQL("INSERT INTO od_run_iov (iov_id, run_iov_id, subrun_num, subrun_start, subrun_end) "
224  "VALUES (OD_run_iov_sq.NextVal, :1, :2, :3, :4)");
225  stmt->setInt(1, runIOVID);
226  stmt->setInt(2, m_subRunNum);
227  stmt->setDate(3, dh.tmToDate(m_subRunStart));
228  stmt->setDate(4, dh.tmToDate(m_subRunEnd));
229 
230  stmt->executeUpdate();
231 
232  m_conn->terminateStatement(stmt);
233  } catch (SQLException &e) {
234  throw(std::runtime_error(std::string("MODRunIOV::writeDB: ")+getOraMessage(&e)));
235  }
236 
237  // Now get the ID
238  if (!this->fetchID()) {
239  throw(std::runtime_error("MODRunIOV::writeDB: Failed to write"));
240  }
241 
242  return m_ID;
243 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
subrun_t m_subRunNum
Definition: MODRunIOV.h:51
Tm m_subRunStart
Definition: MODRunIOV.h:52
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
int fetchID() noexcept(false) override
Definition: MODRunIOV.cc:101
Tm m_subRunEnd
Definition: MODRunIOV.h:53
void fetchParentIDs(int *runIOVID) noexcept(false)
Definition: MODRunIOV.cc:247
int isNull() const
Definition: Tm.cc:63
dh
Definition: cuy.py:353

Friends And Related Function Documentation

friend class EcalCondDBInterface
friend

Definition at line 15 of file MODRunIOV.h.

Member Data Documentation

RunIOV MODRunIOV::m_runIOV
private

Definition at line 50 of file MODRunIOV.h.

Referenced by operator==().

Tm MODRunIOV::m_subRunEnd
private

Definition at line 53 of file MODRunIOV.h.

Referenced by operator==().

subrun_t MODRunIOV::m_subRunNum
private

Definition at line 51 of file MODRunIOV.h.

Referenced by operator==().

Tm MODRunIOV::m_subRunStart
private

Definition at line 52 of file MODRunIOV.h.

Referenced by operator==().