CMS 3D CMS Logo

MonRunDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
4 
8 
9 using namespace std;
10 using namespace oracle::occi;
11 
13 {
14  m_env = nullptr;
15  m_conn = nullptr;
16  m_writeStmt = nullptr;
17  m_readStmt = nullptr;
18 
19  m_numEvents = 0;
20  m_outcomeDef = MonRunOutcomeDef();
21  m_rootfileName = "";
22  m_taskList = 0;
23  m_taskOutcome = 0;
24 }
25 
26 
27 
29 {
30 }
31 
32 
33 
36 {
37  this->checkConnection();
38 
39  try {
40  m_writeStmt = m_conn->createStatement();
41  m_writeStmt->setSQL("INSERT INTO mon_run_dat (iov_id, logic_id, "
42  "num_events, run_outcome_id, rootfile_name, task_list, task_outcome) "
43  "VALUES (:iov_id, :logic_id, "
44  ":num_events, :run_outcome_id, :rootfile_name, :task_list, :task_outcome) ");
45  } catch (SQLException &e) {
46  throw(std::runtime_error("MonRunDat::prepareWrite(): "+e.getMessage()));
47  }
48 }
49 
50 
51 
52 void MonRunDat::writeDB(const EcalLogicID* ecid, const MonRunDat* item, MonRunIOV* iov)
53  noexcept(false)
54 {
55  this->checkConnection();
56  this->checkPrepare();
57 
58  int iovID = iov->fetchID();
59  if (!iovID) { throw(std::runtime_error("MonRunDat::writeDB: IOV not in DB")); }
60 
61  MonRunOutcomeDef monRunOutcomeDef = item->getMonRunOutcomeDef(); // XXX object copy every row!
62  monRunOutcomeDef.setConnection(m_env, m_conn);
63  int outcomeID = monRunOutcomeDef.fetchID();
64  if (!outcomeID) { throw(std::runtime_error("MonRunDat::writeDB: Outcome Definition not in DB")); }
65 
66  int logicID = ecid->getLogicID();
67  if (!logicID) { throw(std::runtime_error("MonRunDat::writeDB: Bad EcalLogicID")); }
68 
69  try {
70  m_writeStmt->setInt(1, iovID);
71  m_writeStmt->setInt(2, logicID);
72  m_writeStmt->setInt(3, item->getNumEvents());
73  m_writeStmt->setInt(4, outcomeID);
74  m_writeStmt->setString(5, item->getRootfileName());
75  m_writeStmt->setInt(6, item->getTaskList());
76  m_writeStmt->setInt(7, item->getTaskOutcome());
77 
78  m_writeStmt->executeUpdate();
79  } catch (SQLException &e) {
80  throw(std::runtime_error("MonRunDat::writeDB(): "+e.getMessage()));
81  }
82 }
83 
84 
85 
86 void MonRunDat::fetchData(map< EcalLogicID, MonRunDat >* fillMap, MonRunIOV* iov)
87  noexcept(false)
88 {
89  this->checkConnection();
90  fillMap->clear();
91 
92  iov->setConnection(m_env, m_conn);
93  int iovID = iov->fetchID();
94  if (!iovID) {
95  // throw(std::runtime_error("MonRunDat::writeDB: IOV not in DB"));
96  return;
97  }
98 
99  try {
100 
101  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
102  "d.num_events, d.run_outcome_id, d.rootfile_name, d.task_list, d.task_outcome "
103  "FROM channelview cv JOIN mon_run_dat d "
104  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
105  "WHERE d.iov_id = :iov_id");
106  m_readStmt->setInt(1, iovID);
107  ResultSet* rset = m_readStmt->executeQuery();
108 
109  std::pair< EcalLogicID, MonRunDat > p;
110  MonRunDat dat;
111  MonRunOutcomeDef outcomeDef;
112  outcomeDef.setConnection(m_env, m_conn);
113  while(rset->next()) {
114  p.first = EcalLogicID( rset->getString(1), // name
115  rset->getInt(2), // logic_id
116  rset->getInt(3), // id1
117  rset->getInt(4), // id2
118  rset->getInt(5), // id3
119  rset->getString(6)); // maps_to
120 
121  dat.setNumEvents( rset->getInt(7) );
122  outcomeDef.setByID( rset->getInt(8) );
123  dat.setMonRunOutcomeDef( outcomeDef );
124  dat.setRootfileName( rset->getString(9) );
125  dat.setTaskList( rset->getInt(10) );
126  dat.setTaskOutcome( rset->getInt(11) );
127 
128  p.second = dat;
129  fillMap->insert(p);
130  }
131  } catch (SQLException &e) {
132  throw(std::runtime_error("MonRunDat::fetchData(): "+e.getMessage()));
133  }
134 }
void setTaskList(int list)
Definition: MonRunDat.h:30
~MonRunDat() override
Definition: MonRunDat.cc:28
void setNumEvents(int num)
Definition: MonRunDat.h:21
void setMonRunOutcomeDef(const MonRunOutcomeDef &outcomeDef)
Definition: MonRunDat.h:24
#define noexcept
void setByID(int id) noexcept(false) override
void fetchData(std::map< EcalLogicID, MonRunDat > *fillMap, MonRunIOV *iov) noexcept(false)
Definition: MonRunDat.cc:86
void writeDB(const EcalLogicID *ecid, const MonRunDat *item, MonRunIOV *iov) noexcept(false)
Definition: MonRunDat.cc:52
void setRootfileName(std::string name)
Definition: MonRunDat.h:27
int fetchID() noexcept(false) override
void setTaskOutcome(int outcome)
Definition: MonRunDat.h:33
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
void prepareWrite() noexcept(false) override
Definition: MonRunDat.cc:34