BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
EmcShEnCalibSvc Class Reference

#include <EmcShEnCalibSvc.h>

+ Inheritance diagram for EmcShEnCalibSvc:

Public Member Functions

 EmcShEnCalibSvc (const std::string &name, ISvcLocator *svcloc)
 
 ~EmcShEnCalibSvc ()
 
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvUnknown)
 
virtual StatusCode initialize ()
 
virtual StatusCode finalize ()
 
void handle (const Incident &)
 
void SetBossRelease (const std::string &_bossrelease)
 
std::string GetBossRelease () const
 
StatusCode getSftParVer (std::string &SftVer, std::string &CalParVer, int &runfrm, int &runto, int RunNo, std::string BossRelease, std::string DataType)
 
bool getEmcShEnCalibSvcInfo ()
 
std::string getPi0CalibFile () const
 
std::string getSingleGammaCalibFile () const
 
unsigned int getRunFrom () const
 
unsigned int getRunTo () const
 
virtual void SetBossRelease (const std::string &_bossrelease)=0
 
virtual std::string GetBossRelease () const =0
 
virtual bool getEmcShEnCalibSvcInfo ()=0
 
virtual std::string getPi0CalibFile () const =0
 
virtual std::string getSingleGammaCalibFile () const =0
 
virtual unsigned int getRunFrom () const =0
 
virtual unsigned int getRunTo () const =0
 

Public Attributes

IDatabaseSvcm_dbsvc
 

Additional Inherited Members

- Static Public Member Functions inherited from IEmcShEnCalibSvc
static const InterfaceID & interfaceID ()
 

Detailed Description

Definition at line 21 of file EmcShEnCalibSvc.h.

Constructor & Destructor Documentation

◆ EmcShEnCalibSvc()

EmcShEnCalibSvc::EmcShEnCalibSvc ( const std::string &  name,
ISvcLocator *  svcloc 
)

Definition at line 39 of file EmcShEnCalibSvc.cxx.

39 :
40 Service (name, svcloc){
41 // declare properties
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");
49 m_ReadPar = false;
50 m_RunFrom = 0;
51 m_RunTo = 0;
52}

◆ ~EmcShEnCalibSvc()

EmcShEnCalibSvc::~EmcShEnCalibSvc ( )

Definition at line 54 of file EmcShEnCalibSvc.cxx.

54 {
55}

Member Function Documentation

◆ finalize()

StatusCode EmcShEnCalibSvc::finalize ( )
virtual

Definition at line 96 of file EmcShEnCalibSvc.cxx.

96 {
97 MsgStream log(messageService(), name());
98 log << MSG::INFO << "EmcShEnCalibSvc::finalize()" << endreq;
99 // if(m_connect_offline) delete m_connect_offline;
100 return StatusCode::SUCCESS;
101}

◆ GetBossRelease()

std::string EmcShEnCalibSvc::GetBossRelease ( ) const
inlinevirtual

Implements IEmcShEnCalibSvc.

Definition at line 40 of file EmcShEnCalibSvc.h.

40{return m_bossRelease;}

◆ getEmcShEnCalibSvcInfo()

bool EmcShEnCalibSvc::getEmcShEnCalibSvcInfo ( )
virtual

Implements IEmcShEnCalibSvc.

Definition at line 187 of file EmcShEnCalibSvc.cxx.

