CMS 3D CMS Logo

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