CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
condbon Class Reference

#include <CSCOnlineDB.h>

Public Member Functions

void cdbon_last_record (std::string obj_name, int *record)
 
void cdbon_read_rec (std::string obj_name, int record, CSCobject *obj)
 
void cdbon_write (CSCobject *obj, std::string obj_name, int record, int global_run, std::string time)
 
 condbon () noexcept(false)
 
 ~condbon () noexcept(false)
 

Private Attributes

oracle::occi::Connection * con
 
oracle::occi::Environment * env
 
oracle::occi::Statement * stmt
 
oracle::occi::Statement * stmt1
 

Detailed Description

Definition at line 17 of file CSCOnlineDB.h.

Constructor & Destructor Documentation

◆ condbon()

condbon::condbon ( )
noexcept

Constructor for condbon

Definition at line 7 of file CSCOnlineDB.cc.

References cms::cuda::assert(), con, gather_cfg::cout, copyBadStrip_cfg::db_user, env, and AlCaHLTBitMon_QueryRunRegistry::string.

7  {
9  std::string db_pass;
10  env = oracle::occi::Environment::createEnvironment(oracle::occi::Environment::OBJECT);
11  char *c_user = std::getenv("CONDBON_AUTH_USER");
12  char *c_pass = std::getenv("CONDBON_AUTH_PASSWORD");
13  assert(c_user);
14  assert(c_pass);
15  db_user = std::string(c_user);
16  db_pass = std::string(c_pass);
17  con = env->createConnection(db_user, db_pass, "omds");
18  std::cout << "Connection to Online DB is done." << std::endl;
19 } // end of constructor condbon ()
assert(be >=bs)
oracle::occi::Connection * con
Definition: CSCOnlineDB.h:20
oracle::occi::Environment * env
Definition: CSCOnlineDB.h:19

◆ ~condbon()

condbon::~condbon ( )
noexcept

Destructor for condbon

Destructor for condbon.

Definition at line 23 of file CSCOnlineDB.cc.

References con, and env.

23  {
24  env->terminateConnection(con);
25  oracle::occi::Environment::terminateEnvironment(env);
26 } // end of ~condbon ()
oracle::occi::Connection * con
Definition: CSCOnlineDB.h:20
oracle::occi::Environment * env
Definition: CSCOnlineDB.h:19

Member Function Documentation

◆ cdbon_last_record()

void condbon::cdbon_last_record ( std::string  obj_name,
int *  record 
)

Definition at line 249 of file CSCOnlineDB.cc.

References con, Hcal_FrontierConditions_cff::record, stmt, and AlCaHLTBitMon_QueryRunRegistry::string.

249  {
250  std::string sqlStmt;
251  sqlStmt = "SELECT max(record_id) from " + obj_name;
252  stmt = con->createStatement();
253  stmt->setSQL(sqlStmt);
254  oracle::occi::ResultSet *rset;
255  rset = stmt->executeQuery();
256  //try{
257  while (rset->next()) {
258  *record = rset->getInt(1);
259  }
260  // }catch(oracle::occi::SQLException ex)
261  //{
262  // std::cout<<"Exception thrown: "<<std::endl;
263  // std::cout<<"Error number: "<< ex.getErrorCode() << std::endl;
264  // std::cout<<ex.getMessage() << std::endl;
265  //}
266  con->terminateStatement(stmt);
267 } // end of cdbon_last_record
oracle::occi::Statement * stmt
Definition: CSCOnlineDB.h:21
oracle::occi::Connection * con
Definition: CSCOnlineDB.h:20

◆ cdbon_read_rec()

void condbon::cdbon_read_rec ( std::string  obj_name,
int  record,
CSCobject obj 
)

Definition at line 269 of file CSCOnlineDB.cc.

References con, ztail::d, mps_fire::i, getGTfromDQMFile::obj, AlCaHLTBitMon_ParallelJobs::p, Hcal_FrontierConditions_cff::record, contentValuesCheck::ss, stmt, stmt1, and AlCaHLTBitMon_QueryRunRegistry::string.

