BOSS 7.1.2
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
38DECLARE_COMPONENT(EmcShEnCalibSvc)
39
40EmcShEnCalibSvc::EmcShEnCalibSvc( const string& name, ISvcLocator* svcloc) :
41 base_class (name, svcloc){
42 // declare properties
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");
50 m_ReadPar = false;
51 m_RunFrom = 0;
52 m_RunTo = 0;
53}
54
57
58/*StatusCode EmcShEnCalibSvc::queryInterface(const InterfaceID& riid, void** ppvInterface){
59 if( IID_IEmcShEnCalibSvc.versionMatch(riid) ){
60 *ppvInterface = static_cast<IEmcShEnCalibSvc*> (this);
61 } else{
62 return Service::queryInterface(riid, ppvInterface);
63 }
64 return StatusCode::SUCCESS;
65}*/
66
68 MsgStream log(messageService(), name());
69 log << MSG::INFO << "EmcShEnCalibSvc::initialize()" << endreq;
70
71 StatusCode sc = Service::initialize();
72 if( sc.isFailure() ) return sc;
73
74
75 IIncidentSvc* incsvc;
76 sc = service("IncidentSvc", incsvc);
77 int priority = 100;
78 if( sc.isSuccess() ){
79 incsvc -> addListener(this, "NewRun", priority);
80 }
81
82 sc = serviceLocator()->service("DatabaseSvc",m_dbsvc,true);
83 if (sc .isFailure() ) {
84 log << MSG::ERROR << "Unable to find DatabaseSvc " << endreq;
85 return sc;
86 }
87
88 sc = serviceLocator()->service("EventDataSvc", m_eventSvc, true);
89 if (sc .isFailure() ) {
90 log << MSG::ERROR << "Unable to find EventDataSvc " << endreq;
91 return sc;
92 }
93
94 return StatusCode::SUCCESS;
95}
96
98 MsgStream log(messageService(), name());
99 log << MSG::INFO << "EmcShEnCalibSvc::finalize()" << endreq;
100 // if(m_connect_offline) delete m_connect_offline;
101 return StatusCode::SUCCESS;
102}
103
104void EmcShEnCalibSvc::handle(const Incident& inc){
105 MsgStream log( messageService(), name() );
106 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
107
108 if ( inc.type() == "NewRun" ){
109 log << MSG::DEBUG << "NewRun" << endreq;
110
111 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,"/Event/EventHeader");
112 int run = eventHeader->runNumber();
113 //cout<<"&&&&&&&&&&&&&&:&&&&&&&&&&&&&&&&&&&& EmcShEnCalibSvc handle,run="<<run<<endl;
114 if (run<0) run = -run;
115 log << MSG::DEBUG << "handle: " <<"Run in handle is: "<<run<< endreq;
116 //cout<<"-------------in EmcShEnCalibSvc in the following-----------" <<endl;
117 //cout<< "handle: " <<"Run in handle is: "<<run<<endl;
118
119 if (run>=m_RunFrom&&run<=m_RunTo&&m_ReadPar==true){
120 //cout<<"do not read the database repeatly in EmcShEnCalibConst"<<endl;
121 //cout<<"run,RunFrom,runTo="<<run<<","<<m_RunFrom<<","<<m_RunTo<<endl;
122 } else {
123
124 //cout<<"read the database in EmcShEnCalibConst"<<endl;
126 log << MSG::ERROR << "can not initilize Shower energy Calib Constants" << endreq;
127 } else {
128 m_ReadPar=true;
129 //std::cout << "in handle of EmcShEnCalibSvc getPi0CalibFile()= " << getPi0CalibFile()<<std::endl;
130 //std::cout << "getSingleGammaCalibFile()= " << getSingleGammaCalibFile() << std::endl;
131 }
132
133 }
134 }
135
136}
137
138//select sftver and parver frm table CalVtxLum
139StatusCode EmcShEnCalibSvc::getSftParVer(std::string& SftVer,
140 std::string& CalParVer,
141 int &runfrm,
142 int &runto,
143 int RunNo,
144 std::string BossRelease,
145 std::string DataType
146 )
147{
148 MsgStream log(msgSvc(), "EmcShEnCalibSvc" );
149 char stmt[300];
150 int run_No =RunNo;
151 MYSQL_RES *res_set;
154 StatusCode sc=serviceLocator()->service("DatabaseSvc",m_dbsvc,true);
155 if (sc .isFailure() ) {
156 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
157 return sc;
158 }
159
160 const char* bossRelease = BossRelease.c_str();
161 const char* dataType = DataType.c_str();
162
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);
164 //cout<<"stmt="<<stmt<<endl;
165
166 int row_no = m_dbsvc->query("offlinedb",stmt,res);
167 //cout<<"raw_no="<<row_no<<endl;
168 if(row_no<1){
169 std::cout<<"ERROR:error searching with:"<<stmt<<std::endl;
170 exit(1);
171 }
172 if(row_no==1){
173 DatabaseRecord* records1 = res[0];
174 runfrm=records1->GetInt("RunFrom");
175 runto=records1->GetInt("RunTo");
176 //cout<<dataType<<" runfrm,runto in getSftParVer is:"<<runfrm<<"::::"<<runto<<endl;
177
178 SftVer=records1->GetString("SftVer");
179 CalParVer=records1->GetString("ParVer");
180 // cout<<"stmt="<<stmt<<"\t"<<SftVer<<"\t"<<CalParVer<<endl;
181 }
182 if(row_no>1){
183 cout<<"ERROR: "<<dataType<<" set overlapped run number in the table CalVtxLumVer"<<endl;
184 exit(1);
185 }
186 return StatusCode::SUCCESS;
187}
188
190 MsgStream log(messageService(), name());
191 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,"/Event/EventHeader");
192 int run = eventHeader->runNumber();
193 //cout<<"Run in getEmcShEnCalibSvcInfo() is: "<<run<<endl;
194
195 char stmt1[400];
196 StatusCode st1;
197 //runfrm,runto are the value from the table ***CalConst;runfrm1,runto1 are the value from the table CalVtxLumVer
198 int runfrm1;
199 int runto1;
200 std::string cType;
201
202 if(run<0) {
203 //cout << "This data is the MC sample with the Run Number: " << run << endl;
204 run = -run;
205 }
206
207 if(m_bossRelease=="default") m_bossRelease = getenv("BES_RELEASE");
208
209 cType="EmcShEnCalib";
210
211 st1=getSftParVer(m_bossVer,m_calPar,runfrm1,runto1,run,m_bossRelease,cType);
212
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);
214
216 int row_no = m_dbsvc->query("offlinedb",stmt1,res);
217
218 if( row_no > 0 ) {
219 DatabaseRecord& dbrec = *res[row_no-1];
220 m_SingleGammaCalibFile = dbrec.GetString("singleGammaCalib");
221 m_Pi0CalibFile = dbrec.GetString("pi0Calib");
222 m_RunFrom = dbrec.GetInt("RunFrom");
223 m_RunTo = dbrec.GetInt("RunTo");
224
225 /*
226 cout<<"BossReleaseVer="<<m_bossRelease.c_str()<<"\t"<<"EmcShEnCalibBossVer="<<m_bossVer.c_str()<<endl;
227 cout<<"m_Pi0CalibFile is:"<<m_Pi0CalibFile<<endl;
228 cout<<"m_SingleGammaCalibFile is:"<<m_SingleGammaCalibFile<<endl;
229 cout<<"m_RunFrom is:"<<m_RunFrom<<endl;
230 cout<<"m_RunTo is:"<<m_RunTo<<endl;
231 cout << "Successfully fetch EmcShEnCalibSvc information for run: " << run << endl;
232 //cout<<"////////// read parameters from EmcShEnCalibConst database/////////////"<<endl;
233 */
234 return true;
235 } else if( row_no<=0 ) {
236 cout << " EmcShEnCalibSvc:: can not found EmcShEnCalibSvc information of run:"
237 << run << ", boss version " << m_bossRelease << endl;
238 exit(1);
239 return false;
240 }
241 return true;
242}
243
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)
StatusCode getSftParVer(std::string &SftVer, std::string &CalParVer, int &runfrm, int &runto, int RunNo, std::string BossRelease, std::string DataType)
virtual StatusCode finalize()
void handle(const Incident &)
IDatabaseSvc * m_dbsvc
virtual StatusCode initialize()
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0