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