8 using namespace oracle::occi;
38 oracle::occi::Connection* conn) :
LMFUnique(env, conn) {
86 std::cout <<
"Run IOV ID: " << runIOVID << std::endl;
90 std::string sql =
"SELECT SEQ_ID FROM LMF_SEQ_DAT "
92 "RUN_IOV_ID = :1 AND "
96 sql +=
"AND VMAX = :4";
98 sql +=
"ORDER BY VMAX DESC";
101 stmt->setInt(1, runIOVID);
111 std::string sql =
"SELECT RUN_IOV_ID, SEQ_NUM, SEQ_START, SEQ_STOP, "
112 "VMIN, VMAX FROM LMF_SEQ_DAT WHERE SEQ_ID = :1";
120 int runIOVID = rset->getInt(1);
121 setInt(
"seq_num", rset->getInt(2));
122 Date startDate = rset->getDate(3);
123 Date endDate = rset->getDate(4);
124 setInt(
"vmin", rset->getInt(5));
125 setInt(
"vmax", rset->getInt(6));
156 throw(std::runtime_error(
"LMFSeqDat::writeDB: not valid"));
164 throw(std::runtime_error(
"LMFSeqDat::writeDB: RunIOV not set"));
167 std::string sql =
"INSERT INTO LMF_SEQ_DAT (SEQ_ID, RUN_IOV_ID, SEQ_NUM, "
168 "SEQ_START, SEQ_STOP, VMIN, VMAX) "
169 "VALUES (SEQ_ID_" + sp +
"_SQ.NextVal, :1, :2, :3, :4, :5, :6)";
172 stmt->setInt(1, runIOVID);
182 throw(std::runtime_error)
190 throw(std::runtime_error(
"LMFSeqDat: Given RunIOV does not exist in DB"));
197 throw(std::runtime_error)
199 std::vector<std::string> pars;
200 return fetchByRunIOV(pars, sql, method);
206 throw(std::runtime_error)
208 std::vector<std::string> pars;
209 std::stringstream ss;
211 pars.push_back(ss.str());
212 return fetchByRunIOV(pars, sql, method);
218 throw(std::runtime_error)
220 std::map<int, LMFSeqDat>
l;
221 this->checkConnection();
223 Statement *stmt = m_conn->createStatement();
225 for (
unsigned int i = 0;
i < pars.size();
i++) {
226 if (pars[
i][0] ==
'I') {
227 stmt->setInt(
i + 1, atoi(pars[
i].c_str() + 1));
228 }
else if (pars[
i][0] ==
'S') {
229 stmt->setString(
i + 1, pars[
i].c_str() + 1);
231 throw(std::runtime_error(m_className +
"::" + method +
": " +
236 while (rset->next()) {
237 int seq_id = rset->getInt(1);
243 m_conn->terminateStatement(stmt);
245 throw(std::runtime_error(m_className +
"::" + method +
": " +
253 std::map<int, LMFSeqDat>
m =
254 fetchByRunIOV(
"SELECT SEQ_ID FROM LMF_SEQ_DAT WHERE SEQ_ID = "
255 "(SELECT MAX(SEQ_ID) FROM LMF_SEQ_DAT)",
"fetchLast");
257 ret = m.begin()->second;
267 int runIOVID = iov.
getID();
269 "SELECT SEQ_ID FROM LMF_SEQ_DAT WHERE RUN_IOV_ID = :1",
275 int runIOVID = iov.
getID();
276 int colorId = col.
getID();
277 std::vector<std::string> pars;
278 std::stringstream ss;
279 ss <<
"I" << runIOVID;
280 pars.push_back(ss.str());
281 ss.str(std::string());
282 ss <<
"I" << colorId;
283 pars.push_back(ss.str());
285 "SELECT S.SEQ_ID FROM LMF_SEQ_DAT S JOIN LMF_RUN_IOV R"
286 " ON S.SEQ_ID = R.SEQ_ID WHERE RUN_IOV_ID = :1 AND "
288 "fetchByRunIOVAndColor");
293 "SELECT SEQ_ID FROM LMF_SEQ_DAT D JOIN RUN_IOV R ON "
294 "D.RUN_IOV_ID = R.IOV_ID WHERE RUN_NUM = :1",
303 std::map<int, LMFSeqDat>
l;
304 std::vector<std::string> pars;
305 std::stringstream ss;
307 pars.push_back(ss.str());
308 ss.str(std::string());
309 ss <<
"S" << taken_at;
310 pars.push_back(ss.str());
311 std::string
q =
"SELECT SEQ_ID FROM LMF_SEQ_DAT D JOIN RUN_IOV R ON "
312 "D.RUN_IOV_ID = R.IOV_ID WHERE RUN_NUM = :1 AND "
313 "SEQ_START >= TO_DATE(:2, 'YYYY-MM-DD HH24:MI:SS') "
314 "AND SEQ_STOP <= TO_DATE(:2, 'YYYY-MM-DD HH24:MI:SS')";
318 std::map<int, LMFSeqDat>::const_iterator
x = l.begin();
320 }
else if (l.size() > 1) {
321 std::cout <<
"WARNING: Your query returned more than one result. "
323 std::cout <<
" This was not expected. Please check the DB!!!"
325 std::cout <<
"Your query: " << std::endl << q << std::endl;
326 std::cout <<
"Your parameters: " << std::endl;
327 for (
unsigned int i = 0;
i < pars.size();
i++) {
LMFUnique & setInt(std::string key, int value)
oracle::occi::Environment * m_env
std::map< int, LMFSeqDat > fetchByRunNumber(int runno)
Tm getSequenceStop() const
oracle::occi::Connection * m_conn
LMFSeqDat & setRunIOV(const RunIOV &iov)
std::string fetchIdSql(Statement *stmt)
std::map< int, LMFSeqDat > fetchByRunIOV(RunIOV &iov)
std::string writeDBSql(Statement *stmt)
int getSequenceNumber() const
oracle::occi::ResultSet ResultSet
virtual void setClassName(std::string s)
virtual void dump() const
oracle::occi::SQLException SQLException
std::string sequencePostfix(Tm t)
LMFSeqDat & setSequenceStop(Tm end)
std::map< std::string, std::string > m_stringFields
oracle::occi::Statement Statement
void setToString(const std::string s)
Tm getSequenceStart() const
oracle::occi::Date tmToDate(const Tm &inTm) const
LMFUnique & setString(std::string key, std::string value)
void getParameters(ResultSet *rset)
std::string getString(std::string fieldname) const
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Tm dateToTm(oracle::occi::Date &date) const
std::string setByIDSql(Statement *stmt, int id)
std::map< std::string, int > m_intFields
const double par[8 *NPar][4]