CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LMFRunIOV.cc
Go to the documentation of this file.
4 
5 using namespace std;
6 using namespace oracle::occi;
7 
9  Tm tm;
10  tm.setToCurrentGMTime();
11 
12  m_intFields["lmr"] = 0;
13  m_intFields["tag_id"] = 0;
14  m_intFields["seq_id"] = 0;
15  m_intFields["color_id"] = 0;
16  m_intFields["trigType_id"] = 0;
17  m_stringFields["subrun_start"] = tm.str();
18  m_stringFields["subrun_end"] = tm.str();
19  m_stringFields["db_timestamp"] = tm.str();
20  m_stringFields["subrun_type"] = "none";
21  m_className = "LMFRunIOV";
22 
23  _fabric = NULL;
24 }
25 
27 {
28  initialize();
29 }
30 
31 LMFRunIOV::LMFRunIOV(oracle::occi::Environment* env,
32  oracle::occi::Connection* conn) : LMFUnique(env, conn)
33 {
34  initialize();
35 }
36 
38 {
39  initialize();
40 }
41 
43  initialize();
44  *this = r;
45 }
46 
48 {
49  if (_fabric != NULL) {
50  delete _fabric;
51  }
52 }
53 
55 {
56  setInt("tag_id", tag.getID());
57  return *this;
58 }
59 
61 {
62  setInt("tag_id", tag_id);
63  return *this;
64 }
65 
67 {
69  rtag.setByID(getInt("tag_id"));
70  return rtag;
71 }
72 
74 {
75  setInt("color_id", color.getID());
76  return *this;
77 }
78 
80 {
81  setInt("color_id", color_id);
82  return *this;
83 }
84 
86  if (_fabric == NULL) {
88  }
89 }
90 
92 {
93  checkFabric();
94  setInt("color_id", _fabric->getColorID(color_index));
95  return *this;
96 }
97 
99 {
100  checkFabric();
101  setInt("color_id", _fabric->getColorID(name));
102  return *this;
103 }
104 
106 {
107  LMFColor rcol = LMFColor(m_env, m_conn);
108  rcol.setByID(getInt("color_id"));
109  return rcol;
110 }
111 
112 std::string LMFRunIOV::getColorShortName() const {
113  LMFColor rcol = getLMFColor();
114  return rcol.getShortName();
115 }
116 
117 std::string LMFRunIOV::getColorLongName() const {
118  LMFColor rcol = getLMFColor();
119  return rcol.getLongName();
120 }
121 
123 {
124  setInt("trigType_id", trigType.getID());
125  return *this;
126 }
127 
129 {
130  checkFabric();
131  setInt("trigType_id", _fabric->getTrigTypeID(sname));
132  return *this;
133 }
134 
136  setInt("trigType_id", id);
137  return *this;
138 }
139 
141 {
143  rt.setByID(getInt("trigType_id"));
144  return rt;
145 }
146 
148  setInt("lmr", n);
149  return *this;
150 }
151 
152 int LMFRunIOV::getLmr() const {
153  return getInt("lmr");
154 }
155 
157  setString("subrun_start", start.str());
158  return *this;
159 }
160 
162  Tm t;
163  t.setToString(getString("subrun_start"));
164  return t;
165 }
166 
168  setString("subrun_end", stop.str());
169  return *this;
170 }
171 
173  Tm t;
174  t.setToString(getString("subrun_end"));
175  return t;
176 }
177 
179  Tm t;
180  t.setToString(getString("db_timestamp"));
181  return t;
182 }
183 
184 LMFRunIOV& LMFRunIOV::setSubRunType(const std::string &s) {
185  setString("subrun_type", s);
186  return *this;
187 }
188 
189 std::string LMFRunIOV::getSubRunType() const {
190  return getString("subrun_type");
191 }
192 
194 {
195  LMFSeqDat *seqdat = new LMFSeqDat();
196  *seqdat = seq;
197  attach("sequence", seqdat);
198  setInt("seq_id", seqdat->getID());
199  return *this;
200 }
201 
203 {
205  rs.setByID(getInt("seq_id"));
206  return rs;
207 }
208 
209 void LMFRunIOV::dump() const {
210  LMFUnique::dump();
211  std::cout << "# Fabric Address: " << _fabric << std::endl;
212  if (m_debug) {
213  _fabric->dump();
214  }
215 }
216 
218 {
219  std::string sql = "";
220 
221  sql = "SELECT LMF_IOV_ID FROM CMS_ECAL_LASER_COND.LMF_RUN_IOV WHERE "
222  "SEQ_ID = :1 "
223  "AND LMR = :2 ";
224  if (m_intFields["tag_id"] > 0) {
225  sql += "AND TAG_ID = :3";
226  }
227  stmt->setSQL(sql);
228  stmt->setInt(1, m_intFields["seq_id"]);
229  stmt->setInt(2, m_intFields["lmr"]);
230  if (m_intFields["tag_id"] > 0) {
231  stmt->setInt(3, m_intFields["tag_id"]);
232  }
233  return sql;
234 }
235 
236 std::string LMFRunIOV::setByIDSql(Statement *stmt, int id)
237 {
238  DateHandler dh(m_env, m_conn);
239  std::string sql = "SELECT TAG_ID, SEQ_ID, LMR, COLOR_ID, TRIG_TYPE, "
240  "SUBRUN_START, SUBRUN_END, SUBRUN_TYPE, DB_TIMESTAMP FROM "
241  "CMS_ECAL_LASER_COND.LMF_RUN_IOV "
242  "WHERE LMF_IOV_ID = :1";
243  stmt->setSQL(sql);
244  stmt->setInt(1, id);
245  return sql;
246 }
247 
249  DateHandler dh(m_env, m_conn);
250  setLMFRunTag(rset->getInt(1));
251  LMFSeqDat *seq;
252  if (m_foreignKeys.find("sequence") != m_foreignKeys.end()) {
253  seq = (LMFSeqDat*)m_foreignKeys["sequence"];
254  setInt("seq_id", seq->getID());
255  } else {
256  seq = new LMFSeqDat;
257  seq->setConnection(m_env, m_conn);
258  seq->setByID(rset->getInt(2));
259  setInt("seq_id", seq->getID());
260  delete seq;
261  }
262  setInt("lmr", rset->getInt(3));
263  setColor(rset->getInt(4));
264  setTriggerType(rset->getInt(5));
265  Date start = rset->getDate(6);
266  setString("subrun_start", dh.dateToTm(start).str());
267  Date stop = rset->getDate(7);
268  setString("subrun_end", dh.dateToTm(stop).str());
269  setString("subrun_type", rset->getString(8));
270  setString("db_timestamp", rset->getTimestamp(9).toText("YYYY-MM-DD HH24:MI:SS", 0));
271 }
272 
274  bool ret = true;
275  if (!getLMFRunTag().isValid()) {
276  ret = false;
277  }
278  if (!getSequence().isValid()) {
279  ret = false;
280  }
281  if (!getTriggerType().isValid()) {
282  ret = false;
283  }
284  if ((getLmr() < 0) || (getLmr() > 92)) {
285  ret = false;
286  }
287  if (!getLMFColor().isValid()) {
288  ret = false;
289  }
290  // subrun start and end are by definition valid
291  return ret;
292 }
293 
294 std::string LMFRunIOV::writeDBSql(Statement *stmt)
295 {
296  // check that everything has been setup
297  int tag_id = getInt("tag_id");
298  int seq_id = getInt("seq_id");
299  int color_id = getInt("color_id");
300  int tt = getInt("trigType_id");
301  std::string sp = sequencePostfix(getSubRunStart());
302  std::string sql = "INSERT INTO LMF_RUN_IOV (LMF_IOV_ID, TAG_ID, SEQ_ID, "
303  "LMR, COLOR_ID, TRIG_TYPE, SUBRUN_START, SUBRUN_END, SUBRUN_TYPE) VALUES "
304  "(lmf_run_iov_" + sp + "_sq.NextVal, :1, :2, :3, :4, :5, :6, :7, :8)";
305  stmt->setSQL(sql);
306  DateHandler dm(m_env, m_conn);
307  stmt->setInt(1, tag_id);
308  stmt->setInt(2, seq_id);
309  stmt->setInt(3, getInt("lmr"));
310  stmt->setInt(4, color_id);
311  stmt->setInt(5, tt);
312  stmt->setDate(6, dm.tmToDate(getSubRunStart()));
313  stmt->setDate(7, dm.tmToDate(getSubRunEnd()));
314  stmt->setString(8, getSubRunType());
315  return sql;
316 }
317 
318 std::list<LMFRunIOV> LMFRunIOV::fetchBySequence(vector<int> par,
319  const std::string &sql,
320  const std::string &method)
321  throw(std::runtime_error)
322 {
323  std::list<LMFRunIOV> l;
324  this->checkConnection();
325  try {
326  Statement *stmt = m_conn->createStatement();
327  stmt->setSQL(sql);
328  for (unsigned int i = 0; i < par.size(); i++) {
329  stmt->setInt(i + 1, par[i]);
330  }
331  ResultSet *rset = stmt->executeQuery();
332  while (rset->next() != 0) {
333  int lmf_iov_id = rset->getInt(1);
334  LMFRunIOV iov;
335  iov.setConnection(m_env, m_conn);
336  iov.setByID(lmf_iov_id);
337  l.push_back(iov);
338  }
339  m_conn->terminateStatement(stmt);
340  } catch (SQLException &e) {
341  throw(std::runtime_error(m_className + "::" + method + ": " +
342  e.getMessage()));
343  }
344  return l;
345 }
346 
347 std::list<LMFRunIOV> LMFRunIOV::fetchBySequence(const LMFSeqDat &s) {
348  int seq_id = s.getID();
349  vector<int> parameters;
350  parameters.push_back(seq_id);
351  return fetchBySequence(parameters, "SELECT LMF_IOV_ID FROM "
352  "CMS_ECAL_LASER_COND.LMF_RUN_IOV "
353  "WHERE SEQ_ID = :1", "fetchBySequence");
354 }
355 
356 std::list<LMFRunIOV> LMFRunIOV::fetchBySequence(const LMFSeqDat &s, int lmr) {
357  int seq_id = s.getID();
358  vector<int> parameters;
359  parameters.push_back(seq_id);
360  parameters.push_back(lmr);
361  return fetchBySequence(parameters, "SELECT LMF_IOV_ID FROM "
362  "CMS_ECAL_LASER_COND.LMF_RUN_IOV "
363  "WHERE SEQ_ID = :1 AND LMR = :2",
364  "fetchBySequence");
365 }
366 
367 std::list<LMFRunIOV> LMFRunIOV::fetchBySequence(const LMFSeqDat &s, int lmr,
368  int type, int color) {
369  int seq_id = s.getID();
370  vector<int> parameters;
371  parameters.push_back(seq_id);
372  parameters.push_back(lmr);
373  parameters.push_back(color);
374  parameters.push_back(type);
375  return fetchBySequence(parameters, "SELECT LMF_IOV_ID FROM "
376  "CMS_ECAL_LASER_COND.LMF_RUN_IOV "
377  "WHERE SEQ_ID = :1 AND LMR = :2 AND COLOR_ID = :3 "
378  "AND TRIG_TYPE = :4",
379  "fetchBySequence");
380 }
381 
382 std::list<LMFRunIOV> LMFRunIOV::fetchLastBeforeSequence(const LMFSeqDat &s,
383  int lmr, int type,
384  int color) {
385  int seq_id = s.getID();
386  vector<int> parameters;
387  parameters.push_back(seq_id);
388  parameters.push_back(lmr);
389  parameters.push_back(color);
390  parameters.push_back(type);
391  return fetchBySequence(parameters, "SELECT LMF_IOV_ID FROM (SELECT "
392  "SEQ_ID, LMF_IOV_ID FROM "
393  "CMS_ECAL_LASER_COND.LMF_RUN_IOV "
394  "WHERE SEQ_ID < :1 AND LMR = :2 AND COLOR_ID = :3 "
395  "AND TRIG_TYPE = :4 ORDER BY SEQ_ID DESC) WHERE "
396  "ROWNUM <= 1",
397  "fetchBySequence");
398 }
399 
401  if (this != &r) {
403  if (r._fabric != NULL) {
404  checkFabric();// _fabric = new LMFDefFabric;
405  if (m_debug) {
406  _fabric->debug();
407  std::cout << "COPYING INTO " << _fabric << std::endl;
408  }
409  *_fabric = *(r._fabric);
410  }
411  }
412  return *this;
413 }
nocap nocap const skelname & operator=(const skelname &)
std::string getSubRunType() const
Definition: LMFRunIOV.cc:189
type
Definition: HCALResponse.h:22
void getParameters(ResultSet *rset)
Definition: LMFRunIOV.cc:248
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
LMFUnique & setInt(std::string key, int value)
Definition: LMFUnique.cc:33
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< LMFRunIOV > fetchBySequence(const LMFSeqDat &s)
Definition: LMFRunIOV.cc:347
std::string fetchIdSql(Statement *stmt)
Definition: LMFRunIOV.cc:217
LMFRunIOV & setLMFRunTag(const LMFRunTag &tag)
Definition: LMFRunIOV.cc:54
virtual LMFRunIOV & operator=(const LMFRunIOV &r)
Definition: LMFRunIOV.cc:400
LMFRunIOV & setSubRunType(const std::string &x)
Definition: LMFRunIOV.cc:184
Tm getDBInsertionTime() const
Definition: LMFRunIOV.cc:178
Tm getSubRunStart() const
Definition: LMFRunIOV.cc:161
LMFColor getLMFColor() const
Definition: LMFRunIOV.cc:105
oracle::occi::ResultSet ResultSet
Definition: LMFUnique.h:19
#define NULL
Definition: scimark2.h:8
std::string getColorShortName() const
Definition: LMFRunIOV.cc:112
int getColorID(std::string name) const
Definition: LMFDefFabric.cc:95
virtual void dump() const
Definition: LMFUnique.cc:112
~LMFRunIOV()
Definition: LMFRunIOV.cc:47
void setToCurrentGMTime()
Definition: Tm.cc:177
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
int getInt(std::string fieldname) const
Definition: LMFUnique.cc:203
LMFRunIOV & setSequence(LMFSeqDat &seq)
Definition: LMFRunIOV.cc:193
std::string getLongName() const
Definition: LMFColor.h:45
void setByID(int id)
Definition: LMFUnique.cc:286
std::string sequencePostfix(Tm t)
Definition: LMFUnique.cc:10
LMFRunIOV & setSubRunStart(Tm start)
Definition: LMFRunIOV.cc:156
void checkFabric()
Definition: LMFRunIOV.cc:85
std::string setByIDSql(Statement *stmt, int id)
Definition: LMFRunIOV.cc:236
bool isValid()
Definition: LMFRunIOV.cc:273
LMFSeqDat getSequence() const
Definition: LMFRunIOV.cc:202
tuple iov
Definition: o2o.py:307
LMFRunIOV & setTriggerType(LMFTrigType &tt)
Definition: LMFRunIOV.cc:122
int getLmr() const
Definition: LMFRunIOV.cc:152
oracle::occi::Statement Statement
Definition: LMFUnique.h:20
void setToString(const std::string s)
Definition: Tm.cc:193
LMFTrigType getTriggerType() const
Definition: LMFRunIOV.cc:140
std::string getShortName() const
Definition: LMFColor.h:44
void initialize()
Definition: LMFRunIOV.cc:8
oracle::occi::Date tmToDate(const Tm &inTm) const
Definition: DateHandler.cc:20
std::map< std::string, LMFUnique * > m_foreignKeys
Definition: LMFUnique.h:106
LMFRunIOV & setSubRunEnd(Tm end)
Definition: LMFRunIOV.cc:167
LMFUnique & setString(std::string key, std::string value)
Definition: LMFUnique.cc:15
virtual void dump() const
Definition: LMFRunIOV.cc:209
int getTrigTypeID(std::string sname) const
LMFRunIOV & setColorIndex(int color_index)
Definition: LMFRunIOV.cc:91
Tm getSubRunEnd() const
Definition: LMFRunIOV.cc:172
LMFDefFabric * _fabric
Definition: LMFRunIOV.h:99
std::string getColorLongName() const
Definition: LMFRunIOV.cc:117
LMFRunIOV & setLmr(int n)
Definition: LMFRunIOV.cc:147
std::string str() const
Definition: Tm.cc:89
tuple cout
Definition: gather_cfg.py:121
std::string getString(std::string fieldname) const
Definition: LMFUnique.cc:194
char m_debug
Definition: LMFUnique.h:100
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
std::list< LMFRunIOV > fetchLastBeforeSequence(const LMFSeqDat &s, int lmr, int type, int color)
Definition: LMFRunIOV.cc:382
LMFRunIOV & setColor(const LMFColor &c)
Definition: LMFRunIOV.cc:73
void attach(std::string name, LMFUnique *u)
Definition: LMFUnique.cc:50
Tm dateToTm(oracle::occi::Date &date) const
Definition: DateHandler.cc:31
LMFRunTag getLMFRunTag() const
Definition: LMFRunIOV.cc:66
Definition: Tm.h:14
tuple conn
Definition: results_mgr.py:53
std::string writeDBSql(Statement *stmt)
Definition: LMFRunIOV.cc:294
std::map< std::string, int > m_intFields
Definition: LMFUnique.h:104