CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RunCommentDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
4 
7 
10 
11 using namespace std;
12 using namespace oracle::occi;
13 
14 
15 
17 {
18  m_env = NULL;
19  m_conn = NULL;
20  m_writeStmt = NULL;
21  m_source = "";
22  m_comment = "";
23  m_time = Tm();
24 }
25 
26 
27 
29 {
30 }
31 
32 
33 
35  throw(std::runtime_error)
36 {
37  this->checkConnection();
38 
39  try {
40  m_writeStmt = m_conn->createStatement();
41  m_writeStmt->setSQL("INSERT INTO run_comment_dat (iov_id, "
42  "source, user_comment) "
43  "VALUES (:iov_id, "
44  ":source, :user_comment)");
45  } catch (SQLException &e) {
46  throw(std::runtime_error("RunCommentDat::prepareWrite(): "+e.getMessage()));
47  }
48 }
49 
50 
51 
52 void RunCommentDat::writeDB(const EcalLogicID* ecid, const RunCommentDat* item, RunIOV* iov)
53  throw(std::runtime_error)
54 {
55  this->checkConnection();
56  this->checkPrepare();
57 
58  int iovID = iov->fetchID();
59  if (!iovID) { throw(std::runtime_error("RunCommentDat::writeDB: IOV not in DB")); }
60 
61  try {
62  m_writeStmt->setInt(1, iovID);
63  m_writeStmt->setString(2, item->getSource());
64  m_writeStmt->setString(3, item->getComment());
65 
66  m_writeStmt->executeUpdate();
67  } catch (SQLException &e) {
68  throw(std::runtime_error("RunCommentDat::writeDB(): "+e.getMessage()));
69  }
70 }
71 
72 
73 
74 void RunCommentDat::fetchData(map< EcalLogicID, RunCommentDat >* fillMap, RunIOV* iov)
75  throw(std::runtime_error)
76 {
77  this->checkConnection();
78  fillMap->clear();
79 
80  DateHandler dh(m_env, m_conn);
81 
82  iov->setConnection(m_env, m_conn);
83  int iovID = iov->fetchID();
84  if (!iovID) {
85  // throw(std::runtime_error("RunCommentDat::writeDB: IOV not in DB"));
86  return;
87  }
88 
89  try {
90  Statement* stmt = m_conn->createStatement();
91  stmt->setSQL("SELECT d.comment_id, "
92  "d.source, d.user_comment, d.db_timestamp "
93  "FROM run_comment_dat d "
94  "WHERE d.iov_id = :iov_id order by d.logic_id ");
95  stmt->setInt(1, iovID);
96  ResultSet* rset = stmt->executeQuery();
97 
98  std::pair< EcalLogicID, RunCommentDat > p;
100  while(rset->next()) {
101  p.first = EcalLogicID( "Comment_order",
102  rset->getInt(1), rset->getInt(1),
103  EcalLogicID::NULLID, EcalLogicID::NULLID, // comment number
104  "Comment_order");
105 
106  dat.setSource( rset->getString(2) );
107  dat.setComment( rset->getString(3) );
108 
109  Date startDate = rset->getDate(4);
110  m_time = dh.dateToTm( startDate );
111 
112  p.second = dat;
113  fillMap->insert(p);
114  }
115  m_conn->terminateStatement(stmt);
116  } catch (SQLException &e) {
117  throw(std::runtime_error("RunCommentDat::fetchData(): "+e.getMessage()));
118  }
119 }
void writeDB(const EcalLogicID *ecid, const RunCommentDat *item, RunIOV *iov)
void setSource(std::string x)
Definition: RunCommentDat.h:20
void fetchData(std::map< EcalLogicID, RunCommentDat > *fillMap, RunIOV *iov)
#define NULL
Definition: scimark2.h:8
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
void prepareWrite()
tuple iov
Definition: o2o.py:307
static std::vector< std::string > checklist dat
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
static const int NULLID
Definition: EcalLogicID.h:42
Definition: RunIOV.h:13
Tm dateToTm(oracle::occi::Date &date) const
Definition: DateHandler.cc:31
void setComment(std::string x)
Definition: RunCommentDat.h:22
Definition: Tm.h:13
tuple dh
Definition: cuy.py:353