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