CMS 3D CMS Logo

RunDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
4 
7 
8 using namespace std;
9 using namespace oracle::occi;
10 
12  m_env = nullptr;
13  m_conn = nullptr;
14  m_writeStmt = nullptr;
15  m_numEvents = 0;
16 }
17 
19 
20 void RunDat::prepareWrite() noexcept(false) {
21  this->checkConnection();
22 
23  try {
24  m_writeStmt = m_conn->createStatement();
25  m_writeStmt->setSQL(
26  "INSERT INTO run_dat (iov_id, logic_id, "
27  "num_events) "
28  "VALUES (:iov_id, :logic_id, "
29  ":num_events)");
30  } catch (SQLException& e) {
31  throw(std::runtime_error("RunDat::prepareWrite(): " + e.getMessage()));
32  }
33 }
34 
35 void RunDat::writeDB(const EcalLogicID* ecid, const RunDat* item, RunIOV* iov) noexcept(false) {
36  this->checkConnection();
37  this->checkPrepare();
38 
39  int iovID = iov->fetchID();
40  if (!iovID) {
41  throw(std::runtime_error("RunDat::writeDB: IOV not in DB"));
42  }
43 
44  int logicID = ecid->getLogicID();
45  if (!logicID) {
46  throw(std::runtime_error("RunDat::writeDB: Bad EcalLogicID"));
47  }
48 
49  try {
50  m_writeStmt->setInt(1, iovID);
51  m_writeStmt->setInt(2, logicID);
52  m_writeStmt->setInt(3, item->getNumEvents());
53 
54  m_writeStmt->executeUpdate();
55  } catch (SQLException& e) {
56  throw(std::runtime_error("RunDat::writeDB(): " + e.getMessage()));
57  }
58 }
59 
60 void RunDat::fetchData(map<EcalLogicID, RunDat>* fillMap, RunIOV* iov) noexcept(false) {
61  this->checkConnection();
62  fillMap->clear();
63 
64  iov->setConnection(m_env, m_conn);
65  int iovID = iov->fetchID();
66  if (!iovID) {
67  // throw(std::runtime_error("RunDat::writeDB: IOV not in DB"));
68  return;
69  }
70 
71  try {
72  Statement* stmt = m_conn->createStatement();
73  stmt->setSQL(
74  "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
75  "d.num_events "
76  "FROM channelview cv JOIN run_dat d "
77  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
78  "WHERE d.iov_id = :iov_id");
79  stmt->setInt(1, iovID);
80  ResultSet* rset = stmt->executeQuery();
81 
82  std::pair<EcalLogicID, RunDat> p;
83  RunDat dat;
84  while (rset->next()) {
85  p.first = EcalLogicID(rset->getString(1), // name
86  rset->getInt(2), // logic_id
87  rset->getInt(3), // id1
88  rset->getInt(4), // id2
89  rset->getInt(5), // id3
90  rset->getString(6)); // maps_to
91 
92  dat.setNumEvents(rset->getInt(7));
93 
94  p.second = dat;
95  fillMap->insert(p);
96  }
97  m_conn->terminateStatement(stmt);
98  } catch (SQLException& e) {
99  throw(std::runtime_error("RunDat::fetchData(): " + e.getMessage()));
100  }
101 }
RunDat
Definition: RunDat.h:11
RunIOV
Definition: RunIOV.h:13
funct::false
false
Definition: Factorize.h:34
RunDat::writeDB
void writeDB(const EcalLogicID *ecid, const RunDat *item, RunIOV *iov) noexcept(false)
Definition: RunDat.cc:35
RunIOV.h
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
RunDat.h
RunDat::RunDat
RunDat()
Definition: RunDat.cc:11
RunDat::~RunDat
~RunDat() override
Definition: RunDat.cc:18
oracle::occi
Definition: ConnectionManager.h:7
EcalLogicID
Definition: EcalLogicID.h:7
RunDat::prepareWrite
void prepareWrite() noexcept(false) override
Definition: RunDat.cc:20
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
RunDat::fetchData
void fetchData(std::map< EcalLogicID, RunDat > *fillMap, RunIOV *iov) noexcept(false)
Definition: RunDat.cc:60
std
Definition: JetResolutionObject.h:76
Oracle.h
RunDat::setNumEvents
void setNumEvents(int num)
Definition: RunDat.h:20
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37