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");
14 con =
env->createConnection(db_user, db_pass,
"omds");
15 std::cout <<
"Connection to Online DB is done." << std::endl;
21 env->terminateConnection(
con);
22 oracle::occi::Environment::terminateEnvironment(
env);
29 int rec_id = 0, map_id = 0, map_index = 0;
34 tab_map = obj_name +
"_map";
35 tab_data = obj_name +
"_data";
36 if (obj_name ==
"test") {
38 tab_map =
"gains_map";
39 tab_data =
"gains_data";
43 oracle::occi::ResultSet *rset;
45 sqlStmt =
"SELECT max(record_id) from " + tab;
46 stmt->setSQL(sqlStmt);
47 rset =
stmt->executeQuery();
49 while (rset->next()) {
50 rec_id = rset->getInt(1);
58 stmt->closeResultSet(rset);
60 if (record > rec_id) {
61 sqlStmt =
"INSERT INTO " + tab +
" VALUES (:1, :2, :3, :4, :5, null)";
62 stmt->setSQL(sqlStmt);
64 curtime = *localtime(&now);
66 stmt->setInt(1, record);
67 stmt->setInt(2, global_run);
84 std::map<std::string, int> month;
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,
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;
130 sqlStmt =
"SELECT max(map_id) from " + tab_map;
131 stmt->setSQL(sqlStmt);
132 rset =
stmt->executeQuery();
134 while (rset->next()) {
135 map_id = rset->getInt(1);
143 stmt->closeResultSet(rset);
145 std::ostringstream
ss;
148 sqlStmt =
"SELECT max(map_index) from " + tab_map +
" where record_id=" + ss.str();
150 stmt->setSQL(sqlStmt);
151 rset =
stmt->executeQuery();
153 while (rset->next()) {
154 map_index = rset->getInt(1);
162 stmt->closeResultSet(rset);
164 sqlStmt =
"INSERT INTO " + tab_map +
" VALUES (:1, :2, :3, :4)";
165 stmt->setSQL(sqlStmt);
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) {
173 sqlStmt1 = sqlStmt1 +
", :" + ss.str();
176 sqlStmt1 = sqlStmt1 +
")";
178 sb4 si =
sizeof(int);
179 sb4 sf =
sizeof(float);
182 int c1[200], c2[200];
184 for (i = 0; i < 200; ++
i) {
190 stmt1->setSQL(sqlStmt1);
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();
197 map_index = map_index + 1;
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();
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;
222 for (j = 0; j < sizei; ++
j) {
223 c[
j][
i] = obj->
obj[id_det][
i][
j];
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]);
232 if (obj_name !=
"test")
233 stmt1->executeArrayUpdate(sizev);
248 sqlStmt =
"SELECT max(record_id) from " + obj_name;
250 stmt->setSQL(sqlStmt);
251 oracle::occi::ResultSet *rset;
252 rset =
stmt->executeQuery();
254 while (rset->next()) {
255 *record = rset->getInt(1);
268 int map_id = 0, layer_id = 0;
271 tab_map = obj_name +
"_map";
272 tab_data = obj_name +
"_data";
279 oracle::occi::ResultSet *rset, *rset1;
280 std::ostringstream
ss;
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));
289 sqlStmt =
"SELECT count(column_name) from user_tab_columns where table_name='" + ss.str() +
"'";
291 stmt->setSQL(sqlStmt);
292 rset =
stmt->executeQuery();
294 while (rset->next()) {
295 num_var = rset->getInt(1) - 2;
303 stmt->closeResultSet(rset);
307 sqlStmt =
"SELECT map_id,map_index,layer_id from " + tab_map +
" where record_id=" + ss.str() +
" order by map_index";
309 stmt->setSQL(sqlStmt);
310 rset =
stmt->executeQuery();
312 while (rset->next()) {
313 map_id = rset->getInt(1);
315 layer_id = rset->getInt(3);
317 sqlStmt1 =
"SELECT * from " + tab_data +
" where map_id=" + ss.str() +
" order by vec_index";
319 stmt1->setSQL(sqlStmt1);
320 rset1 =
stmt1->executeQuery();
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));
const edm::EventSetup & c
condbon() noexcept(false)
oracle::occi::Statement * stmt
void cdbon_last_record(std::string obj_name, int *record)
void cdbon_write(CSCobject *obj, std::string obj_name, int record, int global_run, std::string time)
oracle::occi::Connection * con
std::map< int, std::vector< std::vector< float > > > obj
oracle::occi::Environment * env
~condbon() noexcept(false)
oracle::occi::Statement * stmt1
void cdbon_read_rec(std::string obj_name, int record, CSCobject *obj)