BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
EmcShEnCalibSvc.cxx
Go to the documentation of this file.
1// This service is used to read the EmcShEnCalibSvc information from the database
2//
3// the joboption for this service is shown in share/jobOptions_EmcShEnCalibSvc.txt
4
5
6#include <iostream>
7#include <sstream>
8#include <cstring>
9#include <cstdlib>
10#include <cstdio>
11
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"
22
23
24#include "GaudiKernel/IIncidentSvc.h"
25#include "GaudiKernel/Incident.h"
26#include "GaudiKernel/IIncidentListener.h"
27
28#include "GaudiKernel/ISvcLocator.h"
29#include "GaudiKernel/Bootstrap.h"
31#include "EventModel/Event.h"
33
34#include <TMath.h>
35
36using namespace std;
37
38
39EmcShEnCalibSvc::EmcShEnCalibSvc( const string& name, ISvcLocator* svcloc) :
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}
53
55}
56
57StatusCode EmcShEnCalibSvc::queryInterface(const InterfaceID& riid, void** ppvInterface){
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}
65
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}
95
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}
102
103void EmcShEnCalibSvc::handle(const Incident& inc){
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}
136
137//select sftver and parver frm table CalVtxLum
138StatusCode EmcShEnCalibSvc::getSftParVer(std::string& SftVer,
139 std::string& CalParVer,
140 int &runfrm,
141 int &runto,
142 int RunNo,
143 std::string BossRelease,
144 std::string DataType
145 )
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}
186
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}
241
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)
char * SftVer
Definition: DQA_TO_DB.cxx:18
struct st_mysql_res MYSQL_RES
IMessageSvc * msgSvc()
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)
virtual StatusCode finalize()
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
void handle(const Incident &)
IDatabaseSvc * m_dbsvc
virtual StatusCode initialize()
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0