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"
40 Service (name, svcloc){
42 declareProperty(
"Host" , host = std::string(
"bes3db2.ihep.ac.cn"));
43 declareProperty(
"DbName" , dbName = std::string(
"offlinedb"));
44 declareProperty(
"UserName" , userName = std::string(
"guest"));
45 declareProperty(
"Password" , password = std::string(
"guestpass"));
46 declareProperty(
"BossRelease",m_bossRelease = std::string(
"default"));
47 declareProperty(
"EmcShEnCalibPar",m_calPar=
"default");
48 declareProperty(
"EmcShEnCalibBossVer",m_bossVer=
"default");
58 if( IID_IEmcShEnCalibSvc.versionMatch(riid) ){
61 return Service::queryInterface(riid, ppvInterface);
63 return StatusCode::SUCCESS;
67 MsgStream log(messageService(), name());
68 log << MSG::INFO <<
"EmcShEnCalibSvc::initialize()" << endreq;
70 StatusCode sc = Service::initialize();
71 if( sc.isFailure() )
return sc;
75 sc = service(
"IncidentSvc", incsvc);
78 incsvc -> addListener(
this,
"NewRun", priority);
81 sc = serviceLocator()->service(
"DatabaseSvc",
m_dbsvc,
true);
82 if (sc .isFailure() ) {
83 log << MSG::ERROR <<
"Unable to find DatabaseSvc " << endreq;
87 sc = serviceLocator()->service(
"EventDataSvc", m_eventSvc,
true);
88 if (sc .isFailure() ) {
89 log << MSG::ERROR <<
"Unable to find EventDataSvc " << endreq;
93 return StatusCode::SUCCESS;
97 MsgStream log(messageService(), name());
98 log << MSG::INFO <<
"EmcShEnCalibSvc::finalize()" << endreq;
100 return StatusCode::SUCCESS;
104 MsgStream log( messageService(), name() );
105 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
107 if ( inc.type() ==
"NewRun" ){
108 log << MSG::DEBUG <<
"NewRun" << endreq;
110 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,
"/Event/EventHeader");
111 int run = eventHeader->runNumber();
113 if (run<0) run = -run;
114 log << MSG::DEBUG <<
"handle: " <<
"Run in handle is: "<<run<< endreq;
118 if (run>=m_RunFrom&&run<=m_RunTo&&m_ReadPar==
true){
125 log << MSG::ERROR <<
"can not initilize Shower energy Calib Constants" << endreq;
139 std::string& CalParVer,
143 std::string BossRelease,
147 MsgStream log(
msgSvc(),
"EmcShEnCalibSvc" );
153 StatusCode sc=serviceLocator()->service(
"DatabaseSvc",
m_dbsvc,
true);
154 if (sc .isFailure() ) {
155 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
159 const char* bossRelease = BossRelease.c_str();
160 const char* dataType = DataType.c_str();
162 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);
167 std::cout<<
"ERROR:error searching with:"<<stmt<<std::endl;
172 runfrm=records1->
GetInt(
"RunFrom");
173 runto=records1->
GetInt(
"RunTo");
181 cout<<
"ERROR: "<<dataType<<
" set overlapped run number in the table CalVtxLumVer"<<endl;
184 return StatusCode::SUCCESS;
188 MsgStream log(messageService(), name());
189 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,
"/Event/EventHeader");
190 int run = eventHeader->runNumber();
205 if(m_bossRelease==
"default") m_bossRelease = getenv(
"BES_RELEASE");
207 cType=
"EmcShEnCalib";
209 st1=
getSftParVer(m_bossVer,m_calPar,runfrm1,runto1,run,m_bossRelease,cType);
211 sprintf(stmt1,
"select RunFrom,RunTo,singleGammaCalib,pi0Calib from EmcShEnCalibConst where SftVer = '%s' and RunFrom <= %d and RunTo >= %d ", m_bossVer.c_str(), run, run);
218 m_SingleGammaCalibFile = dbrec.
GetString(
"singleGammaCalib");
219 m_Pi0CalibFile = dbrec.
GetString(
"pi0Calib");
220 m_RunFrom = dbrec.
GetInt(
"RunFrom");
221 m_RunTo = dbrec.
GetInt(
"RunTo");
233 }
else if( row_no<=0 ) {
234 cout <<
" EmcShEnCalibSvc:: can not found EmcShEnCalibSvc information of run:"
235 << 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)
EmcShEnCalibSvc(const std::string &name, ISvcLocator *svcloc)
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()
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
void handle(const Incident &)
virtual StatusCode initialize()
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0