BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EmcSatuDeadEnSvc.cxx
Go to the documentation of this file.
1// This service is used to read the EmcSatuDeadEnSvc information from the database
2//
3// the joboption for this service is shown in share/jobOptions_EmcSatuDeadEnSvc.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#include <TMath.h>
24
25#include "EventModel/Event.h"
26#include "EventModel/EventHeader.h"
27#include "EventModel/EventModel.h"
28
29#include "EmcSatuDeadEnSvc.h"
30
31using namespace std;
32
34
35EmcSatuDeadEnSvc::EmcSatuDeadEnSvc( const string& name, ISvcLocator* svcloc )
36 : base_class( name, svcloc ) {
37 // declare properties
38 declareProperty( "Host", host = std::string( "bes3db2.ihep.ac.cn" ) );
39 declareProperty( "DbName", dbName = std::string( "offlinedb" ) );
40 declareProperty( "UserName", userName = std::string( "guest" ) );
41 declareProperty( "Password", password = std::string( "guestpass" ) );
42 declareProperty( "BossRelease", m_bossRelease = std::string( "default" ) );
43 declareProperty( "EmcSatuDeadEnPar", m_calPar = "default" );
44 declareProperty( "EmcSatuDeadEnBossVer", m_bossVer = "default" );
45 m_ReadPar = false;
46 m_RunFrom = 0;
47 m_RunTo = 0;
48}
49
51
53 MsgStream log( msgSvc(), name() );
54 log << MSG::INFO << "EmcSatuDeadEnSvc::initialize()" << endmsg;
55
56 StatusCode sc = Service::initialize();
57 if ( sc.isFailure() ) return sc;
58
59 IIncidentSvc* incsvc;
60 sc = service( "IncidentSvc", incsvc );
61 int priority = 100;
62 if ( sc.isSuccess() ) { incsvc->addListener( this, "NewRun", priority ); }
63
64 sc = serviceLocator()->service( "DatabaseSvc", m_dbsvc, true );
65 if ( sc.isFailure() )
66 {
67 log << MSG::ERROR << "Unable to find DatabaseSvc " << endmsg;
68 return sc;
69 }
70
71 sc = serviceLocator()->service( "EventDataSvc", m_eventSvc, true );
72 if ( sc.isFailure() )
73 {
74 log << MSG::ERROR << "Unable to find EventDataSvc " << endmsg;
75 return sc;
76 }
77
78 return StatusCode::SUCCESS;
79}
80
82 MsgStream log( msgSvc(), name() );
83 log << MSG::INFO << "EmcSatuDeadEnSvc::finalize()" << endmsg;
84
85 return StatusCode::SUCCESS;
86}
87
88void EmcSatuDeadEnSvc::handle( const Incident& inc ) {
89 MsgStream log( msgSvc(), name() );
90 log << MSG::DEBUG << "handle: " << inc.type() << endmsg;
91
92 /*
93 if ( inc.type() == "NewRun" ){
94 log << MSG::DEBUG << "NewRun" << endmsg;
95
96 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,"/Event/EventHeader");
97 int run = eventHeader->runNumber();
98 //cout<<"&&&&&&&&&&&&&&:&&&&&&&&&&&&&&&&&&&& EmcSatuDeadEnSvc handle,run="<<run<<endl;
99 if (run<0) run = -run;
100 log << MSG::DEBUG << "handle: " <<"Run in handle is: "<<run<< endmsg;
101 log << MSG::DEBUG << "-------------in EmcSatuDeadEnSvc in the following-----------"
102 <<endmsg; log << MSG::DEBUG << "handle: " <<"Run in handle is: "<<run<<endmsg;
103
104 if (run>=m_RunFrom&&run<=m_RunTo&&m_ReadPar==true){
105 log << MSG::DEBUG << "do not read the database repeatly in EmcSatuDeadEn"<<endmsg;
106 log << MSG::DEBUG << "run,RunFrom,runTo="<<run<<","<<m_RunFrom<<","<<m_RunTo <<endmsg;
107 } else {
108
109 log << MSG::DEBUG << "read the database in EmcSatuDeadEn" <<endmsg;
110 if(!getEmcSatuDeadEnSvcInfo()){
111 log << MSG::ERROR << "can not get EmcSatuDeadEnSvc" << endmsg;
112 } else {
113 m_ReadPar=true;
114 log << MSG::DEBUG << "in handle of EmcSatuDeadEnSvc getSatuEnFile()= " <<
115 getSatuEnFile()<<std::endmsg; log << MSG::DEBUG << "getDeadEnFile()= " << getDeadEnFile() <<
116 std::endmsg;
117 }
118
119 }
120 } // NewRun
121 */
122}
123
124// select sftver and parver frm table CalVtxLum
125StatusCode EmcSatuDeadEnSvc::getSftParVer( std::string& SftVer, std::string& CalParVer,
126 int& runfrm, int& runto, int RunNo,
127 std::string BossRelease, std::string DataType ) {
128 MsgStream log( msgSvc(), "EmcSatuDeadEnSvc" );
129 char stmt[300];
130 int run_No = RunNo;
131
134 StatusCode sc = serviceLocator()->service( "DatabaseSvc", m_dbsvc, true );
135 if ( sc.isFailure() )
136 {
137 log << MSG::ERROR << " Unable to find DatabaseSvc " << endmsg;
138 return sc;
139 }
140
141 const char* bossRelease = BossRelease.c_str();
142 const char* dataType = DataType.c_str();
143
144 sprintf( stmt,
145 "select RunFrom,RunTo,SftVer,ParVer from CalVtxLumVer where BossRelease = '%s' and "
146 "RunFrom <= %d and RunTo >= %d and DataType='%s' ",
147 bossRelease, run_No, run_No, dataType );
148 log << MSG::DEBUG << "stmt=" << stmt << endmsg;
149
150 int row_no = m_dbsvc->query( "offlinedb", stmt, res );
151 // cout<<"raw_no="<<row_no<<endl;
152 if ( row_no < 1 )
153 {
154 log << MSG::ERROR << "error searching with:" << stmt << endmsg;
155 exit( 1 );
156 }
157 if ( row_no == 1 )
158 {
159 DatabaseRecord* records1 = res[0];
160 runfrm = records1->GetInt( "RunFrom" );
161 runto = records1->GetInt( "RunTo" );
162 log << MSG::DEBUG << dataType << " runfrm,runto in getSftParVer is:" << runfrm
163 << "::::" << runto << endmsg;
164
165 SftVer = records1->GetString( "SftVer" );
166 CalParVer = records1->GetString( "ParVer" );
167 log << MSG::DEBUG << "stmt=" << stmt << "\t" << SftVer << "\t" << CalParVer << endmsg;
168 }
169 if ( row_no > 1 )
170 {
171 log << MSG::ERROR << "ERROR: " << dataType
172 << " set overlapped run number in the table CalVtxLumVer" << endmsg;
173 exit( 1 );
174 }
175 return StatusCode::SUCCESS;
176}
177
179 MsgStream log( msgSvc(), name() );
180 SmartDataPtr<Event::EventHeader> eventHeader( m_eventSvc, "/Event/EventHeader" );
181 int run = eventHeader->runNumber();
182 log << MSG::DEBUG << "Run in getEmcSatuDeadEnSvcInfo() is: " << run << endmsg;
183
184 char stmt1[400];
185 StatusCode st1;
186 // runfrm,runto are the value from the table ***CalConst;runfrm1,runto1 are the value from
187 // the table CalVtxLumVer
188 int runfrm1;
189 int runto1;
190 std::string cType;
191
192 if ( run < 0 )
193 {
194 log << MSG::DEBUG << "This data is the MC sample with the Run Number: " << run << endmsg;
195 run = -run;
196 }
197
198 // if(m_bossRelease=="default") m_bossRelease = getenv("BES_RELEASE");
199
200 if ( m_bossRelease == "default" )
201 {
202 log << MSG::FATAL << " Boss Release for EmcSatuDeadEnSvc not set!" << endmsg;
203 exit( 1 );
204 }
205 else
206 {
207
208 cType = "EmcSatuDeadEn";
209
210 st1 = getSftParVer( m_bossVer, m_calPar, runfrm1, runto1, run, m_bossRelease, cType );
211
212 sprintf( stmt1,
213 "select RunFrom,RunTo,EmcSatuEn,EmcDeadEn from EmcSatuDeadEn where SftVer = "
214 "'%s' and RunFrom <= %d and "
215 "RunTo >= %d ",
216 m_bossVer.c_str(), run, run );
217 }
218
220 int row_no = m_dbsvc->query( "offlinedb", stmt1, res );
221
222 if ( row_no > 0 )
223 {
224 DatabaseRecord& dbrec = *res[row_no - 1];
225 m_SatuEnFile = dbrec.GetString( "EmcSatuEn" );
226 m_DeadEnFile = dbrec.GetString( "EmcDeadEn" );
227 m_RunFrom = dbrec.GetInt( "RunFrom" );
228 m_RunTo = dbrec.GetInt( "RunTo" );
229
230 log << MSG::DEBUG << "BossReleaseVer=" << m_bossRelease.c_str() << "\t"
231 << "EmcSatuDeadEnBossVer=" << m_bossVer.c_str() << endmsg;
232 log << MSG::DEBUG << "m_SatuEnFile is:" << m_SatuEnFile << endmsg;
233 log << MSG::DEBUG << "m_DeadEnFile is:" << m_DeadEnFile << endmsg;
234 log << MSG::DEBUG << "m_RunFrom is:" << m_RunFrom << endmsg;
235 log << MSG::DEBUG << "m_RunTo is:" << m_RunTo << endmsg;
236 log << MSG::DEBUG << "Successfully fetch EmcSatuDeadEnSvc information for run: " << run
237 << endmsg;
238
239 return true;
240 }
241 else if ( row_no <= 0 )
242 {
243 cout << " EmcSatuDeadEnSvc:: can not found EmcSatuDeadEnSvc information of run:" << run
244 << ", boss version " << m_bossRelease << endl;
245 exit( 1 );
246 return false;
247 }
248 return true;
249}
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()
void handle(const Incident &)
virtual StatusCode finalize()
IDatabaseSvc * m_dbsvc
virtual StatusCode initialize()
StatusCode getSftParVer(std::string &SftVer, std::string &CalParVer, int &runfrm, int &runto, int RunNo, std::string BossRelease, std::string DataType)
EmcSatuDeadEnSvc(const std::string &name, ISvcLocator *svcloc)