BOSS
7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
ReadEb.cxx
Go to the documentation of this file.
1
/****************************************
2
* Read CMS energy from data base for
3
* psi(3770) production
4
*
5
* 2012-1-05 created pingrg
6
*
7
***************************************/
8
9
#include "GaudiKernel/Bootstrap.h"
10
#include "GaudiKernel/IJobOptionsSvc.h"
11
#include "GaudiKernel/ISvcLocator.h"
12
#include "GaudiKernel/PropertyMgr.h"
13
14
15
#include "
KKMC/ReadEb.h
"
16
#include <string>
17
#include <string.h>
18
19
int
ReadEb::previousRun=-1;
20
double
ReadEb::m_Ecms=3.773;
21
double
ReadEb::m_xangle=0.011;
22
23
24
MYSQL
* ReadEb::OpenDb()
const
{
25
26
const
char
host[] =
"bes3db2.ihep.ac.cn"
;
27
const
char
user[] =
"guest"
;
28
const
char
passwd[] =
"guestpass"
;
29
//const char db[] = "run";
30
const
char
db[] =
"offlinedb"
;
31
unsigned
int
port_num = 3306;
32
33
MYSQL
* mysql = mysql_init(NULL);
34
mysql = mysql_real_connect(mysql, host, user, passwd, db, port_num,
35
NULL,
// socket
36
0);
// client_flag
37
38
if
(mysql == NULL) {
39
fprintf(stderr,
"can not open database: offlinedb\n"
);
40
}
41
42
return
mysql;
43
}
44
45
46
void
ReadEb::CloseDb(
MYSQL
* mysql)
const
{
47
mysql_close(mysql);
48
}
49
50
51
void
ReadEb::ReadDb(
int
run){
52
53
//read db use service
54
Gaudi::svcLocator()->service(
"DatabaseSvc"
,m_dbsvc,
true
);
55
//calibrated beam Energy
56
if
(m_usecbE){
57
char
stmt1[400];
58
snprintf(stmt1, 1024,
59
"select beam_energy, px, py, pz "
60
"from RunParams664 where run_number = %d"
, run);
//664 and 664p01 share the same database
61
DatabaseRecordVector
res;
62
int
row_no = m_dbsvc->
query
(
"offlinedb"
, stmt1, res);
63
if
(row_no==0){
64
std::cout<<
"Failed to read offline database"
<<std::endl;abort();
65
}
66
67
DatabaseRecord
* records = res[0];
68
double
bE=0;
69
bE = records->
GetDouble
(
"beam_energy"
);
70
m_beamE=bE;
71
72
double
px=records->
GetDouble
(
"px"
);
73
double
py=records->
GetDouble
(
"py"
);
74
double
pz=records->
GetDouble
(
"pz"
);
75
76
m_beta.setX(px);
77
m_beta.setY(py);
78
m_beta.setZ(pz);
79
80
m_Ecms = bE*2;
81
m_xangle = px;
82
// std::cout<<"beam e is:"<<bE<<", px="<<px<<",py="<<py<<",pz="<<pz<<std::endl;
83
}
84
//use online beam Energy
85
else
{
86
char
stmt1[400];
87
snprintf(stmt1, 1024,
88
"select BER_PRB, BPR_PRB "
89
"from RunParams where run_number = %d"
, run);
90
DatabaseRecordVector
res;
91
int
row_no = m_dbsvc->
query
(
"run"
, stmt1, res);
92
if
(row_no==0){
93
std::cout<<
"Failed to read online database"
<<std::endl;abort();
94
}
95
96
DatabaseRecord
* records = res[0];
97
double
E_E=0, E_P=0;
98
E_E = records->
GetDouble
(
"BER_PRB"
);
99
E_P = records->
GetDouble
(
"BPR_PRB"
);
100
m_beamE=(E_E+E_P)/2.0;
101
m_Ecms = m_beamE*2;
102
m_xangle = 0.011;
103
}
104
105
}
106
107
108
109
MYSQL
struct st_mysql MYSQL
Definition:
MysqlConnection.h:11
ReadEb.h
DatabaseRecordVector
Definition:
DatabaseRecord.h:75
DatabaseRecord
Definition:
DatabaseRecord.h:10
DatabaseRecord::GetDouble
double GetDouble(std::string key)
Definition:
DatabaseRecord.h:46
IDatabaseSvc::query
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0
source
Generator
KKMC
KKMC-00-00-62
src
ReadEb.cxx
Generated by
1.9.6