CMS 3D CMS Logo

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