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 LMF_RUN_IOV WHERE SEQ_ID = :1 "
222  "AND LMR = :2 ";
223  if (m_intFields["tag_id"] > 0) {
224  sql += "AND TAG_ID = :3";
225  }
226  stmt->setSQL(sql);
227  stmt->setInt(1, m_intFields["seq_id"]);
228  stmt->setInt(2, m_intFields["lmr"]);
229  if (m_intFields["tag_id"] > 0) {
230  stmt->setInt(3, m_intFields["tag_id"]);
231  }
232  return sql;
233 }
234 
235 std::string LMFRunIOV::setByIDSql(Statement *stmt, int id)
236 {
237  DateHandler dh(m_env, m_conn);
238  std::string sql = "SELECT TAG_ID, SEQ_ID, LMR, COLOR_ID, TRIG_TYPE, "
239  "SUBRUN_START, SUBRUN_END, SUBRUN_TYPE, DB_TIMESTAMP FROM LMF_RUN_IOV "
240  "WHERE LMF_IOV_ID = :1";
241  stmt->setSQL(sql);
242  stmt->setInt(1, id);
243  return sql;
244 }
245 
247  DateHandler dh(m_env, m_conn);
248  setLMFRunTag(rset->getInt(1));
249  LMFSeqDat *seq;
250  if (m_foreignKeys.find("sequence") != m_foreignKeys.end()) {
251  seq = (LMFSeqDat*)m_foreignKeys["sequence"];
252  setInt("seq_id", seq->getID());
253  } else {
254  seq = new LMFSeqDat;
255  seq->setConnection(m_env, m_conn);
256  seq->setByID(rset->getInt(2));
257  setInt("seq_id", seq->getID());
258  delete seq;
259  }
260  setInt("lmr", rset->getInt(3));
261  setColor(rset->getInt(4));
262  setTriggerType(rset->getInt(5));
263  Date start = rset->getDate(6);
264  setString("subrun_start", dh.dateToTm(start).str());
265  Date stop = rset->getDate(7);
266  setString("subrun_end", dh.dateToTm(stop).str());
267  setString("subrun_type", rset->getString(8));
268  setString("db_timestamp", rset->getTimestamp(9).toText("YYYY-MM-DD HH24:MI:SS", 0));
269 }
270 
272  bool ret = true;
273  if (!getLMFRunTag().isValid()) {
274  ret = false;
275  }
276  if (!getSequence().isValid()) {
277  ret = false;
278  }
279  if (!getTriggerType().isValid()) {
280  ret = false;
281  }
282  if ((getLmr() < 0) || (getLmr() > 92)) {
283  ret = false;
284  }
285  if (!getLMFColor().isValid()) {
286  ret = false;
287  }
288  // subrun start and end are by definition valid
289  return ret;
290 }
291 
292 std::string LMFRunIOV::writeDBSql(Statement *stmt)
293 {
294  // check that everything has been setup
295  int tag_id = getInt("tag_id");
296  int seq_id = getInt("seq_id");
297  int color_id = getInt("color_id");
298  int tt = getInt("trigType_id");
299  std::string sp = sequencePostfix(getSubRunStart());
300  std::string sql = "INSERT INTO LMF_RUN_IOV (LMF_IOV_ID, TAG_ID, SEQ_ID, "
301  "LMR, COLOR_ID, TRIG_TYPE, SUBRUN_START, SUBRUN_END, SUBRUN_TYPE) VALUES "
302  "(lmf_run_iov_" + sp + "_sq.NextVal, :1, :2, :3, :4, :5, :6, :7, :8)";
303  stmt->setSQL(sql);
304  DateHandler dm(m_env, m_conn);
305  stmt->setInt(1, tag_id);
306  stmt->setInt(2, seq_id);
307  stmt->setInt(3, getInt("lmr"));
308  stmt->setInt(4, color_id);
309  stmt->setInt(5, tt);
310  stmt->setDate(6, dm.tmToDate(getSubRunStart()));
311  stmt->setDate(7, dm.tmToDate(getSubRunEnd()));
312  stmt->setString(8, getSubRunType());
313  return sql;
314 }
315 
316 std::list<LMFRunIOV> LMFRunIOV::fetchBySequence(vector<int> par,
317  const std::string &sql,
318  const std::string &method)
319  throw(std::runtime_error)
320 {
321  std::list<LMFRunIOV> l;
322  this->checkConnection();
323  try {
324  Statement *stmt = m_conn->createStatement();
325  stmt->setSQL(sql);
326  for (unsigned int i = 0; i < par.size(); i++) {
327  stmt->setInt(i + 1, par[i]);
328  }
329  ResultSet *rset = stmt->executeQuery();
330  while (rset->next()) {
331  int lmf_iov_id = rset->getInt(1);
332  LMFRunIOV iov;
333  iov.setConnection(m_env, m_conn);
334  iov.setByID(lmf_iov_id);
335  l.push_back(iov);
336  }
337  m_conn->terminateStatement(stmt);
338  } catch (SQLException &e) {
339  throw(std::runtime_error(m_className + "::" + method + ": " +
340  e.getMessage()));
341  }
342  return l;
343 }
344 
345 std::list<LMFRunIOV> LMFRunIOV::fetchBySequence(const LMFSeqDat &s) {
346  int seq_id = s.getID();
347  vector<int> parameters;
348  parameters.push_back(seq_id);
349  return fetchBySequence(parameters, "SELECT LMF_IOV_ID FROM LMF_RUN_IOV "
350  "WHERE SEQ_ID = :1", "fetchBySequence");
351 }
352 
353 std::list<LMFRunIOV> LMFRunIOV::fetchBySequence(const LMFSeqDat &s, int lmr) {
354  int seq_id = s.getID();
355  vector<int> parameters;
356  parameters.push_back(seq_id);
357  parameters.push_back(lmr);
358  return fetchBySequence(parameters, "SELECT LMF_IOV_ID FROM LMF_RUN_IOV "
359  "WHERE SEQ_ID = :1 AND LMR = :2",
360  "fetchBySequence");
361 }
362 
363 std::list<LMFRunIOV> LMFRunIOV::fetchBySequence(const LMFSeqDat &s, int lmr,
364  int type, int color) {
365  int seq_id = s.getID();
366  vector<int> parameters;
367  parameters.push_back(seq_id);
368  parameters.push_back(lmr);
369  parameters.push_back(color);
370  parameters.push_back(type);
371  return fetchBySequence(parameters, "SELECT LMF_IOV_ID FROM LMF_RUN_IOV "
372  "WHERE SEQ_ID = :1 AND LMR = :2 AND COLOR_ID = :3 "
373  "AND TRIG_TYPE = :4",
374  "fetchBySequence");
375 }
376 
377 std::list<LMFRunIOV> LMFRunIOV::fetchLastBeforeSequence(const LMFSeqDat &s,
378  int lmr, int type,
379  int color) {
380  int seq_id = s.getID();
381  vector<int> parameters;
382  parameters.push_back(seq_id);
383  parameters.push_back(lmr);
384  parameters.push_back(color);
385  parameters.push_back(type);
386  return fetchBySequence(parameters, "SELECT LMF_IOV_ID FROM (SELECT "
387  "SEQ_ID, LMF_IOV_ID FROM LMF_RUN_IOV "
388  "WHERE SEQ_ID < :1 AND LMR = :2 AND COLOR_ID = :3 "
389  "AND TRIG_TYPE = :4 ORDER BY SEQ_ID DESC) WHERE "
390  "ROWNUM <= 1",
391  "fetchBySequence");
392 }
393 
395  if (this != &r) {
397  if (r._fabric != NULL) {
398  checkFabric();// _fabric = new LMFDefFabric;
399  if (m_debug) {
400  _fabric->debug();
401  std::cout << "COPYING INTO " << _fabric << std::endl;
402  }
403  *_fabric = *(r._fabric);
404  }
405  }
406  return *this;
407 }
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:246
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:51
std::list< LMFRunIOV > fetchBySequence(const LMFSeqDat &s)
Definition: LMFRunIOV.cc:345
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:394
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:106
~LMFRunIOV()
Definition: LMFRunIOV.cc:47
void setToCurrentGMTime()
Definition: Tm.cc:156
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
int getInt(std::string fieldname) const
Definition: LMFUnique.cc:197
LMFRunIOV & setSequence(LMFSeqDat &seq)
Definition: LMFRunIOV.cc:193
std::string getLongName() const
Definition: LMFColor.h:45
void setByID(int id)
Definition: LMFUnique.cc:280
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:235
bool isValid()
Definition: LMFRunIOV.cc:271
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:172
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:105
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:82
tuple cout
Definition: gather_cfg.py:41
std::string getString(std::string fieldname) const
Definition: LMFUnique.cc:188
char m_debug
Definition: LMFUnique.h:99
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
string s
Definition: asciidump.py:422
std::list< LMFRunIOV > fetchLastBeforeSequence(const LMFSeqDat &s, int lmr, int type, int color)
Definition: LMFRunIOV.cc:377
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
std::string writeDBSql(Statement *stmt)
Definition: LMFRunIOV.cc:292
std::map< std::string, int > m_intFields
Definition: LMFUnique.h:103
const double par[8 *NPar][4]