269  {
270  int i, len;
271  int map_id = 0, layer_id = 0;
272  std::string tab, tab_map, tab_data;
273  tab = obj_name;
274  tab_map = obj_name + "_map";
275  tab_data = obj_name + "_data";
276  int num_var = 0;
277  int vec_index;
278 
279  std::string sqlStmt, sqlStmt1;
280  stmt = con->createStatement();
281  stmt1 = con->createStatement();
282  oracle::occi::ResultSet *rset, *rset1;
283  std::ostringstream ss;
284 
285  char d;
286  const char *p = tab_data.c_str();
287  len = tab_data.length();
288  for (i = 0; i < len; ++i) {
289  d = toupper(*(p + i));
290  ss << d;
291  }
292  sqlStmt = "SELECT count(column_name) from user_tab_columns where table_name='" + ss.str() + "'";
293  ss.str(""); // clear
294  stmt->setSQL(sqlStmt);
295  rset = stmt->executeQuery();
296  // try{
297  while (rset->next()) {
298  num_var = rset->getInt(1) - 2;
299  }
300  // }catch(oracle::occi::SQLException ex)
301  //{
302  // std::cout<<"Exception thrown: "<<std::endl;
303  // std::cout<<"Error number: "<< ex.getErrorCode() << std::endl;
304  // std::cout<<ex.getMessage() << std::endl;
305  //}
306  stmt->closeResultSet(rset);
307 
308  ss << record;
309 
310  sqlStmt = "SELECT map_id,map_index,layer_id from " + tab_map + " where record_id=" + ss.str() + " order by map_index";
311  ss.str(""); // clear
312  stmt->setSQL(sqlStmt);
313  rset = stmt->executeQuery();
314  // try{
315  while (rset->next()) {
316  map_id = rset->getInt(1);
317  rset->getInt(2);
318  layer_id = rset->getInt(3);
319  ss << map_id;
320  sqlStmt1 = "SELECT * from " + tab_data + " where map_id=" + ss.str() + " order by vec_index";
321  ss.str(""); // clear
322  stmt1->setSQL(sqlStmt1);
323  rset1 = stmt1->executeQuery();
324  // try{
325  while (rset1->next()) {
326  vec_index = rset1->getInt(2);
327  obj->obj[layer_id].resize(vec_index);
328  for (i = 0; i < num_var; ++i) {
329  obj->obj[layer_id][vec_index - 1].push_back(rset1->getFloat(3 + i));
330  }
331  }
332  // }catch(oracle::occi::SQLException ex)
333  //{
334  // std::cout<<"Exception thrown: "<<std::endl;
335  // std::cout<<"Error number: "<< ex.getErrorCode() << std::endl;
336  // std::cout<<ex.getMessage() << std::endl;
337  //}
338  }
339  // }catch(oracle::occi::SQLException ex)
340  //{
341  // std::cout<<"Exception thrown: "<<std::endl;
342  // std::cout<<"Error number: "<< ex.getErrorCode() << std::endl;
343  // std::cout<<ex.getMessage() << std::endl;
344  //}
345 } // end of cdbon_read_rec
oracle::occi::Statement * stmt
Definition: CSCOnlineDB.h:21
d
Definition: ztail.py:151
oracle::occi::Connection * con
Definition: CSCOnlineDB.h:20
oracle::occi::Statement * stmt1
Definition: CSCOnlineDB.h:21

◆ cdbon_write()

void condbon::cdbon_write ( CSCobject obj,
std::string  obj_name,
int  record,
int  global_run,
std::string  time 
)

Definition at line 28 of file CSCOnlineDB.cc.

References DummyCfis::c, alignmentValidation::c1, con, gather_cfg::cout, env, beamvalidation::exit(), ALCARECOEcalPhiSym_cff::float, mps_fire::i, createfilelist::int, dqmiolumiharvest::j, isotrackApplyRegressor::k, SiStripPI::min, LaserDQM_cfi::mon, submitPVValidationJobs::now, getGTfromDQMFile::obj, Hcal_FrontierConditions_cff::record, fileinputsource_cfi::sec, contentValuesCheck::ss, stmt, stmt1, AlCaHLTBitMon_QueryRunRegistry::string, hcalRecHitTable_cff::time, and HBHEDarkening_cff::year.

