CMS 3D CMS Logo

LMFLmrSubIOV.cc
Go to the documentation of this file.
2 
3 #include <ctime>
4 #include <string>
5 
7  m_className = "LMFLmrSubIOV";
8 
9  m_lmfIOV = 0;
10  m_t[0] = Tm();
11  m_t[1] = Tm();
12  m_t[2] = Tm();
13 }
14 
16 
18 
19 LMFLmrSubIOV::LMFLmrSubIOV(oracle::occi::Environment *env, oracle::occi::Connection *conn) : LMFUnique(env, conn) {
20  init();
21 }
22 
24 
26  if (m_debug) {
27  std::cout << "[LMFLmrSubIOV] Setting IOV_ID as " << iov.getID() << std::endl << std::flush;
28  }
29  m_lmfIOV = iov.getID();
30  return *this;
31 }
32 
34  m_t[0] = t[0];
35  m_t[1] = t[1];
36  m_t[2] = t[2];
37  return *this;
38 }
39 
40 LMFLmrSubIOV &LMFLmrSubIOV::setTimes(const Tm &t1, const Tm &t2, const Tm &t3) {
41  m_t[0] = t1;
42  m_t[1] = t2;
43  m_t[2] = t3;
44  return *this;
45 }
46 
48  if (!m_lmfIOV) {
49  if (m_debug) {
50  std::cout << m_className << ": LMFIOV not set" << std::endl;
51  }
52  return "";
53  }
54 
55  std::string sql =
56  "SELECT LMR_SUB_IOV_ID FROM "
57  "CMS_ECAL_LASER_COND.LMF_LMR_SUB_IOV "
58  "WHERE "
59  "IOV_ID = :1 AND "
60  "T1 = :2 AND "
61  "T2 = :3 AND "
62  "T3 = :4";
63  stmt->setSQL(sql);
64  stmt->setInt(1, m_lmfIOV);
66  for (int i = 0; i < 3; i++) {
67  oracle::occi::Date t = dh.tmToDate(m_t[i]);
68  stmt->setDate(i + 2, t);
69  }
70  return sql;
71 }
72 
74  std::string sql =
75  "SELECT IOV_ID, T1, T2, T3 FROM "
76  "CMS_ECAL_LASER_COND.LMF_LMR_SUB_IOV "
77  "WHERE LMR_SUB_IOV_ID = :1";
78  stmt->setSQL(sql);
79  stmt->setInt(1, id);
80  return sql;
81 }
82 
84  // Validate the data, use infinity-till convention
86 
87  for (int i = 0; i < 3; i++) {
88  if (m_t[i].isNull()) {
89  m_t[i] = dh.getPlusInfTm();
90  }
91  }
92 
93  if (m_lmfIOV == 0) {
94  throw(std::runtime_error(m_className + "::writeDB: LMFIOV not set"));
95  }
97  std::string sql =
98  "INSERT INTO LMF_LMR_SUB_IOV (LMR_SUB_IOV_ID, "
99  "IOV_ID, T1, T2, T3) "
100  "VALUES (LMF_LMR_SUB_IOV_ID_" +
101  sp + "_SQ.NextVal, :1, :2, :3, :4)";
102  stmt->setSQL(sql);
103  stmt->setInt(1, m_lmfIOV);
104  for (int i = 0; i < 3; i++) {
105  stmt->setDate(i + 2, dh.tmToDate(m_t[i]));
106  }
107  return sql;
108 }
109 
110 void LMFLmrSubIOV::getParameters(ResultSet *rset) noexcept(false) {
111  m_lmfIOV = rset->getInt(1);
112  for (int i = 0; i < 3; i++) {
113  oracle::occi::Date t = rset->getDate(i + 2);
114 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
115  m_t[i].setToString(t.toText("YYYY-MM-DD HH24:MI:SS"));
116 #else
117  int year = 0;
118  unsigned int month = 0;
119  unsigned int day = 0;
120  unsigned int hour = 0;
121  unsigned int min = 0;
122  unsigned int seconds = 0;
123  t.getDate(year, month, day, hour, min, seconds);
124  const std::tm tt = {.tm_sec = static_cast<int>(seconds),
125  .tm_min = static_cast<int>(min),
126  .tm_hour = static_cast<int>(hour),
127  .tm_mday = static_cast<int>(day),
128  .tm_mon = static_cast<int>(month),
129  .tm_year = year - 1900,
130  .tm_wday = 0,
131  .tm_yday = 0,
132  .tm_isdst = 0,
133  .tm_gmtoff = 0,
134  .tm_zone = nullptr};
135  char tt_str[30] = {0};
136  if (std::strftime(tt_str, sizeof(tt_str), "%F %T", &tt)) {
137  m_t[i].setToString(std::string(tt_str));
138  } else {
139  throw std::runtime_error("LMFLmrSubIOV::writeDBSql: failed to generate the date string");
140  }
141 #endif
142  }
143 }
144 
145 std::list<int> LMFLmrSubIOV::getIOVIDsLaterThan(const Tm &t) noexcept(false) {
146  Tm tinf;
147  tinf.setToString("9999-12-31 23:59:59");
148  return getIOVIDsLaterThan(t, tinf, 0);
149 }
150 
151 std::list<int> LMFLmrSubIOV::getIOVIDsLaterThan(const Tm &t, int howmany) noexcept(false) {
152  Tm tinf;
153  tinf.setToString("9999-12-31 23:59:59");
154  return getIOVIDsLaterThan(t, tinf, howmany);
155 }
156 
157 std::list<int> LMFLmrSubIOV::getIOVIDsLaterThan(const Tm &tmin, const Tm &tmax) noexcept(false) {
158  return getIOVIDsLaterThan(tmin, tmax, 0);
159 }
160 
161 std::list<int> LMFLmrSubIOV::getIOVIDsLaterThan(const Tm &tmin, const Tm &tmax, int howMany) noexcept(false) {
162  Tm tinf;
163  tinf.setToString("9999-12-31 23:59:59");
164  std::string sql =
165  "SELECT * FROM (SELECT LMR_SUB_IOV_ID "
166  "FROM CMS_ECAL_LASER_COND.LMF_LMR_SUB_IOV WHERE T3 > :1 ";
167  if (tmax != tinf) {
168  sql += "AND T3 < :2 ORDER BY T3 ASC) ";
169  if (howMany > 0) {
170  sql += "WHERE ROWNUM <= :3";
171  }
172  } else {
173  sql += "ORDER BY T3 ASC) ";
174  if (howMany > 0) {
175  sql += "WHERE ROWNUM <= :2";
176  }
177  }
178  if (m_debug) {
179  std::cout << "Executing query: " << std::endl << sql << std::endl;
180  }
181  std::list<int> ret;
182  if (m_conn != nullptr) {
183  try {
184  DateHandler dh(m_env, m_conn);
185  Statement *stmt = m_conn->createStatement();
186  stmt->setPrefetchRowCount(10000);
187  stmt->setSQL(sql);
188  stmt->setDate(1, dh.tmToDate(tmin));
189  if (tmax != tinf) {
190  stmt->setDate(2, dh.tmToDate(tmax));
191  if (howMany > 0) {
192  stmt->setInt(3, howMany);
193  }
194  } else {
195  if (howMany > 0) {
196  stmt->setInt(2, howMany);
197  }
198  }
199  ResultSet *rset = stmt->executeQuery();
200  int row = 1;
201  while (rset->next() != 0) {
202  if (m_debug) {
203  std::cout << "Getting row " << row++ << std::endl;
204  }
205  ret.push_back(rset->getInt(1));
206  }
207  stmt->setPrefetchRowCount(0);
208  m_conn->terminateStatement(stmt);
209  } catch (oracle::occi::SQLException &e) {
210 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
211  throw(std::runtime_error(m_className + "::getLmrSubIOVLaterThan: " + e.getMessage()));
212 #else
213  throw(
214  std::runtime_error(m_className + "::getLmrSubIOVLaterThan: error code " + std::to_string(e.getErrorCode())));
215 #endif
216  }
217  } else {
218  throw(std::runtime_error(m_className + "::getLmrSubIOVLaterThan: " + "Connection not set"));
219  }
220  if (m_debug) {
221  std::cout << "Sorting..." << std::flush;
222  }
223  ret.sort();
224  if (m_debug) {
225  std::cout << "Done!" << std::endl << std::flush;
226  }
227  return ret;
228 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:543
RandomServiceHelper.t2
t2
Definition: RandomServiceHelper.py:257
mps_fire.i
i
Definition: mps_fire.py:428
LMFLmrSubIOV::LMFLmrSubIOV
LMFLmrSubIOV()
Definition: LMFLmrSubIOV.cc:15
groupFilesInBlocks.tt
int tt
Definition: groupFilesInBlocks.py:144
LMFLmrSubIOV::fetchIdSql
std::string fetchIdSql(Statement *stmt) override
Definition: LMFLmrSubIOV.cc:47
muonTiming_cfi.tmin
tmin
Definition: muonTiming_cfi.py:24
min
T min(T a, T b)
Definition: MathUtil.h:58
LMFLmrSubIOV::setByIDSql
std::string setByIDSql(Statement *stmt, int id) override
Definition: LMFLmrSubIOV.cc:73
gather_cfg.cout
cout
Definition: gather_cfg.py:144
SiStripCommissioningClient_cfg.conn
conn
Definition: SiStripCommissioningClient_cfg.py:5
LMFLmrSubIOV.h
LMFUnique::m_className
std::string m_className
Definition: LMFUnique.h:99
tmax
static const double tmax[3]
Definition: CastorTimeSlew.cc:7
LMFUnique::m_debug
char m_debug
Definition: LMFUnique.h:100
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
IDBObject::m_conn
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
LMFIOV
Definition: LMFIOV.h:17
LMFLmrSubIOV
Definition: LMFLmrSubIOV.h:13
LMFLmrSubIOV::m_t
Tm m_t[3]
Definition: LMFLmrSubIOV.h:78
seconds
double seconds()
RandomServiceHelper.t3
t3
Definition: RandomServiceHelper.py:258
Tm
Definition: Tm.h:13
web.browse_db.env
env
Definition: browse_db.py:18
LMFLmrSubIOV::setTimes
LMFLmrSubIOV & setTimes(const Tm &t1, const Tm &t2, const Tm &t3)
Definition: LMFLmrSubIOV.cc:40
LMFLmrSubIOV::m_lmfIOV
int m_lmfIOV
Definition: LMFLmrSubIOV.h:77
LMFLmrSubIOV::writeDBSql
std::string writeDBSql(Statement *stmt) override
Definition: LMFLmrSubIOV.cc:83
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
util.getRunInfo.day
def day(string)
Definition: getRunInfo.py:11
LMFLmrSubIOV::getIOVIDsLaterThan
std::list< int > getIOVIDsLaterThan(const Tm &t) noexcept(false)
Definition: LMFLmrSubIOV.cc:145
LMFUnique::getID
int getID() const
Definition: LMFUnique.h:58
LMFLmrSubIOV::getParameters
void getParameters(ResultSet *rset) override
Definition: LMFLmrSubIOV.cc:110
Tm::setToString
void setToString(const std::string s) noexcept(false)
Definition: Tm.cc:150
LMFLmrSubIOV::setLMFIOV
LMFLmrSubIOV & setLMFIOV(const LMFIOV &iov)
Definition: LMFLmrSubIOV.cc:25
LMFUnique::Statement
oracle::occi::Statement Statement
Definition: LMFUnique.h:24
LMFLmrSubIOV::~LMFLmrSubIOV
~LMFLmrSubIOV() override
Definition: LMFLmrSubIOV.cc:23
LMFLmrSubIOV::init
void init()
Definition: LMFLmrSubIOV.cc:6
IDBObject::m_env
oracle::occi::Environment * m_env
Definition: IDBObject.h:33
LMFUnique::sequencePostfix
std::string sequencePostfix(const Tm &t)
Definition: LMFUnique.cc:9
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
LMFUnique
Definition: LMFUnique.h:21
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
DateHandler
Definition: DateHandler.h:7
cuy.dh
dh
Definition: cuy.py:354
EcalDBConnection
Definition: EcalDBConnection.h:15
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
LMFUnique::ResultSet
oracle::occi::ResultSet ResultSet
Definition: LMFUnique.h:23