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 6 of file CSCOnlineDB.cc.

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

References con, gather_cfg::cout, env, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ ~condbon()

condbon::~condbon ( )
noexcept

Destructor for condbon

Destructor for condbon.

Definition at line 20 of file CSCOnlineDB.cc.

20  {
21  env->terminateConnection(con);
22  oracle::occi::Environment::terminateEnvironment(env);
23 } // end of ~condbon ()

References con, and env.

Member Function Documentation

◆ cdbon_last_record()

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

Definition at line 246 of file CSCOnlineDB.cc.

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

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

◆ cdbon_read_rec()

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

Definition at line 266 of file CSCOnlineDB.cc.

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

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

◆ cdbon_write()

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

Definition at line 25 of file CSCOnlineDB.cc.

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

References c, alignmentValidation::c1, con, gather_cfg::cout, env, beamvalidation::exit(), dqmMemoryStats::float, mps_fire::i, createfilelist::int, dqmiolumiharvest::j, dqmdumpme::k, min(), LaserDQM_cfi::mon, submitPVValidationJobs::now, getGTfromDQMFile::obj, GlobalPosition_Frontier_DevDB_cff::record, fileinputsource_cfi::sec, contentValuesCheck::ss, stmt, stmt1, AlCaHLTBitMon_QueryRunRegistry::string, and protons_cff::time.

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().

mps_fire.i
i
Definition: mps_fire.py:428
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
submitPVValidationJobs.now
now
Definition: submitPVValidationJobs.py:639
min
T min(T a, T b)
Definition: MathUtil.h:58
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
protons_cff.time
time
Definition: protons_cff.py:39
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
dqmdumpme.k
k
Definition: dqmdumpme.py:60
condbon::env
oracle::occi::Environment * env
Definition: CSCOnlineDB.h:19
LaserDQM_cfi.mon
mon
Definition: LaserDQM_cfi.py:3
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
createfilelist.int
int
Definition: createfilelist.py:10
alignmentValidation.c1
c1
do drawing
Definition: alignmentValidation.py:1025
fileinputsource_cfi.sec
sec
Definition: fileinputsource_cfi.py:87
condbon::stmt1
oracle::occi::Statement * stmt1
Definition: CSCOnlineDB.h:21
condbon::stmt
oracle::occi::Statement * stmt
Definition: CSCOnlineDB.h:21
ztail.d
d
Definition: ztail.py:151
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
condbon::con
oracle::occi::Connection * con
Definition: CSCOnlineDB.h:20