BOSS 8.0.0
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#include <cstdio>
6#include <cstdlib>
7#include <cstring>
8#include <iostream>
9#include <sstream>
10
11#include "GaudiKernel/Bootstrap.h"
12#include "GaudiKernel/IDataProviderSvc.h"
13#include "GaudiKernel/IIncidentListener.h"
14#include "GaudiKernel/IIncidentSvc.h"
15#include "GaudiKernel/IInterface.h"
16#include "GaudiKernel/ISvcLocator.h"
17#include "GaudiKernel/Incident.h"
18#include "GaudiKernel/Kernel.h"
19#include "GaudiKernel/MsgStream.h"
20#include "GaudiKernel/PropertyMgr.h"
21#include "GaudiKernel/SmartDataPtr.h"
22#include "GaudiKernel/StatusCode.h"
23
24#include "EventModel/Event.h"
25#include "EventModel/EventHeader.h"
26#include "EventModel/EventModel.h"
27
28#include "EmcShEnCalibSvc.h"
29
30#include <TMath.h>
31
32using namespace std;
33
35
36EmcShEnCalibSvc::EmcShEnCalibSvc( const string& name, ISvcLocator* svcloc )
37 : base_class( name, svcloc ) {
38 // declare properties
39 declareProperty( "Host", host = std::string( "bes3db2.ihep.ac.cn" ) );
40 declareProperty( "DbName", dbName = std::string( "offlinedb" ) );
41 declareProperty( "UserName", userName = std::string( "guest" ) );
42 declareProperty( "Password", password = std::string( "guestpass" ) );
43 declareProperty( "BossRelease", m_bossRelease = std::string( "default" ) );
44 declareProperty( "EmcShEnCalibPar", m_calPar = "default" );
45 declareProperty( "EmcShEnCalibBossVer", m_bossVer = "default" );
46 m_ReadPar = false;
47 m_RunFrom = 0;
48 m_RunTo = 0;
49}
50
52
53/*StatusCode EmcShEnCalibSvc::queryInterface(const InterfaceID& riid, void** ppvInterface){
54 if( IID_IEmcShEnCalibSvc.versionMatch(riid) ){
55 *ppvInterface = static_cast<IEmcShEnCalibSvc*> (this);
56 } else{
57 return Service::queryInterface(riid, ppvInterface);
58 }
59 return StatusCode::SUCCESS;
60}*/
61
63 MsgStream log( msgSvc(), name() );
64 log << MSG::INFO << "EmcShEnCalibSvc::initialize()" << endmsg;
65
66 StatusCode sc = Service::initialize();
67 if ( sc.isFailure() ) return sc;
68
69 IIncidentSvc* incsvc;
70 sc = service( "IncidentSvc", incsvc );
71 int priority = 100;
72 if ( sc.isSuccess() ) { incsvc->addListener( this, "NewRun", priority ); }
73
74 sc = serviceLocator()->service( "DatabaseSvc", m_dbsvc, true );
75 if ( sc.isFailure() )
76 {
77 log << MSG::ERROR << "Unable to find DatabaseSvc " << endmsg;
78 return sc;
79 }
80
81 sc = serviceLocator()->service( "EventDataSvc", m_eventSvc, true );
82 if ( sc.isFailure() )
83 {
84 log << MSG::ERROR << "Unable to find EventDataSvc " << endmsg;
85 return sc;
86 }
87
88 return StatusCode::SUCCESS;
89}
90
92 MsgStream log( msgSvc(), name() );
93 log << MSG::INFO << "EmcShEnCalibSvc::finalize()" << endmsg;
94 // if(m_connect_offline) delete m_connect_offline;
95 return StatusCode::SUCCESS;
96}
97
98void EmcShEnCalibSvc::handle( const Incident& inc ) {
99 MsgStream log( msgSvc(), name() );
100 log << MSG::DEBUG << "handle: " << inc.type() << endmsg;
101
102 if ( inc.type() == "NewRun" )
103 {
104 log << MSG::DEBUG << "NewRun" << endmsg;
105
106 SmartDataPtr<Event::EventHeader> eventHeader( m_eventSvc, "/Event/EventHeader" );
107 int run = eventHeader->runNumber();
108 // cout<<"&&&&&&&&&&&&&&:&&&&&&&&&&&&&&&&&&&& EmcShEnCalibSvc handle,run="<<run<<endl;
109 if ( run < 0 ) run = -run;
110 log << MSG::DEBUG << "handle: "
111 << "Run in handle is: " << run << endmsg;
112 // cout<<"-------------in EmcShEnCalibSvc in the following-----------" <<endl;
113 // cout<< "handle: " <<"Run in handle is: "<<run<<endl;
114
115 if ( run >= m_RunFrom && run <= m_RunTo && m_ReadPar == true )
116 {
117 // cout<<"do not read the database repeatly in EmcShEnCalibConst"<<endl;
118 // cout<<"run,RunFrom,runTo="<<run<<","<<m_RunFrom<<","<<m_RunTo<<endl;
119 }
120 else
121 {
122
123 // cout<<"read the database in EmcShEnCalibConst"<<endl;
124 if ( !getEmcShEnCalibSvcInfo() )
125 { log << MSG::ERROR << "can not initilize Shower energy Calib Constants" << endmsg; }
126 else
127 {
128 m_ReadPar = true;
129 // std::cout << "in handle of EmcShEnCalibSvc getPi0CalibFile()= " <<
130 // getPi0CalibFile()<<std::endl; std::cout << "getSingleGammaCalibFile()= " <<
131 // getSingleGammaCalibFile() << std::endl;
132 }
133 }
134 }
135}
136
137// select sftver and parver frm table CalVtxLum
138StatusCode EmcShEnCalibSvc::getSftParVer( std::string& SftVer, std::string& CalParVer,
139 int& runfrm, int& runto, int RunNo,
140 std::string BossRelease, std::string DataType ) {
141 MsgStream log( msgSvc(), "EmcShEnCalibSvc" );
142 char stmt[300];
143 int run_No = RunNo;
144 MYSQL_RES* res_set;
147 StatusCode sc = serviceLocator()->service( "DatabaseSvc", m_dbsvc, true );
148 if ( sc.isFailure() )
149 {
150 log << MSG::ERROR << " Unable to find DatabaseSvc " << endmsg;
151 return sc;
152 }
153
154 const char* bossRelease = BossRelease.c_str();
155 const char* dataType = DataType.c_str();
156
157 sprintf( stmt,
158 "select RunFrom,RunTo,SftVer,ParVer from CalVtxLumVer where BossRelease = '%s' and "
159 "RunFrom <= %d and RunTo "
160 ">= %d and DataType='%s' ",
161 bossRelease, run_No, run_No, dataType );
162 // cout<<"stmt="<<stmt<<endl;
163
164 int row_no = m_dbsvc->query( "offlinedb", stmt, res );
165 // cout<<"raw_no="<<row_no<<endl;
166 if ( row_no < 1 )
167 {
168 std::cout << "ERROR:error searching with:" << stmt << std::endl;
169 exit( 1 );
170 }
171 if ( row_no == 1 )
172 {
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 {
184 cout << "ERROR: " << dataType << " set overlapped run number in the table CalVtxLumVer"
185 << endl;
186 exit( 1 );
187 }
188 return StatusCode::SUCCESS;
189}
190
192 MsgStream log( msgSvc(), name() );
193 SmartDataPtr<Event::EventHeader> eventHeader( m_eventSvc, "/Event/EventHeader" );
194 int run = eventHeader->runNumber();
195 // cout<<"Run in getEmcShEnCalibSvcInfo() is: "<<run<<endl;
196
197 char stmt1[400];
198 StatusCode st1;
199 // runfrm,runto are the value from the table ***CalConst;runfrm1,runto1 are the value from
200 // the table CalVtxLumVer
201 int runfrm1;
202 int runto1;
203 std::string cType;
204
205 if ( run < 0 )
206 {
207 // cout << "This data is the MC sample with the Run Number: " << run << endl;
208 run = -run;
209 }
210
211 if ( m_bossRelease == "default" ) m_bossRelease = getenv( "BES_RELEASE" );
212
213 cType = "EmcShEnCalib";
214
215 st1 = getSftParVer( m_bossVer, m_calPar, runfrm1, runto1, run, m_bossRelease, cType );
216
217 sprintf( stmt1,
218 "select RunFrom,RunTo,singleGammaCalib,pi0Calib from EmcShEnCalibConst where "
219 "SftVer = '%s' and RunFrom <= "
220 "%d and RunTo >= %d ",
221 m_bossVer.c_str(), run, run );
222
224 int row_no = m_dbsvc->query( "offlinedb", stmt1, res );
225
226 if ( row_no > 0 )
227 {
228 DatabaseRecord& dbrec = *res[row_no - 1];
229 m_SingleGammaCalibFile = dbrec.GetString( "singleGammaCalib" );
230 m_Pi0CalibFile = dbrec.GetString( "pi0Calib" );
231 m_RunFrom = dbrec.GetInt( "RunFrom" );
232 m_RunTo = dbrec.GetInt( "RunTo" );
233
234 /*
235 cout<<"BossReleaseVer="<<m_bossRelease.c_str()<<"\t"<<"EmcShEnCalibBossVer="<<m_bossVer.c_str()<<endl;
236 cout<<"m_Pi0CalibFile is:"<<m_Pi0CalibFile<<endl;
237 cout<<"m_SingleGammaCalibFile is:"<<m_SingleGammaCalibFile<<endl;
238 cout<<"m_RunFrom is:"<<m_RunFrom<<endl;
239 cout<<"m_RunTo is:"<<m_RunTo<<endl;
240 cout << "Successfully fetch EmcShEnCalibSvc information for run: " << run << endl;
241 //cout<<"////////// read parameters from EmcShEnCalibConst database/////////////"<<endl;
242 */
243 return true;
244 }
245 else if ( row_no <= 0 )
246 {
247 cout << " EmcShEnCalibSvc:: can not found EmcShEnCalibSvc information of run:" << run
248 << ", boss version " << m_bossRelease << endl;
249 exit( 1 );
250 return false;
251 }
252 return true;
253}
DECLARE_COMPONENT(BesBdkRc)
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:19
IMessageSvc * msgSvc()
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()
void handle(const Incident &)
IDatabaseSvc * m_dbsvc
virtual StatusCode initialize()