187 {
188 MsgStream log(messageService(), name());
189 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,"/Event/EventHeader");
190 int run = eventHeader->runNumber();
191 //cout<<"Run in getEmcShEnCalibSvcInfo() is: "<<run<<endl;
192
193 char stmt1[400];
194 StatusCode st1;
195 //runfrm,runto are the value from the table ***CalConst;runfrm1,runto1 are the value from the table CalVtxLumVer
196 int runfrm1;
197 int runto1;
198 std::string cType;
199
200 if(run<0) {
201 //cout << "This data is the MC sample with the Run Number: " << run << endl;
202 run = -run;
203 }
204
205 if(m_bossRelease=="default") m_bossRelease = getenv("BES_RELEASE");
206
207 cType="EmcShEnCalib";
208
209 st1=getSftParVer(m_bossVer,m_calPar,runfrm1,runto1,run,m_bossRelease,cType);
210
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);
212
214 int row_no = m_dbsvc->query("offlinedb",stmt1,res);
215
216 if( row_no > 0 ) {
217 DatabaseRecord& dbrec = *res[row_no-1];
218 m_SingleGammaCalibFile = dbrec.GetString("singleGammaCalib");
219 m_Pi0CalibFile = dbrec.GetString("pi0Calib");
220 m_RunFrom = dbrec.GetInt("RunFrom");
221 m_RunTo = dbrec.GetInt("RunTo");
222
223 /*
224 cout<<"BossReleaseVer="<<m_bossRelease.c_str()<<"\t"<<"EmcShEnCalibBossVer="<<m_bossVer.c_str()<<endl;
225 cout<<"m_Pi0CalibFile is:"<<m_Pi0CalibFile<<endl;
226 cout<<"m_SingleGammaCalibFile is:"<<m_SingleGammaCalibFile<<endl;
227 cout<<"m_RunFrom is:"<<m_RunFrom<<endl;
228 cout<<"m_RunTo is:"<<m_RunTo<<endl;
229 cout << "Successfully fetch EmcShEnCalibSvc information for run: " << run << endl;
230 cout<<"////////// read parameters from EmcShEnCalibConst database/////////////"<<endl;
231 */
232 return true;
233 } else if( row_no<=0 ) {
234 cout << " EmcShEnCalibSvc:: can not found EmcShEnCalibSvc information of run:"
235 << run << ", boss version " << m_bossRelease << endl;
236 exit(1);
237 return false;
238 }
239 return true;
240}
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)
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)
IDatabaseSvc * m_dbsvc
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0

Referenced by handle().

◆ getPi0CalibFile()

std::string EmcShEnCalibSvc::getPi0CalibFile ( ) const
inlinevirtual

Implements IEmcShEnCalibSvc.

Definition at line 51 of file EmcShEnCalibSvc.h.

51{return m_Pi0CalibFile;}

◆ getRunFrom()

unsigned int EmcShEnCalibSvc::getRunFrom ( ) const
inlinevirtual

Implements IEmcShEnCalibSvc.

Definition at line 53 of file EmcShEnCalibSvc.h.

53{ return m_RunFrom;}

◆ getRunTo()

unsigned int EmcShEnCalibSvc::getRunTo ( ) const
inlinevirtual

Implements IEmcShEnCalibSvc.

Definition at line 54 of file EmcShEnCalibSvc.h.

54{ return m_RunTo;}

◆ getSftParVer()

StatusCode EmcShEnCalibSvc::getSftParVer ( std::string &  SftVer,
std::string &  CalParVer,
int &  runfrm,
int &  runto,
int  RunNo,
std::string  BossRelease,
std::string  DataType 
)

Definition at line 138 of file EmcShEnCalibSvc.cxx.

146{
147 MsgStream log(msgSvc(), "EmcShEnCalibSvc" );
148 char stmt[300];
149 int run_No =RunNo;
150 MYSQL_RES *res_set;
153 StatusCode sc=serviceLocator()->service("DatabaseSvc",m_dbsvc,true);
154 if (sc .isFailure() ) {
155 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
156 return sc;
157 }
158
159 const char* bossRelease = BossRelease.c_str();
160 const char* dataType = DataType.c_str();
161
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);
163 //cout<<"stmt="<<stmt<<endl;
164
165 int row_no = m_dbsvc->query("offlinedb",stmt,res);
166 if(row_no<1){
167 std::cout<<"ERROR:error searching with:"<<stmt<<std::endl;
168 exit(1);
169 }
170 if(row_no==1){
171 DatabaseRecord* records1 = res[0];
172 runfrm=records1->GetInt("RunFrom");
173 runto=records1->GetInt("RunTo");
174 //cout<<dataType<<" runfrm,runto in getSftParVer is:"<<runfrm<<"::::"<<runto<<endl;
175
176 SftVer=records1->GetString("SftVer");
177 CalParVer=records1->GetString("ParVer");
178 //cout<<"stmt="<<stmt<<"\t"<<SftVer<<"\t"<<CalParVer<<endl;
179 }
180 if(row_no>1){
181 cout<<"ERROR: "<<dataType<<" set overlapped run number in the table CalVtxLumVer"<<endl;
182 exit(1);
183 }
184 return StatusCode::SUCCESS;
185}
char * SftVer
Definition: DQA_TO_DB.cxx:18
struct st_mysql_res MYSQL_RES
IMessageSvc * msgSvc()

Referenced by getEmcShEnCalibSvcInfo().

◆ getSingleGammaCalibFile()

