CMS 3D CMS Logo

ODTTCFCycle.cc
Go to the documentation of this file.
1 #include <stdexcept>
3 
5 
6 using namespace std;
7 using namespace oracle::occi;
8 
10  m_env = nullptr;
11  m_conn = nullptr;
12  m_writeStmt = nullptr;
13  m_readStmt = nullptr;
14  //
15  m_ID = 0;
16  m_ttcf_config_id = 0;
17 }
18 
20 
21 void ODTTCFCycle::prepareWrite() noexcept(false) {
22  this->checkConnection();
23 
24  try {
25  m_writeStmt = m_conn->createStatement();
26  m_writeStmt->setSQL(
27  "INSERT INTO ECAL_TTCF_Cycle (cycle_id, ttcf_configuration_id ) "
28  "VALUES (:1, :2 )");
29  } catch (SQLException &e) {
30  throw(std::runtime_error("ODTTCFCycle::prepareWrite(): " + e.getMessage()));
31  }
32 }
33 
34 void ODTTCFCycle::writeDB() noexcept(false) {
35  this->checkConnection();
36  this->checkPrepare();
37 
38  try {
39  m_writeStmt->setInt(1, this->getId());
40  m_writeStmt->setInt(2, this->getTTCFConfigurationID());
41 
42  m_writeStmt->executeUpdate();
43 
44  } catch (SQLException &e) {
45  throw(std::runtime_error("ODTTCFCycle::writeDB: " + e.getMessage()));
46  }
47 
48  // Now get the ID
49  if (!this->fetchID()) {
50  throw(std::runtime_error("ODTTCFCycle::writeDB: Failed to write"));
51  }
52 }
53 
54 void ODTTCFCycle::clear() { m_ttcf_config_id = 0; }
55 
56 int ODTTCFCycle::fetchID() noexcept(false) {
57  // Return from memory if available
58  if (m_ID) {
59  return m_ID;
60  }
61 
62  this->checkConnection();
63 
64  try {
65  Statement *stmt = m_conn->createStatement();
66  stmt->setSQL(
67  "SELECT cycle_id, ttcf_configuration_id FROM ecal_ttcf_cycle "
68  "WHERE cycle_id = :1 ");
69  stmt->setInt(1, m_ID);
70  ResultSet *rset = stmt->executeQuery();
71 
72  if (rset->next()) {
73  m_ID = rset->getInt(1);
74  m_ttcf_config_id = rset->getInt(2);
75  } else {
76  m_ID = 0;
77  }
78  m_conn->terminateStatement(stmt);
79  } catch (SQLException &e) {
80  throw(std::runtime_error("ODTTCFCycle::fetchID: " + e.getMessage()));
81  }
82 
83  return m_ID;
84 }
85 
86 void ODTTCFCycle::setByID(int id) noexcept(false) {
87  this->checkConnection();
88 
89  try {
90  Statement *stmt = m_conn->createStatement();
91  stmt->setSQL(
92  "SELECT cycle_id, ttcf_configuration_id FROM ecal_ttcf_cycle "
93  "WHERE cycle_id = :1 ");
94  stmt->setInt(1, id);
95  ResultSet *rset = stmt->executeQuery();
96 
97  if (rset->next()) {
98  m_ID = rset->getInt(1);
99  m_ttcf_config_id = rset->getInt(2);
100  } else {
101  m_ID = 0;
102  }
103  m_conn->terminateStatement(stmt);
104  } catch (SQLException &e) {
105  throw(std::runtime_error("ODTTCFCycle::fetchID: " + e.getMessage()));
106  }
107 }
108 
109 void ODTTCFCycle::fetchData(ODTTCFCycle *result) noexcept(false) {
110  this->checkConnection();
111  result->clear();
112 
113  if (result->getId() == 0) {
114  throw(std::runtime_error("ODTTCFConfig::fetchData(): no Id defined for this ODTTCFConfig "));
115  }
116 
117  try {
118  m_readStmt->setSQL(
119  "SELECT ttcf_configuration_id FROM ecal_ttcf_cycle "
120  "WHERE cycle_id = :1 ");
121 
122  m_readStmt->setInt(1, result->getId());
123  ResultSet *rset = m_readStmt->executeQuery();
124 
125  rset->next();
126 
127  result->setTTCFConfigurationID(rset->getInt(1));
128 
129  } catch (SQLException &e) {
130  throw(std::runtime_error("ODTTCFCycle::fetchData(): " + e.getMessage()));
131  }
132 }
133 
135  try {
136  prepareWrite();
137  writeDB();
138  m_conn->commit();
139  terminateWriteStatement();
140  } catch (std::runtime_error &e) {
141  m_conn->rollback();
142  throw(e);
143  } catch (...) {
144  m_conn->rollback();
145  throw(std::runtime_error("EcalCondDBInterface::insertDataSet: Unknown exception caught"));
146  }
147 }
ODTTCFCycle::writeDB
void writeDB() noexcept(false)
Definition: ODTTCFCycle.cc:34
funct::false
false
Definition: Factorize.h:29
ODTTCFCycle
Definition: ODTTCFCycle.h:9
IODConfig::Statement
oracle::occi::Statement Statement
Definition: IODConfig.h:21
ODTTCFCycle::clear
void clear()
Definition: ODTTCFCycle.cc:54
ODTTCFCycle::ODTTCFCycle
ODTTCFCycle()
Definition: ODTTCFCycle.cc:9
ODTTCFCycle::prepareWrite
void prepareWrite() noexcept(false) override
Definition: ODTTCFCycle.cc:21
IODConfig::SQLException
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
ODTTCFCycle::setByID
void setByID(int id) noexcept(false)
Definition: ODTTCFCycle.cc:86
oracle::occi
Definition: ConnectionManager.h:7
ODTTCFCycle::insertConfig
void insertConfig() noexcept(false)
Definition: ODTTCFCycle.cc:134
ODTTCFCycle::~ODTTCFCycle
~ODTTCFCycle() override
Definition: ODTTCFCycle.cc:19
ODTTCFCycle::fetchData
void fetchData(ODTTCFCycle *result) noexcept(false)
Definition: ODTTCFCycle.cc:109
ODTTCFCycle.h
GlobalTrackerMuonAlignment_cfi.writeDB
writeDB
Definition: GlobalTrackerMuonAlignment_cfi.py:10
std
Definition: JetResolutionObject.h:76
Oracle.h
mps_fire.result
result
Definition: mps_fire.py:311
ODTTCFCycle::fetchID
int fetchID() noexcept(false)
Definition: ODTTCFCycle.cc:56
getId
static unsigned int getId()
Definition: DQMStoreStats.h:129
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37