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