BOSS 8.0.0
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/ISvcLocator.h"
11#include "GaudiKernel/PropertyMgr.h"
12
13#include "ReadEb.h"
14#include <string.h>
15#include <string>
16
17int ReadEb::previousRun = -1;
18double ReadEb::m_Ecms = 3.773;
19double ReadEb::m_xangle = 0.011;
20
21MYSQL* ReadEb::OpenDb() const {
22
23 const char host[] = "bes3db2.ihep.ac.cn";
24 const char user[] = "guest";
25 const char passwd[] = "guestpass";
26 // const char db[] = "run";
27 const char db[] = "offlinedb";
28 unsigned int port_num = 3306;
29
30 MYSQL* mysql = mysql_init( NULL );
31 mysql = mysql_real_connect( mysql, host, user, passwd, db, port_num,
32 NULL, // socket
33 0 ); // client_flag
34
35 if ( mysql == NULL ) { fprintf( stderr, "can not open database: offlinedb\n" ); }
36
37 return mysql;
38}
39
40void ReadEb::CloseDb( MYSQL* mysql ) const { mysql_close( mysql ); }
41
42void ReadEb::ReadDb( int run ) {
43
44 // read db use service
45 Gaudi::svcLocator()->service( "DatabaseSvc", m_dbsvc, true );
46 // calibrated beam Energy
47 if ( m_usecbE )
48 {
49 char stmt1[400];
50 snprintf( stmt1, 1024,
51 "select beam_energy, px, py, pz "
52 "from RunParams664 where run_number = %d",
53 run ); // 664 and 664p01 share the same database
54 DatabaseRecordVector res;
55 int row_no = m_dbsvc->query( "offlinedb", stmt1, res );
56 if ( row_no == 0 )
57 {
58 std::cout << "Failed to read offline database" << std::endl;
59 abort();
60 }
61
62 DatabaseRecord* records = res[0];
63 double bE = 0;
64 bE = records->GetDouble( "beam_energy" );
65 m_beamE = bE;
66
67 double px = records->GetDouble( "px" );
68 double py = records->GetDouble( "py" );
69 double pz = records->GetDouble( "pz" );
70
71 m_beta.setX( px );
72 m_beta.setY( py );
73 m_beta.setZ( pz );
74
75 m_Ecms = bE * 2;
76 m_xangle = px;
77 // std::cout<<"beam e is:"<<bE<<", px="<<px<<",py="<<py<<",pz="<<pz<<std::endl;
78 }
79 // use online beam Energy
80 else
81 {
82 char stmt1[400];
83 snprintf( stmt1, 1024,
84 "select BER_PRB, BPR_PRB "
85 "from RunParams where run_number = %d",
86 run );
87 DatabaseRecordVector res;
88 int row_no = m_dbsvc->query( "run", stmt1, res );
89 if ( row_no == 0 )
90 {
91 std::cout << "Failed to read online database" << std::endl;
92 abort();
93 }
94
95 DatabaseRecord* records = res[0];
96 double E_E = 0, E_P = 0;
97 E_E = records->GetDouble( "BER_PRB" );
98 E_P = records->GetDouble( "BPR_PRB" );
99 m_beamE = ( E_E + E_P ) / 2.0;
100 m_Ecms = m_beamE * 2;
101 m_xangle = 0.011;
102 }
103}