ReadEb Class Reference

#include <ReadEb.h>

List of all members.

Public Member Functions

 ReadEb (int run)
virtual ~ReadEb ()
double getEcms ()
double getXangle ()
CLHEP::Hep3Vector getbeta ()
bool setcalib (bool calib)

Private Member Functions

MYSQLOpenDb () const
void ReadDb (int run)
void CloseDb (MYSQL *mysql) const

Private Attributes

IDatabaseSvcm_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


Detailed Description

Definition at line 17 of file ReadEb.h.


Constructor & Destructor Documentation

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  }

virtual ReadEb::~ReadEb (  )  [inline, virtual]

Definition at line 33 of file ReadEb.h.

00033 {}


Member Function Documentation

void ReadEb::CloseDb ( MYSQL mysql  )  const [private]

Definition at line 46 of file ReadEb.cxx.

00046                                        {
00047   mysql_close(mysql);
00048 }

CLHEP::Hep3Vector ReadEb::getbeta (  )  [inline]

Definition at line 37 of file ReadEb.h.

References m_beta.

00037 {return m_beta;}

double ReadEb::getEcms (  )  [inline]

Definition at line 35 of file ReadEb.h.

References m_Ecms.

00035 {return m_Ecms;}

double ReadEb::getXangle (  )  [inline]

Definition at line 36 of file ReadEb.h.

References m_xangle.

00036 {return m_xangle;}

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 } 

bool ReadEb::setcalib ( bool  calib  )  [inline]

Definition at line 38 of file ReadEb.h.

References m_usecbE.

00038 {m_usecbE=calib;}


Member Data Documentation

double ReadEb::m_beamE [private]

Definition at line 48 of file ReadEb.h.

Referenced by ReadDb().

CLHEP::Hep3Vector ReadEb::m_beta [private]

Definition at line 52 of file ReadEb.h.

Referenced by getbeta(), and ReadDb().

IDatabaseSvc* ReadEb::m_dbsvc [private]

Definition at line 45 of file ReadEb.h.

Referenced by ReadDb().

double ReadEb::m_Ecms = 3.773 [static, private]

Definition at line 49 of file ReadEb.h.

Referenced by getEcms(), and ReadDb().

bool ReadEb::m_isRunValid [private]

Definition at line 47 of file ReadEb.h.

int ReadEb::m_run [private]

Definition at line 46 of file ReadEb.h.

bool ReadEb::m_usecbE [private]

Definition at line 51 of file ReadEb.h.

Referenced by ReadDb(), and setcalib().

double ReadEb::m_xangle = 0.011 [static, private]

Definition at line 50 of file ReadEb.h.

Referenced by getXangle(), and ReadDb().

int ReadEb::previousRun = -1 [static, private]

Definition at line 53 of file ReadEb.h.

Referenced by ReadEb().


Generated on Tue Nov 29 23:20:47 2016 for BOSS_7.0.2 by  doxygen 1.4.7