std::string EmcShEnCalibSvc::getSingleGammaCalibFile ( ) const
inlinevirtual

Implements IEmcShEnCalibSvc.

Definition at line 52 of file EmcShEnCalibSvc.h.

52{return m_SingleGammaCalibFile;}

◆ handle()

void EmcShEnCalibSvc::handle ( const Incident &  inc)

Definition at line 103 of file EmcShEnCalibSvc.cxx.

103 {
104 MsgStream log( messageService(), name() );
105 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
106
107 if ( inc.type() == "NewRun" ){
108 log << MSG::DEBUG << "NewRun" << endreq;
109
110 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,"/Event/EventHeader");
111 int run = eventHeader->runNumber();
112 //cout<<"&&&&&&&&&&&&&&:&&&&&&&&&&&&&&&&&&&& EmcShEnCalibSvc handle,run="<<run<<endl;
113 if (run<0) run = -run;
114 log << MSG::DEBUG << "handle: " <<"Run in handle is: "<<run<< endreq;
115 //cout<<"-------------in EmcShEnCalibSvc in the following-----------" <<endl;
116 //cout<< "handle: " <<"Run in handle is: "<<run<<endl;
117
118 if (run>=m_RunFrom&&run<=m_RunTo&&m_ReadPar==true){
119 //cout<<"do not read the database repeatly in EmcShEnCalibConst"<<endl;
120 //cout<<"run,RunFrom,runTo="<<run<<","<<m_RunFrom<<","<<m_RunTo<<endl;
121 } else {
122
123 //cout<<"read the database in EmcShEnCalibConst"<<endl;
125 log << MSG::ERROR << "can not initilize Shower energy Calib Constants" << endreq;
126 } else {
127 m_ReadPar=true;
128 //std::cout << "in handle of EmcShEnCalibSvc getPi0CalibFile()= " << getPi0CalibFile()<<std::endl;
129 //std::cout << "getSingleGammaCalibFile()= " << getSingleGammaCalibFile() << std::endl;
130 }
131
132 }
133 }
134
135}

◆ initialize()

StatusCode EmcShEnCalibSvc::initialize ( )
virtual

Definition at line 66 of file EmcShEnCalibSvc.cxx.

66 {
67 MsgStream log(messageService(), name());
68 log << MSG::INFO << "EmcShEnCalibSvc::initialize()" << endreq;
69
70 StatusCode sc = Service::initialize();
71 if( sc.isFailure() ) return sc;
72
73
74 IIncidentSvc* incsvc;
75 sc = service("IncidentSvc", incsvc);
76 int priority = 100;
77 if( sc.isSuccess() ){
78 incsvc -> addListener(this, "NewRun", priority);
79 }
80
81 sc = serviceLocator()->service("DatabaseSvc",m_dbsvc,true);
82 if (sc .isFailure() ) {
83 log << MSG::ERROR << "Unable to find DatabaseSvc " << endreq;
84 return sc;
85 }
86
87 sc = serviceLocator()->service("EventDataSvc", m_eventSvc, true);
88 if (sc .isFailure() ) {
89 log << MSG::ERROR << "Unable to find EventDataSvc " << endreq;
90 return sc;
91 }
92
93 return StatusCode::SUCCESS;
94}

◆ queryInterface()

StatusCode EmcShEnCalibSvc::queryInterface ( const InterfaceID &  riid,
void **  ppvUnknown 
)
virtual

Definition at line 57 of file EmcShEnCalibSvc.cxx.

57 {
58 if( IID_IEmcShEnCalibSvc.versionMatch(riid) ){
59 *ppvInterface = static_cast<IEmcShEnCalibSvc*> (this);
60 } else{
61 return Service::queryInterface(riid, ppvInterface);
62 }
63 return StatusCode::SUCCESS;
64}

◆ SetBossRelease()

void EmcShEnCalibSvc::SetBossRelease ( const std::string &  _bossrelease)
inlinevirtual

Implements IEmcShEnCalibSvc.

Definition at line 39 of file EmcShEnCalibSvc.h.

39{m_bossRelease = _bossrelease;}

Member Data Documentation

◆ m_dbsvc

IDatabaseSvc* EmcShEnCalibSvc::m_dbsvc

Definition at line 37 of file EmcShEnCalibSvc.h.

Referenced by getEmcShEnCalibSvcInfo(), getSftParVer(), and initialize().


The documentation for this class was generated from the following files: