BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EmcShEnCalibSvc Class Reference

#include <EmcShEnCalibSvc.h>

Inheritance diagram for EmcShEnCalibSvc:

Public Member Functions

 EmcShEnCalibSvc (const std::string &name, ISvcLocator *svcloc)
 ~EmcShEnCalibSvc ()
virtual StatusCode initialize ()
virtual StatusCode finalize ()
void handle (const Incident &)
void SetBossRelease (const std::string &_bossrelease)
std::string GetBossRelease () const
StatusCode getSftParVer (std::string &SftVer, std::string &CalParVer, int &runfrm, int &runto, int RunNo, std::string BossRelease, std::string DataType)
bool getEmcShEnCalibSvcInfo ()
std::string getPi0CalibFile () const
std::string getSingleGammaCalibFile () const
unsigned int getRunFrom () const
unsigned int getRunTo () const

Public Attributes

IDatabaseSvcm_dbsvc

Detailed Description

Definition at line 20 of file EmcShEnCalibSvc.h.

Constructor & Destructor Documentation

◆ EmcShEnCalibSvc()

EmcShEnCalibSvc::EmcShEnCalibSvc ( const std::string & name,
ISvcLocator * svcloc )

Definition at line 36 of file EmcShEnCalibSvc.cxx.

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}

Referenced by EmcShEnCalibSvc().

◆ ~EmcShEnCalibSvc()

EmcShEnCalibSvc::~EmcShEnCalibSvc ( )

Definition at line 51 of file EmcShEnCalibSvc.cxx.

51{}

Member Function Documentation

◆ finalize()

StatusCode EmcShEnCalibSvc::finalize ( )
virtual

Definition at line 91 of file EmcShEnCalibSvc.cxx.

91 {
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}
IMessageSvc * msgSvc()

◆ GetBossRelease()

std::string EmcShEnCalibSvc::GetBossRelease ( ) const
inline

Definition at line 36 of file EmcShEnCalibSvc.h.

36{ return m_bossRelease; }

◆ getEmcShEnCalibSvcInfo()

bool EmcShEnCalibSvc::getEmcShEnCalibSvcInfo ( )

Definition at line 191 of file EmcShEnCalibSvc.cxx.

191 {
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
223 DatabaseRecordVector res;
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}
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)
StatusCode getSftParVer(std::string &SftVer, std::string &CalParVer, int &runfrm, int &runto, int RunNo, std::string BossRelease, std::string DataType)
IDatabaseSvc * m_dbsvc

Referenced by handle().

◆ getPi0CalibFile()

std::string EmcShEnCalibSvc::getPi0CalibFile ( ) const
inline

Definition at line 45 of file EmcShEnCalibSvc.h.

45{ return m_Pi0CalibFile; }

◆ getRunFrom()

unsigned int EmcShEnCalibSvc::getRunFrom ( ) const
inline

Definition at line 47 of file EmcShEnCalibSvc.h.

47{ return m_RunFrom; }

◆ getRunTo()

unsigned int EmcShEnCalibSvc::getRunTo ( ) const
inline

Definition at line 48 of file EmcShEnCalibSvc.h.

48{ return m_RunTo; }

◆ getSftParVer()

StatusCode EmcShEnCalibSvc::getSftParVer ( std::string & SftVer,
std::string & CalParVer,
int & runfrm,
int & runto,
int RunNo,
std::string BossRelease,
std::string DataType )

Definition at line 138 of file EmcShEnCalibSvc.cxx.

140 {
141 MsgStream log( msgSvc(), "EmcShEnCalibSvc" );
142 char stmt[300];
143 int run_No = RunNo;
144 MYSQL_RES* res_set;
145 IDatabaseSvc* m_dbsvc;
146 DatabaseRecordVector res;
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}
char * SftVer
Definition DQA_TO_DB.cxx:19

Referenced by getEmcShEnCalibSvcInfo().

◆ getSingleGammaCalibFile()

std::string EmcShEnCalibSvc::getSingleGammaCalibFile ( ) const
inline

Definition at line 46 of file EmcShEnCalibSvc.h.

46{ return m_SingleGammaCalibFile; }

◆ handle()

void EmcShEnCalibSvc::handle ( const Incident & inc)

Definition at line 98 of file EmcShEnCalibSvc.cxx.

98 {
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}

◆ initialize()

StatusCode EmcShEnCalibSvc::initialize ( )
virtual

Definition at line 62 of file EmcShEnCalibSvc.cxx.

62 {
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}

◆ SetBossRelease()

void EmcShEnCalibSvc::SetBossRelease ( const std::string & _bossrelease)
inline

Definition at line 35 of file EmcShEnCalibSvc.h.

35{ m_bossRelease = _bossrelease; }

Member Data Documentation

◆ m_dbsvc

IDatabaseSvc* EmcShEnCalibSvc::m_dbsvc

Definition at line 33 of file EmcShEnCalibSvc.h.

Referenced by getEmcShEnCalibSvcInfo(), getSftParVer(), and initialize().


The documentation for this class was generated from the following files: