#include <ReadEb.h>
Public Member Functions | |
ReadEb (int run) | |
virtual | ~ReadEb () |
double | getEcms () |
double | getXangle () |
CLHEP::Hep3Vector | getbeta () |
bool | setcalib (bool calib) |
Private Member Functions | |
MYSQL * | OpenDb () const |
void | ReadDb (int run) |
void | CloseDb (MYSQL *mysql) const |
Private Attributes | |
IDatabaseSvc * | m_dbsvc |
int | m_run |
bool | m_isRunValid |
double | m_beamE |
bool | m_usecbE |
CLHEP::Hep3Vector | m_beta |
Static Private Attributes | |
static double | m_Ecms = 3.773 |
static double | m_xangle = 0.011 |
static int | previousRun = -1 |
Definition at line 17 of file ReadEb.h.
ReadEb::ReadEb | ( | int | run | ) | [inline] |
Definition at line 21 of file ReadEb.h.
References previousRun, and ReadDb().
00021 : 00022 m_run(-1), 00023 m_isRunValid(false), 00024 m_beamE(0), 00025 m_beta(0.011,0,0), 00026 m_usecbE(true){ 00027 if ( run != previousRun) { 00028 previousRun = run; 00029 ReadDb(run); 00030 } 00031 }
void ReadEb::CloseDb | ( | MYSQL * | mysql | ) | const [private] |
CLHEP::Hep3Vector ReadEb::getbeta | ( | ) | [inline] |
double ReadEb::getEcms | ( | ) | [inline] |
double ReadEb::getXangle | ( | ) | [inline] |
MYSQL * ReadEb::OpenDb | ( | ) | const [private] |
Definition at line 24 of file ReadEb.cxx.
00024 { 00025 00026 const char host[] = "bes3db2.ihep.ac.cn"; 00027 const char user[] = "guest"; 00028 const char passwd[] = "guestpass"; 00029 //const char db[] = "run"; 00030 const char db[] = "offlinedb"; 00031 unsigned int port_num = 3306; 00032 00033 MYSQL* mysql = mysql_init(NULL); 00034 mysql = mysql_real_connect(mysql, host, user, passwd, db, port_num, 00035 NULL, // socket 00036 0); // client_flag 00037 00038 if (mysql == NULL) { 00039 fprintf(stderr, "can not open database: offlinedb\n"); 00040 } 00041 00042 return mysql; 00043 }
void ReadEb::ReadDb | ( | int | run | ) | [private] |
Definition at line 51 of file ReadEb.cxx.
References DatabaseRecord::GetDouble(), m_beamE, m_beta, m_dbsvc, m_Ecms, m_usecbE, m_xangle, and IDatabaseSvc::query().
Referenced by ReadEb().
00051 { 00052 00053 //read db use service 00054 Gaudi::svcLocator()->service("DatabaseSvc",m_dbsvc,true); 00055 //calibrated beam Energy 00056 if(m_usecbE){ 00057 char stmt1[400]; 00058 snprintf(stmt1, 1024, 00059 "select beam_energy, px, py, pz " 00060 "from RunParams664 where run_number = %d", run);//664 and 664p01 share the same database 00061 DatabaseRecordVector res; 00062 int row_no = m_dbsvc->query("offlinedb", stmt1, res); 00063 if(row_no==0){ 00064 std::cout<<"Failed to read offline database"<<std::endl;abort(); 00065 } 00066 00067 DatabaseRecord* records = res[0]; 00068 double bE=0; 00069 bE = records->GetDouble("beam_energy"); 00070 m_beamE=bE; 00071 00072 double px=records->GetDouble("px"); 00073 double py=records->GetDouble("py"); 00074 double pz=records->GetDouble("pz"); 00075 00076 m_beta.setX(px); 00077 m_beta.setY(py); 00078 m_beta.setZ(pz); 00079 00080 m_Ecms = bE*2; 00081 m_xangle = px; 00082 // std::cout<<"beam e is:"<<bE<<", px="<<px<<",py="<<py<<",pz="<<pz<<std::endl; 00083 } 00084 //use online beam Energy 00085 else{ 00086 char stmt1[400]; 00087 snprintf(stmt1, 1024, 00088 "select BER_PRB, BPR_PRB " 00089 "from RunParams where run_number = %d", run); 00090 DatabaseRecordVector res; 00091 int row_no = m_dbsvc->query("run", stmt1, res); 00092 if(row_no==0){ 00093 std::cout<<"Failed to read online database"<<std::endl;abort(); 00094 } 00095 00096 DatabaseRecord* records = res[0]; 00097 double E_E=0, E_P=0; 00098 E_E = records->GetDouble("BER_PRB"); 00099 E_P = records->GetDouble("BPR_PRB"); 00100 m_beamE=(E_E+E_P)/2.0; 00101 m_Ecms = m_beamE*2; 00102 m_xangle = 0.011; 00103 } 00104 00105 }
double ReadEb::m_beamE [private] |
CLHEP::Hep3Vector ReadEb::m_beta [private] |
IDatabaseSvc* ReadEb::m_dbsvc [private] |
double ReadEb::m_Ecms = 3.773 [static, private] |
bool ReadEb::m_isRunValid [private] |
int ReadEb::m_run [private] |
bool ReadEb::m_usecbE [private] |
double ReadEb::m_xangle = 0.011 [static, private] |
int ReadEb::previousRun = -1 [static, private] |