BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
ElogBeam.cxx
Go to the documentation of this file.
1
// ----------------------------------------------------------------------
2
// ElogBeam cxx file
3
// Generated 27-11-2017
4
// ----------------------------------------------------------------------
5
6
#include "
ElogBeam.h
"
7
8
#include "
TSQLServer.h
"
9
#include "
TSQLStatement.h
"
10
11
#include <iostream>
12
using namespace
std
;
13
14
/* GENERATED CLASS MEMBERS (SHOULD NOT BE CHANGED MANUALLY) */
15
// ----- Constructor with database connection -----------------------
16
ElogBeam::ElogBeam
(
ElogConnection
* db_connect,
TString
beam,
bool
is_active)
17
{
18
connectionDB
= db_connect;
19
20
str_beam
= beam;
21
b_is_active
= is_active;
22
}
23
24
// ----- Destructor -------------------------------------------------
25
ElogBeam::~ElogBeam
()
26
{
27
if
(
connectionDB
)
28
delete
connectionDB
;
29
}
30
31
// ----- Creating new beam in the database ---------------------------
32
ElogBeam
*
ElogBeam::CreateBeam
(
TString
beam,
bool
is_active)
33
{
34
ElogConnection
* connDb =
ElogConnection::Open
();
35
if
(connDb ==
nullptr
)
36
return
nullptr
;
37
38
TSQLServer
* db_server = connDb->
GetSQLServer
();
39
40
TString
sql =
TString::Format
(
"insert into beam_(beam, is_active) "
41
"values ($1, $2)"
);
42
TSQLStatement
* stmt = db_server->
Statement
(sql);
43
44
stmt->
NextIteration
();
45
stmt->
SetString
(0, beam);
46
stmt->
SetInt
(1, is_active);
47
48
// inserting new beam to the Database
49
if
(!stmt->
Process
()) {
50
cout <<
"ERROR: inserting new beam to the Database has been failed"
<< endl;
51
delete
stmt;
52
delete
connDb;
53
return
nullptr
;
54
}
55
56
delete
stmt;
57
58
TString
tmp_beam;
59
tmp_beam = beam;
60
bool
tmp_is_active;
61
tmp_is_active = is_active;
62
63
return
new
ElogBeam
(connDb, tmp_beam, tmp_is_active);
64
}
65
66
// ----- Get beam from the database ---------------------------
67
ElogBeam
*
ElogBeam::GetBeam
(
TString
beam)
68
{
69
ElogConnection
* connDb =
ElogConnection::Open
();
70
if
(connDb ==
nullptr
)
71
return
nullptr
;
72
73
TSQLServer
* db_server = connDb->
GetSQLServer
();
74
75
TString
sql =
TString::Format
(
"select beam, is_active "
76
"from beam_ "
77
"where lower(beam) = lower('%s')"
,
78
beam.
Data
());
79
TSQLStatement
* stmt = db_server->
Statement
(sql);
80
81
// get beam from the database
82
if
(!stmt->
Process
()) {
83
cout <<
"ERROR: getting beam from the database has been failed"
<< endl;
84
85
delete
stmt;
86
delete
connDb;
87
return
nullptr
;
88
}
89
90
// store result of statement in buffer
91
stmt->
StoreResult
();
92
93
// extract row
94
if
(!stmt->
NextResultRow
()) {
95
cout <<
"ERROR: beam was not found in the database"
<< endl;
96
97
delete
stmt;
98
delete
connDb;
99
return
nullptr
;
100
}
101
102
TString
tmp_beam;
103
tmp_beam = stmt->
GetString
(0);
104
bool
tmp_is_active;
105
tmp_is_active = stmt->
GetInt
(1);
106
107
delete
stmt;
108
109
return
new
ElogBeam
(connDb, tmp_beam, tmp_is_active);
110
}
111
112
// ----- Check beam exists in the database ---------------------------
113
int
ElogBeam::CheckBeamExists
(
TString
beam)
114
{
115
ElogConnection
* connDb =
ElogConnection::Open
();
116
if
(connDb ==
nullptr
)
117
return
-1;
118
119
TSQLServer
* db_server = connDb->
GetSQLServer
();
120
121
TString
sql =
TString::Format
(
"select 1 "
122
"from beam_ "
123
"where lower(beam) = lower('%s')"
,
124
beam.
Data
());
125
TSQLStatement
* stmt = db_server->
Statement
(sql);
126
127
// get beam from the database
128
if
(!stmt->
Process
()) {
129
cout <<
"ERROR: getting beam from the database has been failed"
<< endl;
130
131
delete
stmt;
132
delete
connDb;
133
return
-2;
134
}
135
136
// store result of statement in buffer
137
stmt->
StoreResult
();
138
139
// extract row
140
if
(!stmt->
NextResultRow
()) {
141
delete
stmt;
142
delete
connDb;
143
return
0;
144
}
145
146
delete
stmt;
147
delete
connDb;
148
149
return
1;
150
}
151
152
// ----- Delete beam from the database ---------------------------
153
int
ElogBeam::DeleteBeam
(
TString
beam)
154
{
155
ElogConnection
* connDb =
ElogConnection::Open
();
156
if
(connDb ==
nullptr
)
157
return
-1;
158
159
TSQLServer
* db_server = connDb->
GetSQLServer
();
160
161
TString
sql =
TString::Format
(
"delete from beam_ "
162
"where lower(beam) = lower($1)"
);
163
TSQLStatement
* stmt = db_server->
Statement
(sql);
164
165
stmt->
NextIteration
();
166
stmt->
SetString
(0, beam);
167
168
// delete beam from the dataBase
169
if
(!stmt->
Process
()) {
170
cout <<
"ERROR: deleting beam from the dataBase has been failed"
<< endl;
171
172
delete
stmt;
173
delete
connDb;
174
return
-2;
175
}
176
177
delete
stmt;
178
delete
connDb;
179
return
0;
180
}
181
182
// ----- Print all 'beams' ---------------------------------
183
int
ElogBeam::PrintAll
()
184
{
185
ElogConnection
* connDb =
ElogConnection::Open
();
186
if
(connDb ==
nullptr
)
187
return
-1;
188
189
TSQLServer
* db_server = connDb->
GetSQLServer
();
190
191
TString
sql =
TString::Format
(
"select beam, is_active "
192
"from beam_"
);
193
TSQLStatement
* stmt = db_server->
Statement
(sql);
194
195
// get all 'beams' from the database
196
if
(!stmt->
Process
()) {
197
cout <<
"ERROR: getting all 'beams' from the dataBase has been failed"
<< endl;
198
199
delete
stmt;
200
delete
connDb;
201
return
-2;
202
}
203
204
// store result of statement in buffer
205
stmt->
StoreResult
();
206
207
// print rows
208
cout <<
"Table 'beam_':"
<< endl;
209
while
(stmt->
NextResultRow
()) {
210
cout <<
"beam: "
;
211
cout << (stmt->
GetString
(0));
212
cout <<
", is_active: "
;
213
cout << (stmt->
GetInt
(1));
214
cout <<
"."
<< endl;
215
}
216
217
delete
stmt;
218
delete
connDb;
219
220
return
0;
221
}
222
223
// Setters functions
224
int
ElogBeam::SetBeam
(
TString
beam)
225
{
226
if
(!
connectionDB
) {
227
cout <<
"CRITICAL ERROR: Connection object is null"
<< endl;
228
return
-1;
229
}
230
231
TSQLServer
* db_server =
connectionDB
->GetSQLServer();
232
233
TString
sql =
TString::Format
(
"update beam_ "
234
"set beam = $1 "
235
"where beam = $2"
);
236
TSQLStatement
* stmt = db_server->
Statement
(sql);
237
238
stmt->
NextIteration
();
239
stmt->
SetString
(0, beam);
240
stmt->
SetString
(1,
str_beam
);
241
242
// write new value to the database
243
if
(!stmt->
Process
()) {
244
cout <<
"ERROR: updating information about beam has been failed"
<< endl;
245
246
delete
stmt;
247
return
-2;
248
}
249
250
str_beam
= beam;
251
252
delete
stmt;
253
return
0;
254
}
255
256
int
ElogBeam::SetIsActive
(
bool
is_active)
257
{
258
if
(!
connectionDB
) {
259
cout <<
"CRITICAL ERROR: Connection object is null"
<< endl;
260
return
-1;
261
}
262
263
TSQLServer
* db_server =
connectionDB
->GetSQLServer();
264
265
TString
sql =
TString::Format
(
"update beam_ "
266
"set is_active = $1 "
267
"where beam = $2"
);
268
TSQLStatement
* stmt = db_server->
Statement
(sql);
269
270
stmt->
NextIteration
();
271
stmt->
SetInt
(0, is_active);
272
stmt->
SetString
(1,
str_beam
);
273
274
// write new value to the database
275
if
(!stmt->
Process
()) {
276
cout <<
"ERROR: updating information about beam has been failed"
<< endl;
277
278
delete
stmt;
279
return
-2;
280
}
281
282
b_is_active
= is_active;
283
284
delete
stmt;
285
return
0;
286
}
287
288
// ----- Print current beam ---------------------------------------
289
void
ElogBeam::Print
()
290
{
291
cout <<
"Table 'beam_'"
;
292
cout <<
". beam: "
<<
str_beam
<<
". is_active: "
<<
b_is_active
<< endl;
293
294
return
;
295
}
296
/* END OF GENERATED CLASS PART (SHOULD NOT BE CHANGED MANUALLY) */
TSQLServer.h
TSQLStatement.h
ElogBeam::connectionDB
ElogConnection * connectionDB
connection to the database
Definition
ElogBeam.h:22
ElogBeam::PrintAll
static int PrintAll()
print all beams
Definition
ElogBeam.cxx:183
ElogBeam::GetBeam
TString GetBeam()
get beam of the current beam
Definition
ElogBeam.h:51
ElogBeam::SetBeam
int SetBeam(TString beam)
set beam of the current beam
Definition
ElogBeam.cxx:224
ElogBeam::CreateBeam
static ElogBeam * CreateBeam(TString beam, bool is_active)
add new beam to the database
Definition
ElogBeam.cxx:32
ElogBeam::str_beam
TString str_beam
beam
Definition
ElogBeam.h:25
ElogBeam::ElogBeam
ElogBeam(ElogConnection *db_connect, TString beam, bool is_active)
Definition
ElogBeam.cxx:16
ElogBeam::CheckBeamExists
static int CheckBeamExists(TString beam)
check beam exists in the database: 1- true, 0 - false, <0 - database operation error
Definition
ElogBeam.cxx:113
ElogBeam::DeleteBeam
static int DeleteBeam(TString beam)
delete beam from the database
Definition
ElogBeam.cxx:153
ElogBeam::Print
void Print()
print information about current beam
Definition
ElogBeam.cxx:289
ElogBeam::SetIsActive
int SetIsActive(bool is_active)
set is active of the current beam
Definition
ElogBeam.cxx:256
ElogBeam::b_is_active
bool b_is_active
is active
Definition
ElogBeam.h:27
ElogBeam::~ElogBeam
virtual ~ElogBeam()
Definition
ElogBeam.cxx:25
ElogConnection
Definition
ElogConnection.h:27
ElogConnection::Open
static ElogConnection * Open()
Definition
ElogConnection.cxx:55
ElogConnection::GetSQLServer
TSQLServer * GetSQLServer()
Definition
ElogConnection.h:43
TSQLServer
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::GetInt
virtual Int_t GetInt(Int_t)
TSQLStatement::Process
virtual Bool_t Process()=0
TSQLStatement::SetInt
virtual Bool_t SetInt(Int_t, Int_t)
TSQLStatement::StoreResult
virtual Bool_t StoreResult()=0
TString
TString::Data
const char * Data() const
TString::Format
static TString Format(const char *fmt,...)
ElogBeam.h
std
Definition
json.hpp:4446
database
elog_db
ElogBeam.cxx
Generated on
for BmnRoot by
1.17.0