CMS 3D CMS Logo

ODRunConfigCycleInfo.cc
Go to the documentation of this file.
1 #include <stdexcept>
3 
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_ID = 0;
18 
19  m_sequence_id = 0;
20  m_cycle_num = 0;
21  m_tag = "";
22  m_description = "";
23 }
24 
26 
28  m_sequence_id = 0;
29  m_cycle_num = 0;
30  m_tag = "";
31  m_description = "";
32 }
33 
35  this->checkConnection();
36 
37  try {
38  m_writeStmt = m_conn->createStatement();
39  m_writeStmt->setSQL(
40  "INSERT INTO ECAL_CYCLE_DAT ( sequence_id , cycle_num, tag, description ) "
41  "VALUES (:1, :2, :3 , :4 )");
42 
43  } catch (SQLException& e) {
44  throw(std::runtime_error("ODRunConfigCycleInfo::prepareWrite(): " + e.getMessage()));
45  }
46 }
47 
49  this->checkConnection();
50  this->checkPrepare();
51 
52  // Validate the data, use infinity-till convention
53  DateHandler dh(m_env, m_conn);
54 
55  try {
56  m_writeStmt->setInt(1, this->getSequenceID());
57  m_writeStmt->setInt(2, this->getCycleNumber());
58  m_writeStmt->setString(3, this->getTag());
59  m_writeStmt->setString(4, this->getDescription());
60  m_writeStmt->executeUpdate();
61 
62  } catch (SQLException& e) {
63  throw(std::runtime_error("ODRunConfigCycleInfo::writeDB: " + e.getMessage()));
64  }
65  // Now get the ID
66  if (!this->fetchID()) {
67  throw(std::runtime_error("ODRunConfigCycleInfo::writeDB: Failed to write"));
68  }
69 
70  cout << "ODRunConfigCycleInfo::writeDB>> done inserting ODRunConfigCycleInfo with id=" << m_ID << endl;
71 }
72 
74  // Return from memory if available
75  if (m_ID > 0) {
76  return m_ID;
77  }
78 
79  this->checkConnection();
80 
81  DateHandler dh(m_env, m_conn);
82 
83  try {
84  Statement* stmt = m_conn->createStatement();
85  stmt->setSQL(
86  "SELECT cycle_id from ECAL_cycle_DAT "
87  "WHERE sequence_id = :id1 "
88  " and cycle_num = :id2 ");
89  stmt->setInt(1, m_sequence_id);
90  stmt->setInt(2, m_cycle_num);
91 
92  ResultSet* rset = stmt->executeQuery();
93 
94  if (rset->next()) {
95  m_ID = rset->getInt(1);
96  } else {
97  m_ID = 0;
98  }
99  m_conn->terminateStatement(stmt);
100  } catch (SQLException& e) {
101  throw(std::runtime_error("ODRunConfigCycleInfo::fetchID: " + e.getMessage()));
102  }
103  setByID(m_ID);
104 
105  return m_ID;
106 }
107 
109  this->checkConnection();
110 
111  DateHandler dh(m_env, m_conn);
112 
113  try {
114  Statement* stmt = m_conn->createStatement();
115  stmt->setSQL("SELECT max(cycle_id) FROM ecal_cycle_dat ");
116  ResultSet* rset = stmt->executeQuery();
117 
118  if (rset->next()) {
119  m_ID = rset->getInt(1);
120  } else {
121  m_ID = 0;
122  }
123  m_conn->terminateStatement(stmt);
124  } catch (SQLException& e) {
125  throw(std::runtime_error("ODRunConfigCycleInfo::fetchIDLast: " + e.getMessage()));
126  }
127 
128  setByID(m_ID);
129  return m_ID;
130 }
131 
132 void ODRunConfigCycleInfo::setByID(int id) noexcept(false) {
133  this->checkConnection();
134 
135  DateHandler dh(m_env, m_conn);
136 
137  cout << "ODRunConfigCycleInfo::setByID called for id " << id << endl;
138 
139  try {
140  Statement* stmt = m_conn->createStatement();
141 
142  stmt->setSQL("SELECT sequence_id , cycle_num , tag , description FROM ECAL_cycle_DAT WHERE cycle_id = :1 ");
143  stmt->setInt(1, id);
144 
145  ResultSet* rset = stmt->executeQuery();
146  if (rset->next()) {
147  m_sequence_id = rset->getInt(1);
148  m_cycle_num = rset->getInt(2);
149  m_tag = rset->getString(3);
150  m_description = rset->getString(4);
151  m_ID = id;
152  } else {
153  throw(std::runtime_error("ODRunConfigCycleInfo::setByID: Given cycle_id is not in the database"));
154  }
155  m_conn->terminateStatement(stmt);
156  } catch (SQLException& e) {
157  throw(std::runtime_error("ODRunConfigCycleInfo::setByID: " + e.getMessage()));
158  }
159 }
160 
162  this->checkConnection();
163  result->clear();
164  if (result->getId() == 0) {
165  throw(std::runtime_error("ODRunConfigCycleInfo::fetchData(): no Id defined for this ODRunConfigCycleInfo "));
166  }
167 
168  try {
169  m_readStmt->setSQL("SELECT sequence_id , cycle_num , tag , description FROM ECAL_cycle_DAT WHERE cycle_id = :1 ");
170 
171  m_readStmt->setInt(1, result->getId());
172  ResultSet* rset = m_readStmt->executeQuery();
173 
174  rset->next();
175 
176  result->setSequenceID(rset->getInt(1));
177  result->setCycleNumber(rset->getInt(2));
178  result->setTag(rset->getString(3));
179  result->setDescription(rset->getString(4));
180 
181  } catch (SQLException& e) {
182  throw(std::runtime_error("ODRunConfigCycleInfo::fetchData(): " + e.getMessage()));
183  }
184 }
185 
187  try {
188  prepareWrite();
189  writeDB();
190  m_conn->commit();
191  terminateWriteStatement();
192  } catch (std::runtime_error& e) {
193  m_conn->rollback();
194  throw(e);
195  } catch (...) {
196  m_conn->rollback();
197  throw(std::runtime_error("EcalCondDBInterface::insertDataSet: Unknown exception caught"));
198  }
199 }
ODRunConfigCycleInfo::insertConfig
void insertConfig() noexcept(false)
Definition: ODRunConfigCycleInfo.cc:186
ODRunConfigCycleInfo
Definition: ODRunConfigCycleInfo.h:12
funct::false
false
Definition: Factorize.h:29
ODRunConfigCycleInfo.h
ODRunConfigCycleInfo::fetchID
int fetchID() noexcept(false)
Definition: ODRunConfigCycleInfo.cc:73
IODConfig::Statement
oracle::occi::Statement Statement
Definition: IODConfig.h:21
gather_cfg.cout
cout
Definition: gather_cfg.py:144
ODRunConfigCycleInfo::writeDB
void writeDB() noexcept(false)
Definition: ODRunConfigCycleInfo.cc:48
IODConfig::SQLException
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
oracle::occi
Definition: ConnectionManager.h:7
ODRunConfigCycleInfo::fetchData
void fetchData(ODRunConfigCycleInfo *result) noexcept(false)
Definition: ODRunConfigCycleInfo.cc:161
ODRunConfigCycleInfo::ODRunConfigCycleInfo
ODRunConfigCycleInfo()
Definition: ODRunConfigCycleInfo.cc:11
ODRunConfigCycleInfo::~ODRunConfigCycleInfo
~ODRunConfigCycleInfo() override
Definition: ODRunConfigCycleInfo.cc:25
Tm.h
GlobalTrackerMuonAlignment_cfi.writeDB
writeDB
Definition: GlobalTrackerMuonAlignment_cfi.py:10
std
Definition: JetResolutionObject.h:76
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
ODRunConfigCycleInfo::clear
void clear()
Definition: ODRunConfigCycleInfo.cc:27
ODRunConfigCycleInfo::fetchIDLast
int fetchIDLast() noexcept(false)
Definition: ODRunConfigCycleInfo.cc:108
Oracle.h
DateHandler.h
mps_fire.result
result
Definition: mps_fire.py:311
ODRunConfigCycleInfo::prepareWrite
void prepareWrite() noexcept(false) override
Definition: ODRunConfigCycleInfo.cc:34
ODRunConfigCycleInfo::setByID
void setByID(int id) noexcept(false)
Definition: ODRunConfigCycleInfo.cc:132
DateHandler
Definition: DateHandler.h:7
cuy.dh
dh
Definition: cuy.py:355
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37