17#include "GaudiKernel/Kernel.h"
18#include "GaudiKernel/IInterface.h"
19#include "GaudiKernel/StatusCode.h"
20#include "GaudiKernel/SvcFactory.h"
21#include "GaudiKernel/MsgStream.h"
22#include "GaudiKernel/ISvcLocator.h"
23#include "GaudiKernel/SmartDataPtr.h"
24#include "GaudiKernel/IDataProviderSvc.h"
25#include "GaudiKernel/PropertyMgr.h"
28#include "GaudiKernel/IIncidentSvc.h"
29#include "GaudiKernel/Incident.h"
30#include "GaudiKernel/IIncidentListener.h"
32#include "GaudiKernel/ISvcLocator.h"
33#include "GaudiKernel/Bootstrap.h"
44 Service (name, svcloc){
46 declareProperty(
"Host" , host = std::string(
"bes3db2.ihep.ac.cn"));
47 declareProperty(
"DbName" , dbName = std::string(
"offlinedb"));
48 declareProperty(
"UserName" , userName = std::string(
"guest"));
49 declareProperty(
"Password" , password = std::string(
"guestpass"));
50 declareProperty(
"IsData" , m_isData = std::string(
"default"));
51 declareProperty(
"BossRelease",m_bossRelease = std::string(
"default"));
52 declareProperty(
"TofEnergyPar",m_calPar=
"default");
53 declareProperty(
"TofEnergyBossVer",m_bossVer=
"default");
61 if( IID_ITofEnergyCalibSvc.versionMatch(riid) ){
64 return Service::queryInterface(riid, ppvInterface);
66 return StatusCode::SUCCESS;
70 MsgStream log(messageService(), name());
71 log << MSG::INFO <<
"TofEnergyCalibSvc::initialize()" << endreq;
73 StatusCode sc = Service::initialize();
74 if( sc.isFailure() )
return sc;
78 sc = service(
"IncidentSvc", incsvc);
81 incsvc -> addListener(
this,
"NewRun", priority);
84 sc = serviceLocator()->service(
"DatabaseSvc",
m_dbsvc,
true);
85 if (sc .isFailure() ) {
86 log << MSG::ERROR <<
"Unable to find DatabaseSvc " << endreq;
90 sc = serviceLocator()->service(
"EventDataSvc", m_eventSvc,
true);
91 if (sc .isFailure() ) {
92 log << MSG::ERROR <<
"Unable to find EventDataSvc " << endreq;
96 return StatusCode::SUCCESS;
100 MsgStream log(messageService(), name());
101 log << MSG::INFO <<
"TofEnergyCalibSvc::finalize()" << endreq;
103 return StatusCode::SUCCESS;
107 MsgStream log( messageService(), name() );
108 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
110 if ( inc.type() ==
"NewRun" ){
111 log << MSG::DEBUG <<
"NewRun" << endreq;
113 log << MSG::ERROR <<
"can not initilize Tof energy Calib Constants" << endreq;
120 std::string& CalParVer,
124 std::string BossRelease,
128 MsgStream log(
msgSvc(),
"TofEnergyCalibSvc" );
134 StatusCode sc=serviceLocator()->service(
"DatabaseSvc",
m_dbsvc,
true);
135 if (sc .isFailure() ) {
136 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
140 const char* bossRelease = BossRelease.c_str();
141 const char* dataType = DataType.c_str();
143 sprintf(stmt,
"select RunFrom,RunTo,SftVer,ParVer from CalVtxLumVer where BossRelease = '%s' and RunFrom <= %d and RunTo >= %d and DataType='%s' ",bossRelease,run_No,run_No,dataType);
147 std::cout<<
"ERROR:error searching with:"<<stmt<<std::endl;
152 runfrm=records1->
GetInt(
"RunFrom");
153 runto=records1->
GetInt(
"RunTo");
154 cout<<dataType<<
" runfrm,runto in getSftParVer is:"<<runfrm<<
"::::"<<runto<<endl;
159 cout<<
"ERROR: "<<dataType<<
" set overlapped run number in the table CalVtxLumVer"<<endl;
162 return StatusCode::SUCCESS;
165 MsgStream log(messageService(), name());
166 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,
"/Event/EventHeader");
167 int run = eventHeader->runNumber();
178 cout <<
"This data is the MC sample with the Run Number: " << run << endl;
182 if(m_bossRelease==
"default") m_bossRelease = getenv(
"BES_RELEASE");
183 if(m_isData==
"default")
185 cout<<
"Please set the type of TofEnergy"<<endl;
188 if(m_isData==
"Data") cType=
"TofEnergyData";
189 if(m_isData==
"MC") cType=
"TofEnergyMC";
190 st1=
getSftParVer(m_bossVer,m_calPar,runfrm1,runto1,run,m_bossRelease,cType);
191 if(cType==
"TofEnergyData"){
192 sprintf(stmt1,
"select CalibConst,Para1,Para2,Para3,Para4,Para5 from TofEnergyCalib where BossVer = '%s' and RunFrom <= %d and RunTo >= %d and isData = '%s'", m_bossVer.c_str(), run, run, m_isData.c_str());}
193 else if(cType==
"TofEnergyMC"){
194 sprintf(stmt1,
"select CalibConst,Para1,Para2,Para3,Para4,Para5 from TofEnergySim where BossVer = '%s' and RunFrom <= %d and RunTo >= %d and isData = '%s'", m_bossVer.c_str(), run, run, m_isData.c_str());}
200 m_CalibConst = dbrec.
GetDouble(
"CalibConst");
207 cout<<
"BossReleaseVer="<<m_bossRelease.c_str()<<
"\t"<<
"TofEnergyBossVer="<<m_bossVer.c_str()<<endl;
208 cout<<
"m_CalibConst is:"<<m_CalibConst<<endl;
209 cout<<
"Para1="<<m_Para1<<
"\t"
210 <<
"Para2="<<m_Para2<<
"\t"
211 <<
"Para3="<<m_Para3<<
"\t"
212 <<
"Para4="<<m_Para4<<
"\t"
213 <<
"Para5="<<m_Para5<<endl;
214 cout <<
"Successfully fetch TofEnergyCalibSvc information for run: "
217 }
else if( row_no<=0 ) {
218 cout <<
" TofEnergyCalibSvc:: can not found TofEnergyCalibSvc information of run:"
219 << run <<
", boss version " << m_bossRelease << endl;
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
struct st_mysql_res MYSQL_RES
double GetDouble(std::string key)
int GetInt(std::string key)
std::string GetString(std::string key)
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0
virtual StatusCode initialize()
bool getTofEnergyCalibSvcInfo()
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
TofEnergyCalibSvc(const std::string &name, ISvcLocator *svcloc)
virtual StatusCode finalize()
void handle(const Incident &)
StatusCode getSftParVer(std::string &SftVer, std::string &CalParVer, int &runfrm, int &runto, int RunNo, std::string BossRelease, std::string DataType)