CMS 3D CMS Logo

FEConfigMainInfo.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  m_version = 0;
19  clear();
20 }
21 
23 
25  m_description = "";
26  m_ped_id = 0;
27  m_lin_id = 0;
28  m_lut_id = 0;
29  m_sli_id = 0;
30  m_fgr_id = 0;
31  m_wei_id = 0;
32  m_bxt_id = 0;
33  m_btt_id = 0;
34  m_tim_id = 0;
35  m_spi_id = 0;
36  m_bst_id = 0;
37 
38  m_db_time = Tm();
39 }
41  int result = 0;
42  try {
43  this->checkConnection();
44 
45  m_readStmt = m_conn->createStatement();
46  m_readStmt->setSQL("select fe_config_main_sq.NextVal from dual");
47  ResultSet* rset = m_readStmt->executeQuery();
48  while (rset->next()) {
49  result = rset->getInt(1);
50  }
51  m_conn->terminateStatement(m_readStmt);
52  return result;
53 
54  } catch (SQLException& e) {
55  throw(std::runtime_error("FEConfigMainInfo::fetchNextId(): " + e.getMessage()));
56  }
57 }
58 
60  // Return from memory if available
61  if (m_ID > 0) {
62  return m_ID;
63  }
64 
65  this->checkConnection();
66 
67  DateHandler dh(m_env, m_conn);
68 
69  std::cout << " tag/version " << getConfigTag() << "/" << getVersion() << std::endl;
70 
71  try {
72  Statement* stmt = m_conn->createStatement();
73  if (m_version != 0) {
74  stmt->setSQL(
75  "SELECT conf_id from FE_CONFIG_MAIN "
76  "WHERE tag = :tag "
77  " and version = :version ");
78  stmt->setString(1, m_config_tag);
79  stmt->setInt(2, m_version);
80  std::cout << " using query with version " << endl;
81  } else {
82  // always select the last inserted one with a given tag
83  stmt->setSQL(
84  "SELECT conf_id from FE_CONFIG_MAIN "
85  "WHERE tag = :1 and version= (select max(version) from FE_CONFIG_MAIN where tag=:2) ");
86  stmt->setString(1, m_config_tag);
87  stmt->setString(2, m_config_tag);
88  std::cout << " using query WITHOUT version " << endl;
89  }
90 
91  ResultSet* rset = stmt->executeQuery();
92 
93  if (rset->next()) {
94  m_ID = rset->getInt(1);
95  } else {
96  m_ID = 0;
97  }
98  std::cout << m_ID << endl;
99  m_conn->terminateStatement(stmt);
100  } catch (SQLException& e) {
101  throw(std::runtime_error("FEConfigMainInfo::fetchID: " + e.getMessage()));
102  }
103  setByID(m_ID);
104  return m_ID;
105 }
106 
108  this->checkConnection();
109 
110  int next_id = fetchNextId();
111 
112  try {
113  m_writeStmt = m_conn->createStatement();
114  m_writeStmt->setSQL(
115  "INSERT INTO fe_config_main (conf_id, ped_conf_id, lin_conf_id, lut_conf_id, fgr_conf_id, sli_conf_id, "
116  "wei_conf_id, spi_conf_id, tim_conf_id, bxt_conf_id, btt_conf_id, bst_conf_id, tag, version, description) "
117  " VALUES (:1, :2, :3 , :4, :5, :6 ,:7, :8, :9, :10, :11, :12, :13, :14, :15 )");
118 
119  m_writeStmt->setInt(1, next_id);
120  m_ID = next_id;
121 
122  } catch (SQLException& e) {
123  throw(std::runtime_error("FEConfigMainInfo::prepareWrite(): " + e.getMessage()));
124  }
125 }
126 
128  this->checkConnection();
129  this->checkPrepare();
130 
131  // Validate the data, use infinity-till convention
132  DateHandler dh(m_env, m_conn);
133 
134  try {
135  m_writeStmt->setInt(2, this->getPedId());
136  m_writeStmt->setInt(3, this->getLinId());
137  m_writeStmt->setInt(4, this->getLUTId());
138  m_writeStmt->setInt(5, this->getFgrId());
139  m_writeStmt->setInt(6, this->getSliId());
140  m_writeStmt->setInt(7, this->getWeiId());
141  m_writeStmt->setInt(8, this->getSpiId());
142  m_writeStmt->setInt(9, this->getTimId());
143  m_writeStmt->setInt(10, this->getBxtId());
144  m_writeStmt->setInt(11, this->getBttId());
145  m_writeStmt->setInt(12, this->getBstId());
146  m_writeStmt->setString(13, this->getConfigTag());
147  m_writeStmt->setInt(14, this->getVersion());
148  m_writeStmt->setString(15, this->getDescription());
149  m_writeStmt->executeUpdate();
150 
151  } catch (SQLException& e) {
152  throw(std::runtime_error("FEConfigMainInfo::writeDB: " + e.getMessage()));
153  }
154  // Now get the ID
155  if (!this->fetchID()) {
156  throw(std::runtime_error("FEConfigMainInfo::writeDB: Failed to write"));
157  }
158  setByID(m_ID);
159 
160  cout << "FEConfigMainInfo::writeDB>> done inserting FEConfigMainInfo with id=" << m_ID << endl;
161 }
162 
164  this->checkConnection();
165 
166  DateHandler dh(m_env, m_conn);
167 
168  try {
169  Statement* stmt = m_conn->createStatement();
170  stmt->setSQL("SELECT max(conf_id) FROM fe_config_main ");
171  ResultSet* rset = stmt->executeQuery();
172 
173  if (rset->next()) {
174  m_ID = rset->getInt(1);
175  } else {
176  m_ID = 0;
177  }
178  m_conn->terminateStatement(stmt);
179  } catch (SQLException& e) {
180  throw(std::runtime_error("ODRunConfigInfo::fetchIDLast: " + e.getMessage()));
181  }
182 
183  setByID(m_ID);
184  return m_ID;
185 }
186 
187 void FEConfigMainInfo::setByID(int id) noexcept(false) {
188  this->checkConnection();
189 
190  DateHandler dh(m_env, m_conn);
191 
192  cout << "FEConfigMainInfo::setByID called for id " << id << endl;
193 
194  try {
195  Statement* stmt = m_conn->createStatement();
196 
197  stmt->setSQL("SELECT * FROM FE_CONFIG_MAIN WHERE conf_id = :1 ");
198  stmt->setInt(1, id);
199 
200  ResultSet* rset = stmt->executeQuery();
201  if (rset->next()) {
202  setId(rset->getInt(1));
203  setPedId(rset->getInt(2));
204  setLinId(rset->getInt(3));
205  setLUTId(rset->getInt(4));
206  setFgrId(rset->getInt(5));
207  setSliId(rset->getInt(6));
208  setWeiId(rset->getInt(7));
209  setSpiId(rset->getInt(8));
210  setTimId(rset->getInt(9));
211  setBxtId(rset->getInt(10));
212  setBttId(rset->getInt(11));
213  setBstId(rset->getInt(12));
214  setConfigTag(rset->getString(13));
215  setVersion(rset->getInt(14));
216  setDescription(rset->getString(15));
217  Date dbdate = rset->getDate(16);
218  setDBTime(dh.dateToTm(dbdate));
219  m_ID = id;
220  } else {
221  throw(std::runtime_error("FEConfigMainInfo::setByID: Given cycle_id is not in the database"));
222  }
223  m_conn->terminateStatement(stmt);
224  } catch (SQLException& e) {
225  throw(std::runtime_error("FEConfigMainInfo::setByID: " + e.getMessage()));
226  }
227 }
228 
230  std::cout << " ### 1 getId from FEConfigMainInfo = " << result->getId() << std::endl;
231  std::cout << " tag/version " << result->getConfigTag() << "/" << result->getVersion() << std::endl;
232 
233  this->checkConnection();
234  DateHandler dh(m_env, m_conn);
235  // result->clear();
236 
237  int idid = 0;
238 
239  if (result->getId() == 0) {
240  //throw(std::runtime_error("FEConfigMainInfo::fetchData(): no Id defined for this FEConfigMainInfo "));
241  idid = result->fetchID();
242  result->setId(idid);
243  }
244 
245  try {
246  m_readStmt->setSQL("SELECT * FROM FE_CONFIG_MAIN WHERE conf_id = :1 ");
247 
248  std::cout << " ### 2 getId from FEConfigMainInfo = " << result->getId() << std::endl;
249 
250  // good m_readStmt->setInt(1, result->getId());
251  m_readStmt->setInt(1, result->getId());
252  ResultSet* rset = m_readStmt->executeQuery();
253 
254  rset->next();
255 
256  result->setId(rset->getInt(1));
257 
258  setPedId(rset->getInt(2));
259  setLinId(rset->getInt(3));
260  setLUTId(rset->getInt(4));
261  setFgrId(rset->getInt(5));
262  setSliId(rset->getInt(6));
263  setWeiId(rset->getInt(7));
264  setSpiId(rset->getInt(8));
265  setTimId(rset->getInt(9));
266  setBxtId(rset->getInt(10));
267  setBttId(rset->getInt(11));
268  setBstId(rset->getInt(12));
269 
270  result->setConfigTag(rset->getString(13));
271  result->setVersion(rset->getInt(14));
272  result->setDescription(rset->getString(15));
273  Date dbdate = rset->getDate(16);
274  result->setDBTime(dh.dateToTm(dbdate));
275 
276  } catch (SQLException& e) {
277  throw(std::runtime_error("FEConfigMainInfo::fetchData(): " + e.getMessage()));
278  }
279 }
280 
282  try {
283  prepareWrite();
284  writeDB();
285  m_conn->commit();
286  terminateWriteStatement();
287  } catch (std::runtime_error& e) {
288  m_conn->rollback();
289  throw(e);
290  } catch (...) {
291  m_conn->rollback();
292  throw(std::runtime_error("FEConfigMainInfo::insertConfig: Unknown exception caught"));
293  }
294 }
funct::false
false
Definition: Factorize.h:34
FEConfigMainInfo::FEConfigMainInfo
FEConfigMainInfo()
Definition: FEConfigMainInfo.cc:11
FEConfigMainInfo::writeDB
void writeDB() noexcept(false)
Definition: FEConfigMainInfo.cc:127
IODConfig::Statement
oracle::occi::Statement Statement
Definition: IODConfig.h:21
gather_cfg.cout
cout
Definition: gather_cfg.py:144
FEConfigMainInfo
Definition: FEConfigMainInfo.h:14
FEConfigMainInfo::fetchID
int fetchID() noexcept(false)
Definition: FEConfigMainInfo.cc:59
IODConfig::SQLException
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
FEConfigMainInfo::~FEConfigMainInfo
~FEConfigMainInfo() override
Definition: FEConfigMainInfo.cc:22
FEConfigMainInfo.h
FEConfigMainInfo::prepareWrite
void prepareWrite() noexcept(false) override
Definition: FEConfigMainInfo.cc:107
oracle::occi
Definition: ConnectionManager.h:7
FEConfigMainInfo::fetchNextId
int fetchNextId() noexcept(false)
Definition: FEConfigMainInfo.cc:40
Tm
Definition: Tm.h:13
clear
void clear(HadCaloObj &c)
Definition: data.h:124
Tm.h
GlobalTrackerMuonAlignment_cfi.writeDB
writeDB
Definition: GlobalTrackerMuonAlignment_cfi.py:10
FEConfigMainInfo::fetchData
void fetchData(FEConfigMainInfo *result) noexcept(false)
Definition: FEConfigMainInfo.cc:229
FEConfigMainInfo::insertConfig
void insertConfig() noexcept(false)
Definition: FEConfigMainInfo.cc:281
FEConfigMainInfo::setByID
void setByID(int id) noexcept(false)
Definition: FEConfigMainInfo.cc:187
std
Definition: JetResolutionObject.h:76
FEConfigMainInfo::clear
void clear()
Definition: FEConfigMainInfo.cc:24
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
Oracle.h
DateHandler.h
mps_fire.result
result
Definition: mps_fire.py:303
FEConfigMainInfo::fetchIDLast
int fetchIDLast() noexcept(false)
Definition: FEConfigMainInfo.cc:163
DateHandler
Definition: DateHandler.h:7
cuy.dh
dh
Definition: cuy.py:355
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37