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