CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LMFLmrSubIOV.cc
Go to the documentation of this file.
2 
4  m_className = "LMFLmrSubIOV";
5 
6  m_lmfIOV = 0;
7  m_t[0] = Tm();
8  m_t[1] = Tm();
9  m_t[2] = Tm();
10 }
11 
13  init();
14 }
15 
17  init();
18 }
19 
20 LMFLmrSubIOV::LMFLmrSubIOV(oracle::occi::Environment* env,
21  oracle::occi::Connection* conn): LMFUnique(env, conn)
22 {
23  init();
24 }
25 
27 }
28 
30  if (m_debug) {
31  std::cout << "[LMFLmrSubIOV] Setting IOV_ID as " << iov.getID()
32  << std::endl << std::flush;
33  }
34  m_lmfIOV = iov.getID();
35  return *this;
36 }
37 
39  m_t[0] = t[0];
40  m_t[1] = t[1];
41  m_t[2] = t[2];
42  return *this;
43 }
44 
46  m_t[0] = t1;
47  m_t[1] = t2;
48  m_t[2] = t3;
49  return *this;
50 }
51 
52 std::string LMFLmrSubIOV::fetchIdSql(Statement *stmt) {
53  if (!m_lmfIOV) {
54  if (m_debug) {
55  std::cout << m_className << ": LMFIOV not set" << std::endl;
56  }
57  return "";
58  }
59 
60  std::string sql = "SELECT LMR_SUB_IOV_ID FROM "
61  "CMS_ECAL_LASER_COND.LMF_LMR_SUB_IOV "
62  "WHERE "
63  "IOV_ID = :1 AND "
64  "T1 = :2 AND "
65  "T2 = :3 AND "
66  "T3 = :4";
67  stmt->setSQL(sql);
68  stmt->setInt(1, m_lmfIOV);
70  for (int i = 0; i < 3; i++) {
71  oracle::occi::Date t = dh.tmToDate(m_t[i]);
72  stmt->setDate(i + 2, t);
73  }
74  return sql;
75 
76 }
77 
78 std::string LMFLmrSubIOV::setByIDSql(Statement *stmt, int id) {
79  std::string sql = "SELECT IOV_ID, T1, T2, T3 FROM "
80  "CMS_ECAL_LASER_COND.LMF_LMR_SUB_IOV "
81  "WHERE LMR_SUB_IOV_ID = :1";
82  stmt->setSQL(sql);
83  stmt->setInt(1, id);
84  return sql;
85 }
86 
87 std::string LMFLmrSubIOV::writeDBSql(Statement *stmt) {
88  // Validate the data, use infinity-till convention
90 
91  for (int i = 0; i < 3; i++) {
92  if (m_t[i].isNull()) {
93  m_t[i] = dh.getPlusInfTm();
94  }
95  }
96 
97  if (m_lmfIOV == 0) {
98  throw(std::runtime_error(m_className + "::writeDB: LMFIOV not set"));
99  }
100  std::string sp = sequencePostfix(m_t[0]);
101  std::string sql = "INSERT INTO LMF_LMR_SUB_IOV (LMR_SUB_IOV_ID, "
102  "IOV_ID, T1, T2, T3) "
103  "VALUES (LMF_LMR_SUB_IOV_ID_" + sp + "_SQ.NextVal, :1, :2, :3, :4)";
104  stmt->setSQL(sql);
105  stmt->setInt(1, m_lmfIOV);
106  for (int i = 0; i < 3; i++) {
107  stmt->setDate(i + 2, dh.tmToDate(m_t[i]));
108  }
109  return sql;
110 }
111 
113  m_lmfIOV = rset->getInt(1);
114  for (int i = 0; i < 3; i++) {
115  oracle::occi::Date t = rset->getDate(i + 2);
116  m_t[i].setToString(t.toText("YYYY-MM-DD HH24:MI:SS"));
117  }
118 }
119 
120 std::list<int> LMFLmrSubIOV::getIOVIDsLaterThan(const Tm &t)
121  throw(std::runtime_error) {
122  Tm tinf;
123  tinf.setToString("9999-12-31 23:59:59");
124  return getIOVIDsLaterThan(t, tinf, 0);
125 }
126 
127 std::list<int> LMFLmrSubIOV::getIOVIDsLaterThan(const Tm &t, int howmany)
128  throw(std::runtime_error) {
129  Tm tinf;
130  tinf.setToString("9999-12-31 23:59:59");
131  return getIOVIDsLaterThan(t, tinf, howmany);
132 }
133 
134 std::list<int> LMFLmrSubIOV::getIOVIDsLaterThan(const Tm &tmin,
135  const Tm &tmax)
136  throw(std::runtime_error) {
137  return getIOVIDsLaterThan(tmin, tmax, 0);
138 }
139 
140 std::list<int> LMFLmrSubIOV::getIOVIDsLaterThan(const Tm &tmin, const Tm &tmax,
141  int howMany)
142  throw(std::runtime_error) {
143  Tm tinf;
144  tinf.setToString("9999-12-31 23:59:59");
145  std::string sql = "SELECT * FROM (SELECT LMR_SUB_IOV_ID "
146  "FROM CMS_ECAL_LASER_COND.LMF_LMR_SUB_IOV WHERE T3 > :1 ";
147  if (tmax != tinf) {
148  sql += "AND T3 < :2 ORDER BY T3 ASC) ";
149  if (howMany > 0) {
150  sql += "WHERE ROWNUM <= :3";
151  }
152  } else {
153  sql += "ORDER BY T3 ASC) ";
154  if (howMany > 0) {
155  sql += "WHERE ROWNUM <= :2";
156  }
157  }
158  if (m_debug) {
159  std::cout << "Executing query: " << std::endl << sql << std::endl;
160  }
161  std::list<int> ret;
162  if (m_conn != NULL) {
163  try {
164  DateHandler dh(m_env, m_conn);
165  Statement *stmt = m_conn->createStatement();
166  stmt->setPrefetchRowCount(10000);
167  stmt->setSQL(sql);
168  stmt->setDate(1, dh.tmToDate(tmin));
169  if (tmax != tinf) {
170  stmt->setDate(2, dh.tmToDate(tmax));
171  if (howMany > 0) {
172  stmt->setInt(3, howMany);
173  }
174  } else {
175  if (howMany > 0) {
176  stmt->setInt(2, howMany);
177  }
178  }
179  ResultSet *rset = stmt->executeQuery();
180  int row = 1;
181  while (rset->next() != 0) {
182  if (m_debug) {
183  std::cout << "Getting row " << row++ << std::endl;
184  }
185  ret.push_back(rset->getInt(1));
186  }
187  stmt->setPrefetchRowCount(0);
188  m_conn->terminateStatement(stmt);
189  }
190  catch (oracle::occi::SQLException e) {
191  throw(std::runtime_error(m_className + "::getLmrSubIOVLaterThan: " +
192  e.getMessage()));
193  }
194  } else {
195  throw(std::runtime_error(m_className + "::getLmrSubIOVLaterThan: " +
196  "Connection not set"));
197  }
198  if (m_debug) {
199  std::cout << "Sorting..." << std::flush;
200  }
201  ret.sort();
202  if (m_debug) {
203  std::cout << "Done!" << std::endl << std::flush;
204  }
205  return ret;
206 }
207 
208 
std::string m_className
Definition: LMFUnique.h:99
int i
Definition: DBlmapReader.cc:9
void getParameters(ResultSet *rset)
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
int getID() const
Definition: LMFUnique.h:52
std::list< int > getIOVIDsLaterThan(const Tm &t)
oracle::occi::ResultSet ResultSet
Definition: LMFUnique.h:19
#define NULL
Definition: scimark2.h:8
std::string setByIDSql(Statement *stmt, int id)
Definition: LMFLmrSubIOV.cc:78
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
std::string fetchIdSql(Statement *stmt)
Definition: LMFLmrSubIOV.cc:52
std::string sequencePostfix(Tm t)
Definition: LMFUnique.cc:10
LMFLmrSubIOV & setTimes(Tm t1, Tm t2, Tm t3)
Definition: LMFLmrSubIOV.cc:45
tuple iov
Definition: o2o.py:307
oracle::occi::Statement Statement
Definition: LMFUnique.h:20
void setToString(const std::string s)
Definition: Tm.cc:193
oracle::occi::Date tmToDate(const Tm &inTm) const
Definition: DateHandler.cc:20
Tm getPlusInfTm() const
Definition: DateHandler.h:15
Definition: LMFIOV.h:17
static const double tmax[3]
tuple cout
Definition: gather_cfg.py:121
char m_debug
Definition: LMFUnique.h:100
Definition: Tm.h:14
tuple conn
Definition: results_mgr.py:53
std::string writeDBSql(Statement *stmt)
Definition: LMFLmrSubIOV.cc:87
LMFLmrSubIOV & setLMFIOV(const LMFIOV &iov)
Definition: LMFLmrSubIOV.cc:29