BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
ScanEnergySvc.cxx
Go to the documentation of this file.
1// This service is used to read the ScanEnergySvc information from the database
2//
3// an example to use this service is shown in test/test_read.cxx
4//
5// the joboption for the example is shown in share/job-test.txt
6//
7// the joboption for this service is shown in share/jobOptions_ScanEnergySvc.txt
8
9
10#include <iostream>
11#include <sstream>
12#include <cstring>
13#include <cstdlib>
14#include <cstdio>
15
17#include "GaudiKernel/Kernel.h"
18#include "GaudiKernel/IInterface.h"
19#include "GaudiKernel/StatusCode.h"
20#include "GaudiKernel/SvcFactory.h"
21#include "GaudiKernel/MsgStream.h"
22#include "GaudiKernel/ISvcLocator.h"
23#include "GaudiKernel/SmartDataPtr.h"
24#include "GaudiKernel/IDataProviderSvc.h"
25#include "GaudiKernel/PropertyMgr.h"
26
27
28#include "GaudiKernel/IIncidentSvc.h"
29#include "GaudiKernel/Incident.h"
30#include "GaudiKernel/IIncidentListener.h"
31
32#include "GaudiKernel/ISvcLocator.h"
33#include "GaudiKernel/Bootstrap.h"
35#include "EventModel/Event.h"
37
38#include <TMath.h>
39
40using namespace std;
41
42DECLARE_COMPONENT(ScanEnergySvc)
43ScanEnergySvc::ScanEnergySvc( const string& name, ISvcLocator* svcloc) :
44 base_class (name, svcloc){
45 // declare properties
46 declareProperty("Host" , host = std::string("bes3db2.ihep.ac.cn"));
47 declareProperty("DbName" , dbName = std::string("offlinedb"));
48 declareProperty("UserName" , userName = std::string("guest"));
49 declareProperty("Password" , password = std::string("guestpass"));
50 // m_dbsvc = DatabaseSvc::instance();
51 }
52
54}
55
56/*StatusCode ScanEnergySvc::queryInterface(const InterfaceID& riid, void** ppvInterface){
57 if( IID_IScanEnergySvc.versionMatch(riid) ){
58 *ppvInterface = static_cast<IScanEnergySvc*> (this);
59 } else{
60 return Service::queryInterface(riid, ppvInterface);
61 }
62 return StatusCode::SUCCESS;
63}
64*/
66 MsgStream log(messageService(), name());
67 log << MSG::INFO << "ScanEnergySvc::initialize()" << endreq;
68
69 StatusCode sc = Service::initialize();
70 if( sc.isFailure() ) return sc;
71
72
73 IIncidentSvc* incsvc;
74 sc = service("IncidentSvc", incsvc);
75 int priority = 100;
76 if( sc.isSuccess() ){
77 incsvc -> addListener(this, "NewRun", priority);
78 }
79
80 sc = serviceLocator()->service("DatabaseSvc",m_dbsvc,true);
81 if (sc .isFailure() ) {
82 log << MSG::ERROR << "Unable to find DatabaseSvc " << endreq;
83 return sc;
84 }
85
86 sc = serviceLocator()->service("EventDataSvc", m_eventSvc, true);
87 if (sc .isFailure() ) {
88 log << MSG::ERROR << "Unable to find EventDataSvc " << endreq;
89 return sc;
90 }
91
92 return StatusCode::SUCCESS;
93}
94
96 MsgStream log(messageService(), name());
97 log << MSG::INFO << "ScanEnergySvc::finalize()" << endreq;
98 // if(m_connect_offline) delete m_connect_offline;
99 return StatusCode::SUCCESS;
100}
101
102void ScanEnergySvc::handle(const Incident& inc){
103 MsgStream log( messageService(), name() );
104 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
105
106 if ( inc.type() == "NewRun" ){
107 log << MSG::DEBUG << "NewRun" << endreq;
109 log << MSG::ERROR << "can not initilize Tof energy Calib Constants" << endreq;
110 }
111 }
112}
113
114
116 MsgStream log(messageService(), name());
117 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,"/Event/EventHeader");
118 int run = eventHeader->runNumber();
119
120 if (run>=55054&&run<=55859){
121
122 cout<<"Run in getScanEnergySvcInfo() is: "<<run<<endl;
123
124 char stmt1[400];
125 if(run<0) {
126 cout << "This data is the MC sample with the Run Number: " << run << endl;
127 run = -run;
128 }
129
130 sprintf(stmt1, "select runStart,runEnd,Energy from ScanEnergy where runStart <= %d and runEnd >= %d ", run, run);
131 cout<<"stmt is:"<<stmt1<<endl;
133 int row_no = m_dbsvc->query("offlinedb",stmt1,res);
134 if( row_no > 0 ) {
135 DatabaseRecord& dbrec = *res[row_no-1];
136 m_ScanEnergy = dbrec.GetDouble("Energy");
137 m_RunStart =dbrec.GetInt("runStart");
138 m_RunEnd =dbrec.GetInt("runEnd");
139 cout<<"m_ScanEnergy is:"<<m_ScanEnergy<<" m_RunStart is:"<<m_RunStart<<" m_RunEnd is:"<<m_RunEnd<<endl;
140 cout << "Successfully fetch ScanEnergySvc information for run: "
141 << run << endl;
142 return true;
143 } else if( row_no<=0 ) {
144 cout << " ScanEnergySvc:: can not found ScanEnergySvc information of run:"
145 << run << endl;
146 exit(1);
147 return false;
148 }
149 }
150
151 return true;
152}
153
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)
double GetDouble(std::string key)
int GetInt(std::string key)
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0
bool getScanEnergySvcInfo()
virtual StatusCode initialize()
virtual StatusCode finalize()
IDatabaseSvc * m_dbsvc
Definition: ScanEnergySvc.h:40
void handle(const Incident &)