28  {
29  int i, j, k;
30  std::string tab, tab_map, tab_data;
31  std::string sqlStmt, sqlStmt1;
32  int rec_id = 0, map_id = 0, map_index = 0;
33  tm curtime;
34  time_t now;
35 
36  tab = obj_name;
37  tab_map = obj_name + "_map";
38  tab_data = obj_name + "_data";
39  if (obj_name == "test") {
40  tab = "gains";
41  tab_map = "gains_map";
42  tab_data = "gains_data";
43  }
44  stmt = con->createStatement();
45 
46  oracle::occi::ResultSet *rset;
47 
48  sqlStmt = "SELECT max(record_id) from " + tab;
49  stmt->setSQL(sqlStmt);
50  rset = stmt->executeQuery();
51  // try{
52  while (rset->next()) {
53  rec_id = rset->getInt(1);
54  }
55  // }catch(oracle::occi::SQLException ex)
56  // {
57  // std::cout<<"Exception thrown: "<<std::endl;
58  // std::cout<<"Error number: "<< ex.getErrorCode() << std::endl;
59  // std::cout<<ex.getMessage() << std::endl;
60  //}
61  stmt->closeResultSet(rset);
62 
63  if (record > rec_id) {
64  sqlStmt = "INSERT INTO " + tab + " VALUES (:1, :2, :3, :4, :5, null)";
65  stmt->setSQL(sqlStmt);
66  time(&now);
67  curtime = *localtime(&now);
68  try {
69  stmt->setInt(1, record);
70  stmt->setInt(2, global_run);
71  stmt->setInt(5, 0);
72  /* For time as "05/17/2006 16:30:07"
73  std::string st=data_time.substr(0,2);
74  int mon=atoi(st.c_str());
75  st=data_time.substr(3,2);
76  int mday=atoi(st.c_str());
77  st=data_time.substr(6,4);
78  int year=atoi(st.c_str());
79  st=data_time.substr(11,2);
80  int hour=atoi(st.c_str());
81  st=data_time.substr(14,2);
82  int min=atoi(st.c_str());
83  st=data_time.substr(17,2);
84  int sec=atoi(st.c_str());
85 */
86  /* For time of format "Mon May 29 10:28:58 2006" */
87  std::map<std::string, int> month;
88  month["Jan"] = 1;
89  month["Feb"] = 2;
90  month["Mar"] = 3;
91  month["Apr"] = 4;
92  month["May"] = 5;
93  month["Jun"] = 6;
94  month["Jul"] = 7;
95  month["Aug"] = 8;
96  month["Sep"] = 9;
97  month["Oct"] = 10;
98  month["Nov"] = 11;
99  month["Dec"] = 12;
100  std::string st = data_time.substr(4, 3);
101  int mon = month[st];
102  st = data_time.substr(8, 2);
103  int mday = atoi(st.c_str());
104  st = data_time.substr(20, 4);
105  int year = atoi(st.c_str());
106  st = data_time.substr(11, 2);
107  int hour = atoi(st.c_str());
108  st = data_time.substr(14, 2);
109  int min = atoi(st.c_str());
110  st = data_time.substr(17, 2);
111  int sec = atoi(st.c_str());
112  oracle::occi::Date edate(env, year, mon, mday, hour, min, sec);
113  stmt->setDate(3, edate);
114  oracle::occi::Date edate_c(env,
115  curtime.tm_year + 1900,
116  curtime.tm_mon + 1,
117  curtime.tm_mday,
118  curtime.tm_hour,
119  curtime.tm_min,
120  curtime.tm_sec);
121  stmt->setDate(4, edate_c);
122  if (obj_name != "test")
123  stmt->executeUpdate();
124  } catch (oracle::occi::SQLException &ex) {
125  std::cout << "Exception thrown for insertBind" << std::endl;
126  std::cout << "Error number: " << ex.getErrorCode() << std::endl;
127 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
128  std::cout << ex.getMessage() << std::endl;
129 #endif
130  }
131  }
132 
133  sqlStmt = "SELECT max(map_id) from " + tab_map;
134  stmt->setSQL(sqlStmt);
135  rset = stmt->executeQuery();
136  // try{
137  while (rset->next()) {
138  map_id = rset->getInt(1);
139  }
140  // }catch(oracle::occi::SQLException ex)
141  //{
142  // std::cout<<"Exception thrown: "<<std::endl;
143  // std::cout<<"Error number: "<< ex.getErrorCode() << std::endl;
144  // std::cout<<ex.getMessage() << std::endl;
145  //}
146  stmt->closeResultSet(rset);
147 
148  std::ostringstream ss;
149  ss << record;
150 
151  sqlStmt = "SELECT max(map_index) from " + tab_map + " where record_id=" + ss.str();
152  ss.str(""); // clear
153  stmt->setSQL(sqlStmt);
154  rset = stmt->executeQuery();
155  // try{
156  while (rset->next()) {
157  map_index = rset->getInt(1);
158  }
159  // }catch(oracle::occi::SQLException ex)
160  //{
161  // std::cout<<"Exception thrown: "<<std::endl;
162  // std::cout<<"Error number: "<< ex.getErrorCode() << std::endl;
163  // std::cout<<ex.getMessage() << std::endl;
164  //}
165  stmt->closeResultSet(rset);
166 
167  sqlStmt = "INSERT INTO " + tab_map + " VALUES (:1, :2, :3, :4)";
168  stmt->setSQL(sqlStmt);
169 
170  std::map<int, std::vector<std::vector<float> > >::const_iterator itm;
171  itm = obj->obj.begin();
172  int sizeint = itm->second[0].size();
173  sqlStmt1 = "INSERT INTO " + tab_data + " VALUES (:1, :2";
174  for (i = 1; i < sizeint + 1; ++i) {
175  ss << i + 2;
176  sqlStmt1 = sqlStmt1 + ", :" + ss.str();
177  ss.str(""); // clear
178  }
179  sqlStmt1 = sqlStmt1 + ")";
180 
181  sb4 si = sizeof(int);
182  sb4 sf = sizeof(float);
183  ub2 elensi[200];
184  ub2 elensf[200];
185  int c1[200], c2[200];
186  float c[100][200];
187  for (i = 0; i < 200; ++i) {
188  elensi[i] = si;
189  elensf[i] = sf;
190  }
191 
192  stmt1 = con->createStatement();
193  stmt1->setSQL(sqlStmt1);
194 
195  for (itm = obj->obj.begin(); itm != obj->obj.end(); ++itm) {
196  int id_det = itm->first;
197  int sizev = obj->obj[id_det].size();
198 
199  map_id = map_id + 1;
200  map_index = map_index + 1;
201  // try{
202  stmt->setInt(1, map_id);
203  stmt->setInt(2, record);
204  stmt->setInt(3, map_index);
205  stmt->setInt(4, id_det);
206  if (obj_name != "test")
207  stmt->executeUpdate();
208  //}catch(oracle::occi::SQLException ex)
209  //{
210  //std::cout<<"Exception thrown for insertBind"<<std::endl;
211  //std::cout<<"Error number: "<< ex.getErrorCode() << std::endl;
212  //std::cout<<ex.getMessage() << std::endl;
213  //}
214 
215  k = 0;
216  for (i = 0; i < sizev; ++i) {
217  int sizei = obj->obj[id_det][i].size();
218  if (sizei != sizeint) {
219  std::cout << "Inconsistent object - dimention of internal vector is not " << sizeint << std::endl;
220  exit(1);
221  }
222  c1[i] = map_id;
223  k = k + 1;
224  c2[i] = k;
225  for (j = 0; j < sizei; ++j) {
226  c[j][i] = obj->obj[id_det][i][j];
227  }
228  }
229  // try{
230  stmt1->setDataBuffer(1, c1, oracle::occi::OCCIINT, si, &elensi[0]);
231  stmt1->setDataBuffer(2, c2, oracle::occi::OCCIINT, si, &elensi[0]);
232  for (j = 0; j < sizeint; ++j) {
233  stmt1->setDataBuffer(j + 3, c[j], oracle::occi::OCCIFLOAT, sf, &elensf[0]);
234  }
235  if (obj_name != "test")
236  stmt1->executeArrayUpdate(sizev);
237  // }catch(oracle::occi::SQLException ex)
238  // {
239  // std::cout<<"Exception thrown: "<<std::endl;
240  // std::cout<<"Error number: "<< ex.getErrorCode() << std::endl;
241  // std::cout<<ex.getMessage() << std::endl;
242  // }
243  }
244  con->commit();
245  con->terminateStatement(stmt);
246  con->terminateStatement(stmt1);
247 } //end of cdbon_write
oracle::occi::Statement * stmt
Definition: CSCOnlineDB.h:21
oracle::occi::Connection * con
Definition: CSCOnlineDB.h:20
oracle::occi::Environment * env
Definition: CSCOnlineDB.h:19
oracle::occi::Statement * stmt1
Definition: CSCOnlineDB.h:21
def exit(msg="")

Member Data Documentation

◆ con

oracle::occi::Connection* condbon::con
private

Definition at line 20 of file CSCOnlineDB.h.

Referenced by cdbon_last_record(), cdbon_read_rec(), cdbon_write(), condbon(), and ~condbon().

◆ env

oracle::occi::Environment* condbon::env
private

Definition at line 19 of file CSCOnlineDB.h.

Referenced by cdbon_write(), condbon(), and ~condbon().

◆ stmt

oracle::occi::Statement* condbon::stmt
private

Definition at line 21 of file CSCOnlineDB.h.

Referenced by cdbon_last_record(), cdbon_read_rec(), and cdbon_write().

◆ stmt1

oracle::occi::Statement * condbon::stmt1
private

Definition at line 21 of file CSCOnlineDB.h.

Referenced by cdbon_read_rec(), and cdbon_write().