#include <ReadBeamInfFromDb.h>
Public Member Functions | |
ReadBeamInfFromDb () | |
~ReadBeamInfFromDb () | |
bool | isRunValid (int run) |
double | getbeamE (int run) |
ReadBeamInfFromDb () | |
~ReadBeamInfFromDb () | |
bool | isRunValid (int run) |
double | getbeamE (int run, double defaultbeamE) |
CLHEP::Hep3Vector | getbeta () |
bool | setcalib (bool calib) |
Private Member Functions | |
MYSQL * | OpenDb () const |
void | ReadDb (int run) |
void | CloseDb (MYSQL *mysql) const |
MYSQL * | OpenDb () const |
double | ReadDb (int run) |
void | CloseDb (MYSQL *mysql) const |
Private Attributes | |
int | m_run |
bool | m_isRunValid |
double | m_beamE |
IDatabaseSvc * | m_dbsvc |
bool | m_usecbE |
CLHEP::Hep3Vector | m_beta |
Definition at line 9 of file ReadBeamInfFromDb.h.
ReadBeamInfFromDb::ReadBeamInfFromDb | ( | ) |
Definition at line 5 of file ReadBeamInfFromDb.cxx.
00005 : 00006 m_run(-1), 00007 m_isRunValid(false), 00008 m_beamE(0){ 00009 }
ReadBeamInfFromDb::~ReadBeamInfFromDb | ( | ) | [inline] |
ReadBeamInfFromDb::ReadBeamInfFromDb | ( | ) |
ReadBeamInfFromDb::~ReadBeamInfFromDb | ( | ) | [inline] |
void ReadBeamInfFromDb::CloseDb | ( | MYSQL * | mysql | ) | const [private] |
void ReadBeamInfFromDb::CloseDb | ( | MYSQL * | mysql | ) | const [private] |
double ReadBeamInfFromDb::getbeamE | ( | int | run, | |
double | defaultbeamE | |||
) |
Definition at line 153 of file ReadBeamInfFromDb.cxx.
References isRunValid(), and m_beamE.
00153 { 00154 int absrun=fabs(run); 00155 00156 if (!isRunValid(absrun)){ 00157 return defaultbeamE; 00158 fprintf(stderr, "ERROR in ReadBeamInfFromDb: runNo is invalid!\n"); 00159 } 00160 return m_beamE; 00161 }
double ReadBeamInfFromDb::getbeamE | ( | int | run | ) |
Definition at line 84 of file ReadBeamInfFromDb.cxx.
References isRunValid(), and m_beamE.
Referenced by NeutralDReconstruction::execute(), DsReconstruction::execute(), ChargedDReconstruction::execute(), and DQADtag::execute().
00084 { 00085 if (!isRunValid(run)){ 00086 fprintf(stderr, "ERROR in ReadBeamInfFromDb: runNo is invalid!\n"); 00087 } 00088 return m_beamE; 00089 }
CLHEP::Hep3Vector ReadBeamInfFromDb::getbeta | ( | ) | [inline] |
Definition at line 19 of file ReadBeamInfFromDb.h.
References m_beta.
Referenced by NeutralDReconstruction::execute(), DsReconstruction::execute(), and ChargedDReconstruction::execute().
00019 {return m_beta;}
bool ReadBeamInfFromDb::isRunValid | ( | int | run | ) |
bool ReadBeamInfFromDb::isRunValid | ( | int | run | ) |
Definition at line 75 of file ReadBeamInfFromDb.cxx.
References m_isRunValid, m_run, and ReadDb().
Referenced by DQADtag::execute(), and getbeamE().
00075 { 00076 if (run == -1 || m_run != run) { 00077 ReadDb(run); 00078 } 00079 00080 return m_isRunValid; 00081 }
MYSQL* ReadBeamInfFromDb::OpenDb | ( | ) | const [private] |
MYSQL * ReadBeamInfFromDb::OpenDb | ( | ) | const [private] |
Definition at line 11 of file ReadBeamInfFromDb.cxx.
Referenced by ReadDb().
00011 { 00012 00013 const char host[] = "bes3db2.ihep.ac.cn"; 00014 const char user[] = "guest"; 00015 const char passwd[] = "guestpass"; 00016 const char db[] = "run"; 00017 unsigned int port_num = 3306; 00018 00019 MYSQL* mysql = mysql_init(NULL); 00020 mysql = mysql_real_connect(mysql, host, user, passwd, db, port_num, 00021 NULL, // socket 00022 0); // client_flag 00023 00024 if (mysql == NULL) { 00025 fprintf(stderr, "can not open database: offlinedb\n"); 00026 } 00027 00028 return mysql; 00029 }
double ReadBeamInfFromDb::ReadDb | ( | int | run | ) | [private] |
double ReadBeamInfFromDb::ReadDb | ( | int | run | ) | [private] |
Definition at line 37 of file ReadBeamInfFromDb.cxx.
References CloseDb(), m_beamE, m_isRunValid, m_run, and OpenDb().
Referenced by isRunValid().
00037 { 00038 00039 m_run=run; 00040 m_isRunValid = false; 00041 00042 MYSQL* mysql=OpenDb(); 00043 00044 char stmt[1024]; 00045 snprintf(stmt, 1024, 00046 "select BER_PRB, BPR_PRB " 00047 "from RunParams where run_number = %d", run); 00048 if (mysql_real_query(mysql, stmt, strlen(stmt))) { 00049 fprintf(stderr, "query error\n"); 00050 return ; 00051 } 00052 00053 00054 MYSQL_RES* result_set = mysql_store_result(mysql); 00055 MYSQL_ROW row = mysql_fetch_row(result_set); 00056 if (!row) { 00057 fprintf(stderr, "cannot find data for RunNo %d\n", run); 00058 return ; 00059 } 00060 00061 m_isRunValid = true; 00062 00063 double E_E=0, E_P=0; 00064 sscanf(row[0], "%lf", &E_E); 00065 sscanf(row[1], "%lf", &E_P); 00066 00067 m_beamE=(E_E+E_P)/2.0; 00068 00069 // Free the memory to prevent memory leak! 00070 mysql_free_result(result_set); 00071 00072 CloseDb(mysql); 00073 }
Definition at line 20 of file ReadBeamInfFromDb.h.
References m_usecbE.
Referenced by NeutralDReconstruction::execute(), DsReconstruction::execute(), and ChargedDReconstruction::execute().
00020 {m_usecbE=calib;}
double ReadBeamInfFromDb::m_beamE [private] |
CLHEP::Hep3Vector ReadBeamInfFromDb::m_beta [private] |
IDatabaseSvc* ReadBeamInfFromDb::m_dbsvc [private] |
Definition at line 27 of file ReadBeamInfFromDb.h.
bool ReadBeamInfFromDb::m_isRunValid [private] |
int ReadBeamInfFromDb::m_run [private] |
bool ReadBeamInfFromDb::m_usecbE [private] |