BOSS 8.0.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#include <cstdio>
10#include <cstdlib>
11#include <cstring>
12#include <iostream>
13#include <sstream>
14
15#include "GaudiKernel/IDataProviderSvc.h"
16#include "GaudiKernel/IInterface.h"
17#include "GaudiKernel/ISvcLocator.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 "ScanEnergySvc.h"
24
25#include "GaudiKernel/IIncidentListener.h"
26#include "GaudiKernel/IIncidentSvc.h"
27#include "GaudiKernel/Incident.h"
28
29#include "EventModel/Event.h"
30#include "EventModel/EventHeader.h"
31#include "EventModel/EventModel.h"
32#include "GaudiKernel/Bootstrap.h"
33#include "GaudiKernel/ISvcLocator.h"
34
35#include <TMath.h>
36
37using namespace std;
38
40ScanEnergySvc::ScanEnergySvc( 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 // m_dbsvc = DatabaseSvc::instance();
48}
49
51
52/*StatusCode ScanEnergySvc::queryInterface(const InterfaceID& riid, void** ppvInterface){
53 if( IID_IScanEnergySvc.versionMatch(riid) ){
54 *ppvInterface = static_cast<IScanEnergySvc*> (this);
55 } else{
56 return Service::queryInterface(riid, ppvInterface);
57 }
58 return StatusCode::SUCCESS;
59}
60*/
62 MsgStream log( msgSvc(), name() );
63 log << MSG::INFO << "ScanEnergySvc::initialize()" << endmsg;
64
65 StatusCode sc = Service::initialize();
66 if ( sc.isFailure() ) return sc;
67
68 IIncidentSvc* incsvc;
69 sc = service( "IncidentSvc", incsvc );
70 int priority = 100;
71 if ( sc.isSuccess() ) { incsvc->addListener( this, "NewRun", priority ); }
72
73 sc = serviceLocator()->service( "DatabaseSvc", m_dbsvc, true );
74 if ( sc.isFailure() )
75 {
76 log << MSG::ERROR << "Unable to find DatabaseSvc " << endmsg;
77 return sc;
78 }
79
80 sc = serviceLocator()->service( "EventDataSvc", m_eventSvc, true );
81 if ( sc.isFailure() )
82 {
83 log << MSG::ERROR << "Unable to find EventDataSvc " << endmsg;
84 return sc;
85 }
86
87 return StatusCode::SUCCESS;
88}
89
91 MsgStream log( msgSvc(), name() );
92 log << MSG::INFO << "ScanEnergySvc::finalize()" << endmsg;
93 // if(m_connect_offline) delete m_connect_offline;
94 return StatusCode::SUCCESS;
95}
96
97void ScanEnergySvc::handle( const Incident& inc ) {
98 MsgStream log( msgSvc(), name() );
99 log << MSG::DEBUG << "handle: " << inc.type() << endmsg;
100
101 if ( inc.type() == "NewRun" )
102 {
103 log << MSG::DEBUG << "NewRun" << endmsg;
104 if ( !getScanEnergySvcInfo() )
105 { log << MSG::ERROR << "can not initilize Tof energy Calib Constants" << endmsg; }
106 }
107}
108
110 MsgStream log( msgSvc(), name() );
111 SmartDataPtr<Event::EventHeader> eventHeader( m_eventSvc, "/Event/EventHeader" );
112 int run = eventHeader->runNumber();
113
114 if ( run >= 55054 && run <= 55859 )
115 {
116
117 cout << "Run in getScanEnergySvcInfo() is: " << run << endl;
118
119 char stmt1[400];
120 if ( run < 0 )
121 {
122 cout << "This data is the MC sample with the Run Number: " << run << endl;
123 run = -run;
124 }
125
126 sprintf(
127 stmt1,
128 "select runStart,runEnd,Energy from ScanEnergy where runStart <= %d and runEnd >= %d ",
129 run, run );
130 cout << "stmt is:" << stmt1 << endl;
132 int row_no = m_dbsvc->query( "offlinedb", stmt1, res );
133 if ( row_no > 0 )
134 {
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
140 << " m_RunEnd is:" << m_RunEnd << endl;
141 cout << "Successfully fetch ScanEnergySvc information for run: " << run << endl;
142 return true;
143 }
144 else if ( row_no <= 0 )
145 {
146 cout << " ScanEnergySvc:: can not found ScanEnergySvc information of run:" << run
147 << endl;
148 exit( 1 );
149 return false;
150 }
151 }
152
153 return true;
154}
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)
IMessageSvc * msgSvc()
bool getScanEnergySvcInfo()
virtual StatusCode initialize()
virtual StatusCode finalize()
ScanEnergySvc(const std::string &name, ISvcLocator *svcloc)
IDatabaseSvc * m_dbsvc
void handle(const Incident &)