CMS 3D CMS Logo

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