CMS 3D CMS Logo

LMFSeqDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <sstream>
3 #include <climits>
6 
7 using namespace std;
8 using namespace oracle::occi;
9 
11  setClassName("LMFSeqDat");
12 
13  m_runIOV = RunIOV();
14  m_intFields["seq_num"] = 0;
15  Tm t;
16  t = t.plusInfinity();
17  m_stringFields["seq_start"] = t.str();
18  m_stringFields["seq_stop"] = t.str();
19  m_intFields["vmin"] = 1;
20  m_intFields["vmax"] = 0;
21 }
22 
24  setClassName("LMFSeqDat");
25 
26  m_runIOV = RunIOV();
27  m_intFields["seq_num"] = 0;
28  Tm t;
29  t = t.plusInfinity();
30  m_stringFields["seq_start"] = t.str();
31  m_stringFields["seq_stop"] = t.str();
32  m_intFields["vmin"] = 1;
33  m_intFields["vmax"] = 0;
34 }
35 
36 LMFSeqDat::LMFSeqDat(oracle::occi::Environment *env, oracle::occi::Connection *conn) : LMFUnique(env, conn) {
37  setClassName("LMFSeqDat");
38 
39  m_runIOV = RunIOV();
40  m_intFields["seq_num"] = 0;
41  Tm t;
42  t = t.plusInfinity();
43  m_stringFields["seq_start"] = t.str();
44  m_stringFields["seq_stop"] = t.str();
45  m_intFields["vmin"] = 1;
46  m_intFields["vmax"] = 0;
47 }
48 
50 
52  Tm t;
53  t.setToString(getString("seq_stop"));
54  return t;
55 }
56 
58 
60  if (iov != m_runIOV) {
61  m_ID = 0;
62  m_runIOV = iov;
63  }
64  return *this;
65 }
66 
68  int runIOVID = m_runIOV.getID();
69  if (!runIOVID) {
70  if (m_debug) {
71  std::cout << m_className << ": RunIOV not set" << endl;
72  }
73  return "";
74  }
75 
76  if (m_debug) {
77  std::cout << "Run IOV ID: " << runIOVID << std::endl;
78  std::cout << "SEQ # : " << getSequenceNumber() << std::endl;
79  std::cout << "Versions : " << getVmin() << " - " << getVmax() << endl;
80  }
81  std::string sql =
82  "SELECT SEQ_ID FROM CMS_ECAL_LASER_COND.LMF_SEQ_DAT "
83  "WHERE "
84  "RUN_IOV_ID = :1 AND "
85  "SEQ_NUM = :2 AND "
86  "VMIN = :3 ";
87  if (getVmax() > 0) {
88  sql += "AND VMAX = :4";
89  } else {
90  sql += "ORDER BY VMAX DESC";
91  }
92  stmt->setSQL(sql);
93  stmt->setInt(1, runIOVID);
94  stmt->setInt(2, getSequenceNumber());
95  stmt->setInt(3, getVmin());
96  if (getVmax() > 0) {
97  stmt->setInt(4, getVmax());
98  }
99  return sql;
100 }
101 
103  std::string sql =
104  "SELECT RUN_IOV_ID, SEQ_NUM, SEQ_START, SEQ_STOP, "
105  "VMIN, VMAX FROM CMS_ECAL_LASER_COND.LMF_SEQ_DAT WHERE SEQ_ID = :1";
106  stmt->setSQL(sql);
107  stmt->setInt(1, id);
108  return sql;
109 }
110 
113  int runIOVID = rset->getInt(1);
114  setInt("seq_num", rset->getInt(2));
115  Date startDate = rset->getDate(3);
116  Date endDate = rset->getDate(4);
117  setInt("vmin", rset->getInt(5));
118  setInt("vmax", rset->getInt(6));
119 
120  setString("seq_start", dh.dateToTm(startDate).str());
121  setString("seq_stop", dh.dateToTm(endDate).str());
122 
124  m_runIOV.setByID(runIOVID);
125 }
126 
127 bool LMFSeqDat::isValid() const {
128  bool ret = true;
129  if (getSequenceStart().isNull()) {
130  ret = false;
131  }
132  if ((getSequenceStop().str().length() > 0) && (getSequenceStop().microsTime() < getSequenceStart().microsTime())) {
133  ret = false;
134  }
135  if (getSequenceStop() == Tm().plusInfinity()) {
136  ret = false;
137  }
138  return ret;
139 }
140 
142  // Validate the data, use infinity-till convention
144 
145  if (!isValid()) {
146  dump();
147  throw(std::runtime_error("LMFSeqDat::writeDB: not valid"));
148  }
149 
150  if (getSequenceStop().str().length() == 0) {
151  setSequenceStop(dh.getPlusInfTm());
152  }
153  int runIOVID = m_runIOV.getID();
154  if (runIOVID == 0) {
155  throw(std::runtime_error("LMFSeqDat::writeDB: RunIOV not set"));
156  }
158  std::string sql =
159  "INSERT INTO LMF_SEQ_DAT (SEQ_ID, RUN_IOV_ID, SEQ_NUM, "
160  "SEQ_START, SEQ_STOP, VMIN, VMAX) "
161  "VALUES (SEQ_ID_" +
162  sp + "_SQ.NextVal, :1, :2, :3, :4, :5, :6)";
163  cout << sql << endl;
164  stmt->setSQL(sql);
165  stmt->setInt(1, runIOVID);
166  stmt->setInt(2, getSequenceNumber());
167  stmt->setDate(3, dh.tmToDate(getSequenceStart()));
168  stmt->setDate(4, dh.tmToDate(getSequenceStop()));
169  stmt->setInt(5, getVmin());
170  stmt->setInt(6, getVmax());
171  return sql;
172 }
173 
175  // get the RunIOV
177  int runIOVID = m_runIOV.getID();
178  m_runIOV.setByID(runIOVID);
179 
180  if (m_runIOV.getID() == 0) {
181  throw(std::runtime_error("LMFSeqDat: Given RunIOV does not exist in DB"));
182  }
183 }
184 
185 std::map<int, LMFSeqDat> LMFSeqDat::fetchByRunIOV(std::string sql, std::string method) noexcept(false) {
186  std::vector<std::string> pars;
187  return fetchByRunIOV(pars, sql, method);
188 }
189 
190 std::map<int, LMFSeqDat> LMFSeqDat::fetchByRunIOV(int par, std::string sql, std::string method) noexcept(false) {
191  std::vector<std::string> pars;
192  std::stringstream ss;
193  ss << "I" << par;
194  pars.push_back(ss.str());
195  return fetchByRunIOV(pars, sql, method);
196 }
197 
198 std::map<int, LMFSeqDat> LMFSeqDat::fetchByRunIOV(const std::vector<std::string> &pars,
199  std::string sql,
200  std::string method) noexcept(false) {
201  std::map<int, LMFSeqDat> l;
202  this->checkConnection();
203  try {
204  Statement *stmt = m_conn->createStatement();
205  stmt->setSQL(sql);
206  for (unsigned int i = 0; i < pars.size(); i++) {
207  if (pars[i][0] == 'I') {
208  stmt->setInt(i + 1, atoi(pars[i].c_str() + 1));
209  } else if (pars[i][0] == 'S') {
210  stmt->setString(i + 1, pars[i].c_str() + 1);
211  } else {
212  throw(std::runtime_error(m_className + "::" + method + ": " + "Invalid type"));
213  }
214  }
215  ResultSet *rset = stmt->executeQuery();
216  while (rset->next() != 0) {
217  int seq_id = rset->getInt(1);
218  LMFSeqDat s;
219  s.setConnection(m_env, m_conn);
220  s.setByID(seq_id);
221  l[s.getSequenceNumber()] = s;
222  }
223  m_conn->terminateStatement(stmt);
224  } catch (SQLException &e) {
225  throw(std::runtime_error(m_className + "::" + method + ": " + e.getMessage()));
226  }
227  return l;
228 }
229 
231  LMFSeqDat ret;
232  std::map<int, LMFSeqDat> m = fetchByRunIOV(
233  "SELECT SEQ_ID FROM CMS_ECAL_LASER_COND.LMF_SEQ_DAT "
234  "WHERE SEQ_ID = "
235  "(SELECT MAX(SEQ_ID) FROM CMS_ECAL_LASER_COND.LMF_SEQ_DAT)",
236  "fetchLast");
237  if (!m.empty()) {
238  ret = m.begin()->second;
239  }
240  return ret;
241 }
242 
244 
245 std::map<int, LMFSeqDat> LMFSeqDat::fetchByRunIOV(RunIOV &iov) {
246  int runIOVID = iov.getID();
247  return fetchByRunIOV(runIOVID,
248  "SELECT SEQ_ID FROM CMS_ECAL_LASER_COND.LMF_SEQ_DAT "
249  "WHERE RUN_IOV_ID = :1",
250  "fetchByRunIOV");
251 }
252 
253 std::map<int, LMFSeqDat> LMFSeqDat::fetchByRunIOV(RunIOV &iov, const LMFColor &col) {
254  int runIOVID = iov.getID();
255  int colorId = col.getID();
256  std::vector<std::string> pars;
257  std::stringstream ss;
258  ss << "I" << runIOVID;
259  pars.push_back(ss.str());
260  ss.str(std::string());
261  ss << "I" << colorId;
262  pars.push_back(ss.str());
263  return fetchByRunIOV(pars,
264  "SELECT S.SEQ_ID FROM CMS_ECAL_LASER_COND.LMF_SEQ_DAT "
265  "S JOIN CMS_ECAL_LASER_COND.LMF_RUN_IOV R"
266  " ON S.SEQ_ID = R.SEQ_ID WHERE RUN_IOV_ID = :1 AND "
267  " COLOR_ID = :2",
268  "fetchByRunIOVAndColor");
269 }
270 
271 std::map<int, LMFSeqDat> LMFSeqDat::fetchByRunNumber(int runno) {
272  return fetchByRunIOV(runno,
273  "SELECT SEQ_ID FROM CMS_ECAL_LASER_COND.LMF_SEQ_DAT D "
274  "JOIN CMS_ECAL_COND.RUN_IOV R ON "
275  "D.RUN_IOV_ID = R.IOV_ID WHERE RUN_NUM = :1",
276  "fetchByRunNumber");
277 }
278 
279 LMFSeqDat LMFSeqDat::fetchByRunNumber(int runno, const Tm &taken_at) { return fetchByRunNumber(runno, taken_at.str()); }
280 
282  std::map<int, LMFSeqDat> l;
283  std::vector<std::string> pars;
284  std::stringstream ss;
285  ss << "I" << runno;
286  pars.push_back(ss.str());
287  ss.str(std::string());
288  ss << "S" << taken_at;
289  pars.push_back(ss.str());
290  std::string q =
291  "SELECT SEQ_ID FROM CMS_ECAL_LASER_COND.LMF_SEQ_DAT D "
292  "JOIN CMS_ECAL_COND.RUN_IOV R ON "
293  "D.RUN_IOV_ID = R.IOV_ID WHERE RUN_NUM = :1 AND "
294  "SEQ_START >= TO_DATE(:2, 'YYYY-MM-DD HH24:MI:SS') "
295  "AND SEQ_STOP <= TO_DATE(:2, 'YYYY-MM-DD HH24:MI:SS')";
296  l = fetchByRunIOV(pars, q, "fetchByRunNumberAt");
297  LMFSeqDat ret;
298  if (l.size() == 1) {
299  std::map<int, LMFSeqDat>::const_iterator x = l.begin();
300  ret = x->second;
301  } else if (l.size() > 1) {
302  std::cout << "WARNING: Your query returned more than one result. " << std::endl;
303  std::cout << " This was not expected. Please check the DB!!!" << std::endl;
304  std::cout << "Your query: " << std::endl << q << std::endl;
305  std::cout << "Your parameters: " << std::endl;
306  for (unsigned int i = 0; i < pars.size(); i++) {
307  std::cout << i << ": " << pars[i] << std::endl;
308  }
309  }
310  return ret;
311 }
Tm::str
std::string str() const
Definition: Tm.cc:66
LMFUnique::setClassName
virtual void setClassName(std::string s)
Definition: LMFUnique.h:97
LMFSeqDat::getVmin
int getVmin() const
Definition: LMFSeqDat.h:51
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:542
RunIOV
Definition: RunIOV.h:13
RunIOV::getID
int getID()
Definition: RunIOV.h:35
mps_fire.i
i
Definition: mps_fire.py:428
LMFSeqDat::fetchIdSql
std::string fetchIdSql(Statement *stmt) override
Definition: LMFSeqDat.cc:67
IUniqueDBObject::m_ID
int m_ID
Definition: IUniqueDBObject.h:18
funct::false
false
Definition: Factorize.h:29
LMFSeqDat::getRunIOV
RunIOV getRunIOV() const
Definition: LMFSeqDat.cc:57
cuy.col
col
Definition: cuy.py:1010
gather_cfg.cout
cout
Definition: gather_cfg.py:144
AlcaSiPixelAliHarvester0T_cff.method
method
Definition: AlcaSiPixelAliHarvester0T_cff.py:41
RunIOV::setByID
void setByID(int id) noexcept(false) override
Definition: RunIOV.cc:106
SiStripCommissioningClient_cfg.conn
conn
Definition: SiStripCommissioningClient_cfg.py:5
LMFColor
Definition: LMFColor.h:12
LMFUnique::m_className
std::string m_className
Definition: LMFUnique.h:99
DDAxes::x
LMFUnique::setInt
LMFUnique & setInt(std::string key, int value)
Definition: LMFUnique.cc:31
LMFUnique::m_debug
char m_debug
Definition: LMFUnique.h:100
LMFSeqDat::writeDBSql
std::string writeDBSql(Statement *stmt) override
Definition: LMFSeqDat.cc:141
LMFSeqDat::fetchParentIDs
void fetchParentIDs() noexcept(false) override
Definition: LMFSeqDat.cc:174
LMFUnique::m_intFields
std::map< std::string, int > m_intFields
Definition: LMFUnique.h:104
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
LMFSeqDat::m_runIOV
RunIOV m_runIOV
Definition: LMFSeqDat.h:74
alignCSCRings.s
s
Definition: alignCSCRings.py:92
LMFUnique::dump
virtual void dump() const
Definition: LMFUnique.cc:104
LMFSeqDat.h
IDBObject::m_conn
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
oracle::occi
Definition: ConnectionManager.h:7
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
str
#define str(s)
Definition: TestProcessor.cc:52
LMFSeqDat::fetchByRunIOV
std::map< int, LMFSeqDat > fetchByRunIOV(RunIOV &iov)
Definition: LMFSeqDat.cc:245
Tm
Definition: Tm.h:13
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
web.browse_db.env
env
Definition: browse_db.py:18
LMFSeqDat::getSequenceStop
Tm getSequenceStop() const
Definition: LMFSeqDat.cc:51
LMFSeqDat::fetchByRunNumber
std::map< int, LMFSeqDat > fetchByRunNumber(int runno)
Definition: LMFSeqDat.cc:271
LMFSeqDat::getSequenceNumber
int getSequenceNumber() const
Definition: LMFSeqDat.h:44
visualization-live-secondInstance_cfg.runno
runno
Definition: visualization-live-secondInstance_cfg.py:73
LMFUnique::getString
std::string getString(std::string fieldname) const
Definition: LMFUnique.cc:178
LMFSeqDat::LMFSeqDat
LMFSeqDat()
Definition: LMFSeqDat.cc:10
submitPVResolutionJobs.q
q
Definition: submitPVResolutionJobs.py:84
LMFSeqDat
Definition: LMFSeqDat.h:14
LMFSeqDat::setByIDSql
std::string setByIDSql(Statement *stmt, int id) override
Definition: LMFSeqDat.cc:102
LMFSeqDat::~LMFSeqDat
~LMFSeqDat() override
Definition: LMFSeqDat.cc:49
LMFSeqDat::setRunIOV
LMFSeqDat & setRunIOV(const RunIOV &iov)
Definition: LMFSeqDat.cc:59
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
LMFSeqDat::getSequenceStart
Tm getSequenceStart() const
Definition: LMFSeqDat.h:45
LMFSeqDat::getParameters
void getParameters(ResultSet *rset) override
Definition: LMFSeqDat.cc:111
std
Definition: JetResolutionObject.h:76
IDBObject::setConnection
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
LMFUnique::Statement
oracle::occi::Statement Statement
Definition: LMFUnique.h:24
LMFSeqDat::fetchLast
LMFSeqDat fetchLast()
Definition: LMFSeqDat.cc:230
LMFUnique::m_stringFields
std::map< std::string, std::string > m_stringFields
Definition: LMFUnique.h:102
LMFSeqDat::fetchLastRun
RunIOV fetchLastRun()
Definition: LMFSeqDat.cc:243
LMFUnique::setString
LMFUnique & setString(std::string key, std::string value)
Definition: LMFUnique.cc:14
DateHandler.h
IDBObject::m_env
oracle::occi::Environment * m_env
Definition: IDBObject.h:33
LMFUnique::sequencePostfix
std::string sequencePostfix(const Tm &t)
Definition: LMFUnique.cc:9
LMFSeqDat::getVmax
int getVmax() const
Definition: LMFSeqDat.h:52
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
LMFUnique
Definition: LMFUnique.h:21
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
DateHandler
Definition: DateHandler.h:7
cuy.dh
dh
Definition: cuy.py:355
LMFSeqDat::isValid
bool isValid() const override
Definition: LMFSeqDat.cc:127
EcalDBConnection
Definition: EcalDBConnection.h:15
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
LMFSeqDat::setSequenceStop
LMFSeqDat & setSequenceStop(const Tm &end)
Definition: LMFSeqDat.h:33
LMFUnique::ResultSet
oracle::occi::ResultSet ResultSet
Definition: LMFUnique.h:23