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) {
410  LMFUnique::operator=(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 }
Tm::str
std::string str() const
Definition: Tm.cc:66
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
LMFTrigType
Definition: LMFTrigType.h:10
LMFRunIOV::initialize
void initialize()
Definition: LMFRunIOV.cc:10
mps_fire.i
i
Definition: mps_fire.py:355
start
Definition: start.py:1
LMFRunIOV::checkFabric
void checkFabric()
Definition: LMFRunIOV.cc:73
LMFUnique::setByID
void setByID(int id) noexcept(false) override
Definition: LMFUnique.cc:267
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
cmsswSequenceInfo.seq
seq
Definition: cmsswSequenceInfo.py:540
groupFilesInBlocks.tt
int tt
Definition: groupFilesInBlocks.py:144
LMFRunTag
Definition: LMFRunTag.h:16
gather_cfg.cout
cout
Definition: gather_cfg.py:144
AlcaSiPixelAliHarvester0T_cff.method
method
Definition: AlcaSiPixelAliHarvester0T_cff.py:41
hcal_runs.rt
rt
Definition: hcal_runs.py:76
LMFColor::getLongName
std::string getLongName() const
Definition: LMFColor.h:44
SiStripCommissioningClient_cfg.conn
conn
Definition: SiStripCommissioningClient_cfg.py:5
LMFColor
Definition: LMFColor.h:12
LMFRunIOV::getParameters
void getParameters(ResultSet *rset) override
Definition: LMFRunIOV.cc:225
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
LMFRunIOV::setSubRunEnd
LMFRunIOV & setSubRunEnd(const Tm &end)
Definition: LMFRunIOV.cc:147
LMFDefFabric::getTrigTypeID
int getTrigTypeID(std::string sname) const
Definition: LMFDefFabric.cc:85
LMFColor::getShortName
std::string getShortName() const
Definition: LMFColor.h:43
LMFUnique::setInt
LMFUnique & setInt(std::string key, int value)
Definition: LMFUnique.cc:31
LMFRunIOV::getColorShortName
std::string getColorShortName() const
Definition: LMFRunIOV.cc:97
LMFUnique::getInt
int getInt(std::string fieldname) const
Definition: LMFUnique.cc:187
LMFUnique::m_debug
char m_debug
Definition: LMFUnique.h:96
parameters
parameters
Definition: BeamSpot_PayloadInspector.cc:14
LMFUnique::m_intFields
std::map< std::string, int > m_intFields
Definition: LMFUnique.h:100
alignCSCRings.s
s
Definition: alignCSCRings.py:92
LMFRunIOV::setSubRunStart
LMFRunIOV & setSubRunStart(const Tm &start)
Definition: LMFRunIOV.cc:136
LMFUnique::dump
virtual void dump() const
Definition: LMFUnique.cc:104
LMFDefFabric::getColorID
int getColorID(std::string name) const
Definition: LMFDefFabric.cc:81
LMFRunIOV::_fabric
LMFDefFabric * _fabric
Definition: LMFRunIOV.h:89
IDBObject::m_conn
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
LMFRunIOV::fetchLastBeforeSequence
std::list< LMFRunIOV > fetchLastBeforeSequence(const LMFSeqDat &s, int lmr, int type, int color)
Definition: LMFRunIOV.cc:391
LMFRunIOV::getLMFColor
LMFColor getLMFColor() const
Definition: LMFRunIOV.cc:91
LMFRunIOV
Definition: LMFRunIOV.h:18
oracle::occi
Definition: ConnectionManager.h:7
LMFRunIOV::getSequence
LMFSeqDat getSequence() const
Definition: LMFRunIOV.cc:180
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
LMFRunIOV::LMFRunIOV
LMFRunIOV()
Definition: LMFRunIOV.cc:28
LMFRunIOV::getLmr
int getLmr() const
Definition: LMFRunIOV.cc:134
Tm::setToCurrentGMTime
void setToCurrentGMTime()
Definition: Tm.cc:141
OrderedSet.t
t
Definition: OrderedSet.py:90
Tm
Definition: Tm.h:13
LMFRunIOV::isValid
bool isValid() override
Definition: LMFRunIOV.cc:281
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
web.browse_db.env
env
Definition: browse_db.py:18
LMFRunIOV::setTriggerType
LMFRunIOV & setTriggerType(LMFTrigType &tt)
Definition: LMFRunIOV.cc:107
LMFRunIOV::dump
void dump() const override
Definition: LMFRunIOV.cc:186
LMFRunIOV::getLMFRunTag
LMFRunTag getLMFRunTag() const
Definition: LMFRunIOV.cc:57
LMFDefFabric
Definition: LMFDefFabric.h:25
LMFUnique::attach
void attach(std::string name, LMFUnique *u)
Definition: LMFUnique.cc:48
LMFRunIOV::getSubRunType
std::string getSubRunType() const
Definition: LMFRunIOV.cc:170
LMFUnique::getString
std::string getString(std::string fieldname) const
Definition: LMFUnique.cc:178
symbols.dm
dm
Definition: symbols.py:66
LMFRunIOV::fetchBySequence
std::list< LMFRunIOV > fetchBySequence(const LMFSeqDat &s)
Definition: LMFRunIOV.cc:353
LMFRunIOV.h
LMFRunIOV::setByIDSql
std::string setByIDSql(Statement *stmt, int id) override
Definition: LMFRunIOV.cc:213
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
LMFSeqDat
Definition: LMFSeqDat.h:14
LMFRunIOV::getColorLongName
std::string getColorLongName() const
Definition: LMFRunIOV.cc:102
LMFRunIOV::setLmr
LMFRunIOV & setLmr(int n)
Definition: LMFRunIOV.cc:129
util.getRunInfo.day
def day(string)
Definition: getRunInfo.py:11
LMFRunIOV::~LMFRunIOV
~LMFRunIOV() override
Definition: LMFRunIOV.cc:41
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:193
alignCSCRings.r
r
Definition: alignCSCRings.py:93
LMFDefFabric::debug
void debug()
Definition: LMFDefFabric.cc:26
LMFRunIOV::getTriggerType
LMFTrigType getTriggerType() const
Definition: LMFRunIOV.cc:123
LMFRunIOV::operator=
virtual LMFRunIOV & operator=(const LMFRunIOV &r)
Definition: LMFRunIOV.cc:408
LMFDefFabric.h
LMFRunIOV::setColorIndex
LMFRunIOV & setColorIndex(int color_index)
Definition: LMFRunIOV.cc:79
type
type
Definition: HCALResponse.h:21
std
Definition: JetResolutionObject.h:76
LMFUnique::getID
int getID() const
Definition: LMFUnique.h:54
IDBObject::setConnection
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
LMFDefFabric::dump
void dump()
Definition: LMFDefFabric.cc:225
HBDarkeningEP_cfi.year
year
Definition: HBDarkeningEP_cfi.py:23
LMFUnique::Statement
oracle::occi::Statement Statement
Definition: LMFUnique.h:20
LMFRunIOV::getSubRunStart
Tm getSubRunStart() const
Definition: LMFRunIOV.cc:141
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
LMFRunIOV::setSequence
LMFRunIOV & setSequence(LMFSeqDat &seq)
Definition: LMFRunIOV.cc:172
LMFUnique::setString
LMFUnique & setString(std::string key, std::string value)
Definition: LMFUnique.cc:14
DateHandler.h
LMFRunIOV::setLMFRunTag
LMFRunIOV & setLMFRunTag(const LMFRunTag &tag)
Definition: LMFRunIOV.cc:47
IDBObject::m_env
oracle::occi::Environment * m_env
Definition: IDBObject.h:33
LMFUnique::sequencePostfix
std::string sequencePostfix(const Tm &t)
Definition: LMFUnique.cc:9
LMFRunIOV::getDBInsertionTime
Tm getDBInsertionTime() const
Definition: LMFRunIOV.cc:159
LMFUnique
Definition: LMFUnique.h:17
DateHandler
Definition: DateHandler.h:7
cuy.dh
dh
Definition: cuy.py:355
LMFRunIOV::getSubRunEnd
Tm getSubRunEnd() const
Definition: LMFRunIOV.cc:152
LMFRunIOV::setColor
LMFRunIOV & setColor(const LMFColor &c)
Definition: LMFRunIOV.cc:63
LMFRunIOV::writeDBSql
std::string writeDBSql(Statement *stmt) override
Definition: LMFRunIOV.cc:302
EcalDBConnection
Definition: EcalDBConnection.h:15
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
LMFRunIOV::setSubRunType
LMFRunIOV & setSubRunType(const std::string &x)
Definition: LMFRunIOV.cc:165
LMFRunIOV::fetchIdSql
std::string fetchIdSql(Statement *stmt) override
Definition: LMFRunIOV.cc:194
LMFUnique::ResultSet
oracle::occi::ResultSet ResultSet
Definition: LMFUnique.h:19