/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Generator/KKMC/KKMC-00-00-55/src/ReadEb.cxx

Go to the documentation of this file.
00001 /****************************************
00002  * Read CMS energy from data base for 
00003  * psi(3770) production
00004  *
00005  * 2012-1-05 created pingrg 
00006  *
00007  ***************************************/
00008 
00009 #include "GaudiKernel/Bootstrap.h"
00010 #include "GaudiKernel/IJobOptionsSvc.h"
00011 #include "GaudiKernel/ISvcLocator.h"
00012 #include "GaudiKernel/PropertyMgr.h"
00013 
00014 
00015 #include "KKMC/ReadEb.h"
00016 #include <string>
00017 #include <string.h>
00018 
00019 int ReadEb::previousRun=-1;
00020 double ReadEb::m_Ecms=3.773;
00021 double ReadEb::m_xangle=0.011;
00022 
00023 
00024 MYSQL* ReadEb::OpenDb() const {
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 }
00044 
00045 
00046 void ReadEb::CloseDb(MYSQL* mysql) const {
00047   mysql_close(mysql);
00048 }
00049 
00050 
00051 void ReadEb::ReadDb(int run){
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 } 
00106 
00107 
00108 
00109 

Generated on Tue Nov 29 23:12:40 2016 for BOSS_7.0.2 by  doxygen 1.4.7