BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
copy_table_db2db.C
Go to the documentation of this file.
1
#include "../../../uni_db_settings.h"
2
3
int
copy_table_db2db
()
4
{
5
TStopwatch
timer;
6
timer.
Start
();
7
gDebug
= 0;
8
9
// connection to MySQL
10
TSQLServer
* MySQLServer =
11
TSQLServer::Connect
(
"mysql://nc4.jinr.ru/mpd_grids"
, MYSQL_DB_USERNAME, MYSQL_DB_PASSWORD);
12
if
(MySQLServer ==
nullptr
) {
13
cout <<
"Error: connection to MySQLServer wasn't established"
<< endl;
14
return
nullptr
;
15
}
16
17
// connection to PostgreSQL
18
TSQLServer
* PgSQLServer =
19
TSQLServer::Connect
(
"pgsql://"
+
UNI_DB_HOST
+
"/"
+
UNI_DB_NAME
,
UNI_DB_USERNAME
,
UNI_DB_PASSWORD
);
20
if
(PgSQLServer ==
nullptr
) {
21
cout <<
"Error: connection to PgSQLServer wasn't established"
<< endl;
22
return
nullptr
;
23
}
24
25
// read from mysql
26
TString
my_sql =
TString::Format
(
"select id, data4mpd_datatype, data4mpd_generator, data4mpd_collision, "
27
"data4mpd_energy, data4mpd_trigger, data4mpd_path, data4mpd_description "
28
"from events"
);
29
TSQLStatement
* my_stmt = MySQLServer->
Statement
(my_sql);
30
31
// write to pgsql
32
TString
pg_sql =
TString::Format
(
"insert into simulation_file(file_path, generator_name, beam_particle, "
33
"target_particle, energy, centrality, file_desc) "
34
"values ($1, $2, $3, $4, $5, $6, $7)"
);
35
TSQLStatement
* pg_stmt = PgSQLServer->
Statement
(pg_sql);
36
37
// get table record from DB
38
if
(!my_stmt->
Process
()) {
39
cout <<
"Error: getting all records from MySQL DB has been failed"
<< endl;
40
41
delete
my_stmt;
42
delete
pg_stmt;
43
delete
MySQLServer;
44
delete
PgSQLServer;
45
return
-1;
46
}
47
48
// store result of statement in buffer
49
my_stmt->
StoreResult
();
50
51
// insert to pgSQL
52
while
(my_stmt->
NextResultRow
()) {
53
if
(pg_stmt->
NextIteration
()) {
54
// file_path
55
if
(my_stmt->
IsNull
(6))
56
pg_stmt->
SetNull
(0);
57
else
58
pg_stmt->
SetString
(0, my_stmt->
GetString
(6));
59
// generator_name
60
if
(my_stmt->
IsNull
(2))
61
pg_stmt->
SetNull
(1);
62
else
63
pg_stmt->
SetString
(1, my_stmt->
GetString
(2));
64
// beam_particle, target_particle
65
if
(my_stmt->
IsNull
(3)) {
66
pg_stmt->
SetNull
(2);
67
pg_stmt->
SetNull
(3);
68
}
else
{
69
TString
str_collision = my_stmt->
GetString
(3);
70
str_collision.
ToLower
();
71
int
index = 0;
72
for
(
int
i
= 0;
i
< 2;
i
++) {
73
if
(str_collision[index] ==
'a'
) {
74
pg_stmt->
SetString
(2 +
i
,
"Au"
);
75
index++;
76
index++;
77
}
else
{
78
if
(str_collision[index] ==
'd'
) {
79
pg_stmt->
SetString
(2 +
i
,
"d"
);
80
index++;
81
}
else
{
82
if
(str_collision[index] ==
'c'
) {
83
pg_stmt->
SetString
(2 +
i
,
"C"
);
84
index++;
85
}
86
}
87
}
88
}
89
}
90
// energy
91
if
(my_stmt->
IsNull
(4))
92
pg_stmt->
SetNull
(4);
93
else
94
pg_stmt->
SetDouble
(4, my_stmt->
GetDouble
(4));
95
// centrality
96
if
(my_stmt->
IsNull
(5))
97
pg_stmt->
SetNull
(5);
98
else
99
pg_stmt->
SetString
(5, my_stmt->
GetString
(5));
100
// description
101
if
(my_stmt->
IsNull
(7))
102
pg_stmt->
SetNull
(6);
103
else
104
pg_stmt->
SetString
(6, my_stmt->
GetString
(7));
105
}
106
}
107
108
// inserting new records to PgSQL DB
109
if
(!pg_stmt->
Process
()) {
110
cout <<
"Error: inserting new records to PgSQL DB has been failed"
<< endl;
111
delete
my_stmt;
112
delete
pg_stmt;
113
delete
MySQLServer;
114
delete
PgSQLServer;
115
return
-2;
116
}
117
118
delete
my_stmt;
119
delete
pg_stmt;
120
delete
MySQLServer;
121
delete
PgSQLServer;
122
123
timer.
Stop
();
124
Double_t
rtime = timer.
RealTime
(), ctime = timer.
CpuTime
();
125
printf(
"RealTime=%f seconds, CpuTime=%f seconds\n"
, rtime, ctime);
126
127
cout <<
"Macro was successfull"
<< endl;
128
129
return
0;
130
}
i
int i
Definition
P4_F32vec4.h:22
gDebug
Int_t gDebug
Double_t
double Double_t
TSQLServer
TSQLServer::Connect
static TSQLServer * Connect(const char *db, const char *uid, const char *pw)
TSQLServer::Statement
virtual TSQLStatement * Statement(const char *, Int_t=100)
TSQLStatement
TSQLStatement::GetString
virtual const char * GetString(Int_t)
TSQLStatement::NextIteration
virtual Bool_t NextIteration()=0
TSQLStatement::NextResultRow
virtual Bool_t NextResultRow()=0
TSQLStatement::SetString
virtual Bool_t SetString(Int_t, const char *, Int_t=256)
TSQLStatement::IsNull
virtual Bool_t IsNull(Int_t)
TSQLStatement::SetDouble
virtual Bool_t SetDouble(Int_t, Double_t)
TSQLStatement::Process
virtual Bool_t Process()=0
TSQLStatement::SetNull
virtual Bool_t SetNull(Int_t)
TSQLStatement::GetDouble
virtual Double_t GetDouble(Int_t)
TSQLStatement::StoreResult
virtual Bool_t StoreResult()=0
TStopwatch
TStopwatch::RealTime
Double_t RealTime()
TStopwatch::Start
void Start(Bool_t reset=kTRUE)
TStopwatch::CpuTime
Double_t CpuTime()
TStopwatch::Stop
void Stop()
TString
TString::ToLower
void ToLower()
TString::Format
static TString Format(const char *fmt,...)
copy_table_db2db
int copy_table_db2db()
Definition
copy_table_db2db.C:3
UNI_DB_HOST
const char *const UNI_DB_HOST
Definition
uni_db_settings.h:9
UNI_DB_NAME
const char *const UNI_DB_NAME
Definition
uni_db_settings.h:10
UNI_DB_PASSWORD
const char *const UNI_DB_PASSWORD
Definition
uni_db_settings.h:8
UNI_DB_USERNAME
const char *const UNI_DB_USERNAME
Definition
uni_db_settings.h:7
database
uni_db
macros
etc
copy_table_db2db.C
Generated on
for BmnRoot by
1.17.0