13#include "GaudiKernel/Kernel.h"
14#include "GaudiKernel/IInterface.h"
15#include "GaudiKernel/StatusCode.h"
16#include "GaudiKernel/SvcFactory.h"
17#include "GaudiKernel/MsgStream.h"
18#include "GaudiKernel/ISvcLocator.h"
19#include "GaudiKernel/SmartDataPtr.h"
20#include "GaudiKernel/IDataProviderSvc.h"
21#include "GaudiKernel/PropertyMgr.h"
24#include "GaudiKernel/IIncidentSvc.h"
25#include "GaudiKernel/Incident.h"
26#include "GaudiKernel/IIncidentListener.h"
28#include "GaudiKernel/ISvcLocator.h"
29#include "GaudiKernel/Bootstrap.h"
41 base_class (name, svcloc){
43 declareProperty(
"Host" , host = std::string(
"bes3db2.ihep.ac.cn"));
44 declareProperty(
"DbName" , dbName = std::string(
"offlinedb"));
45 declareProperty(
"UserName" , userName = std::string(
"guest"));
46 declareProperty(
"Password" , password = std::string(
"guestpass"));
47 declareProperty(
"BossRelease",m_bossRelease = std::string(
"default"));
48 declareProperty(
"EmcShEnCalibPar",m_calPar=
"default");
49 declareProperty(
"EmcShEnCalibBossVer",m_bossVer=
"default");
68 MsgStream log(messageService(), name());
69 log << MSG::INFO <<
"EmcShEnCalibSvc::initialize()" << endreq;
71 StatusCode sc = Service::initialize();
72 if( sc.isFailure() )
return sc;
76 sc = service(
"IncidentSvc", incsvc);
79 incsvc -> addListener(
this,
"NewRun", priority);
82 sc = serviceLocator()->service(
"DatabaseSvc",
m_dbsvc,
true);
83 if (sc .isFailure() ) {
84 log << MSG::ERROR <<
"Unable to find DatabaseSvc " << endreq;
88 sc = serviceLocator()->service(
"EventDataSvc", m_eventSvc,
true);
89 if (sc .isFailure() ) {
90 log << MSG::ERROR <<
"Unable to find EventDataSvc " << endreq;
94 return StatusCode::SUCCESS;
98 MsgStream log(messageService(), name());
99 log << MSG::INFO <<
"EmcShEnCalibSvc::finalize()" << endreq;
101 return StatusCode::SUCCESS;
105 MsgStream log( messageService(), name() );
106 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
108 if ( inc.type() ==
"NewRun" ){
109 log << MSG::DEBUG <<
"NewRun" << endreq;
111 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,
"/Event/EventHeader");
112 int run = eventHeader->runNumber();
114 if (run<0) run = -run;
115 log << MSG::DEBUG <<
"handle: " <<
"Run in handle is: "<<run<< endreq;
119 if (run>=m_RunFrom&&run<=m_RunTo&&m_ReadPar==
true){
126 log << MSG::ERROR <<
"can not initilize Shower energy Calib Constants" << endreq;
140 std::string& CalParVer,
144 std::string BossRelease,
148 MsgStream log(
msgSvc(),
"EmcShEnCalibSvc" );
154 StatusCode sc=serviceLocator()->service(
"DatabaseSvc",
m_dbsvc,
true);
155 if (sc .isFailure() ) {
156 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
160 const char* bossRelease = BossRelease.c_str();
161 const char* dataType = DataType.c_str();
163 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);
169 std::cout<<
"ERROR:error searching with:"<<stmt<<std::endl;
174 runfrm=records1->
GetInt(
"RunFrom");
175 runto=records1->
GetInt(
"RunTo");
183 cout<<
"ERROR: "<<dataType<<
" set overlapped run number in the table CalVtxLumVer"<<endl;
186 return StatusCode::SUCCESS;
190 MsgStream log(messageService(), name());
191 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,
"/Event/EventHeader");
192 int run = eventHeader->runNumber();
207 if(m_bossRelease==
"default") m_bossRelease = getenv(
"BES_RELEASE");
209 cType=
"EmcShEnCalib";
211 st1=
getSftParVer(m_bossVer,m_calPar,runfrm1,runto1,run,m_bossRelease,cType);
213 sprintf(stmt1,
"select RunFrom,RunTo,singleGammaCalib,pi0Calib from EmcShEnCalibConst where SftVer = '%s' and RunFrom <= %d and RunTo >= %d ", m_bossVer.c_str(), run, run);
220 m_SingleGammaCalibFile = dbrec.
GetString(
"singleGammaCalib");
221 m_Pi0CalibFile = dbrec.
GetString(
"pi0Calib");
222 m_RunFrom = dbrec.
GetInt(
"RunFrom");
223 m_RunTo = dbrec.
GetInt(
"RunTo");
235 }
else if( row_no<=0 ) {
236 cout <<
" EmcShEnCalibSvc:: can not found EmcShEnCalibSvc information of run:"
237 << 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
int GetInt(std::string key)
std::string GetString(std::string key)
StatusCode getSftParVer(std::string &SftVer, std::string &CalParVer, int &runfrm, int &runto, int RunNo, std::string BossRelease, std::string DataType)
bool getEmcShEnCalibSvcInfo()
virtual StatusCode finalize()
void handle(const Incident &)
virtual StatusCode initialize()
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0