2#include "GaudiKernel/Kernel.h"
3#include "GaudiKernel/IInterface.h"
4#include "GaudiKernel/IIncidentSvc.h"
5#include "GaudiKernel/Incident.h"
6#include "GaudiKernel/IIncidentListener.h"
7#include "GaudiKernel/StatusCode.h"
8#include "GaudiKernel/SvcFactory.h"
9#include "GaudiKernel/MsgStream.h"
10#include "GaudiKernel/IDataProviderSvc.h"
11#include "GaudiKernel/SmartDataPtr.h"
12#include "GaudiKernel/DataSvc.h"
14#include "CLHEP/Random/RandGauss.h"
24 Service (name, svcloc) {
26 declareProperty(
"RunIDList", m_runNoList);
27 declareProperty(
"IfUseDB", m_useDB =
true);
28 declareProperty(
"IfReadBunch", m_ifReadBunch =
true);
29 declareProperty(
"IfUseTrg", m_ifReadTrg =
false);
30 declareProperty(
"IfReadRanTrg", m_ifReadRandTrg =
false);
31 declareProperty(
"IfReadTFEE", m_ifReadTFEE =
false);
32 declareProperty(
"IfReadRunInfo", m_ifReadRunInfo =
false);
33 declareProperty(
"BossRelease", m_bossRelease=
"default");
34 declareProperty(
"SftVer", m_SftVer =
"default");
35 declareProperty(
"ParVer", m_ParVer =
"default");
36 declareProperty(
"InitEvtID", m_initEvtID = 0);
40 MsgStream log(messageService(), name());
41 log << MSG::INFO <<
"RealizationSvc::initialize()" << endreq;
43 StatusCode sc = Service::initialize();
44 if( sc.isFailure() )
return sc;
46 if(m_SftVer ==
"NONE") m_SftVer = getenv(
"BES_RELEASE");
48 for(
unsigned int i = 0; i < m_runNoList.size(); i++) {
49 if(m_runNoList[i] != 0) {
50 std::cout <<
"run id : " << m_runNoList[i] << std::endl;
51 if(find(m_runIdList.begin(),m_runIdList.end(),m_runNoList[i]) == m_runIdList.end()) m_runIdList.push_back(m_runNoList[i]);
52 else log << MSG::ALWAYS <<
"RunNo "<<m_runNoList[i]<<
" repeated in run list"<<endreq;
55 if(i == 0 || (i+1) >= m_runNoList.size()) log << MSG::ERROR <<
"Please check your run id list, it is wrong" << endreq;
56 if(m_runNoList[i+1] < m_runNoList[i-1]) {
57 for(
int j = m_runNoList[i+1]+1; j < m_runNoList[i-1]; j++) {
58 if(find(m_runIdList.begin(),m_runIdList.end(),j) == m_runIdList.end()) m_runIdList.push_back(j);
59 else log << MSG::ALWAYS <<
"RunNo "<<j<<
" repeated in run list"<<endreq;
63 for(
int j = m_runNoList[i-1]+1; j < m_runNoList[i+1]; j++) {
64 if(find(m_runIdList.begin(),m_runIdList.end(),j) == m_runIdList.end()) m_runIdList.push_back(j);
65 else log << MSG::ALWAYS <<
"RunNo "<<j<<
" repeated in run list"<<endreq;
70 m_runID = m_runIdList[0];
74 log << MSG::ERROR <<
"Could not open connection to database" << endreq;
78 sc = service(
"IncidentSvc", incsvc);
81 incsvc -> addListener(
this,
"NewRun", priority);
84 sc = serviceLocator()->service(
"EventDataSvc", m_eventSvc,
true);
85 if (sc.isFailure() ) {
86 log << MSG::ERROR <<
"Unable to find EventDataSvc " << endreq;
90 return StatusCode::SUCCESS;
94 MsgStream log(messageService(), name());
95 log << MSG::INFO <<
"RealizationSvc::finalize()" << endreq;
97 return StatusCode::SUCCESS;
105 return Service::queryInterface(riid, ppvInterface);
108 return StatusCode::SUCCESS;
112 MsgStream log( messageService(), name() );
113 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
114 if ( inc.type() ==
"NewRun" ){
115 log << MSG::DEBUG <<
"Begin New Run" << endreq;
116 if(m_useDB ==
true) {
118 SmartDataPtr<Event::EventHeader> evt(m_eventSvc,
"/Event/EventHeader");
120 runNo = evt -> runNumber();
121 log << MSG::INFO <<
"The runNumber of current event is "<<
runNo<<endreq;
124 log << MSG::ERROR <<
"Can not get EventHeader!"<<endreq;
134 MsgStream log( messageService(), name() );
136 ConnectionProvider::eRet e = m_connect->
getReadLumInfo(sLum,
runNo, m_SftVer, m_ParVer, m_bossRelease);
138 log << MSG::ERROR <<
"Could not find Luminosity infor., exit." << endreq;
141 m_lumi = std::atof(sLum.c_str());
142 log << MSG::INFO <<
"Luminosity is " << m_lumi <<
" in Run " <<
runNo << endreq;
147 MsgStream log( messageService(), name() );
150 std::vector<std::string> Bgfilename;
153 std::vector<std::string> fileInfor;
156 log << MSG::ERROR <<
"Could not find background infor., exit." << endreq;
160 for(
unsigned int i = 0; i < fileInfor.size(); i+=2)
162 Bgfilename.push_back(fileInfor[i]+
"/"+fileInfor[i+1]);
166 for(
unsigned int i = 0; i < Bgfilename.size(); i++) {
167 log << MSG::INFO <<
"Background file name: " << Bgfilename[i] << endreq;
243 MsgStream log( messageService(), name() );
244 log << MSG::DEBUG <<
"In getCaliConst" << endreq;
251 if(m_ifReadBunch ==
true) {
252 std::vector<std::string> sbunch;
253 std::vector<double> bunchInfo;
254 ConnectionProvider::eRet e = m_connect->
getReadBunchInfo(sbunch,
runNo,m_SftVer,m_ParVer,m_bossRelease);
257 for(
int id = 1;
true;
id++) {
267 if(last ==
true) log << MSG::INFO <<
"Use Bunch infor. of run " <<
runNo+
id <<
" instead of run " <<
runNo << endreq;
268 if(last ==
false) log << MSG::INFO <<
"Use Bunch infor. of run " <<
runNo-
id <<
" instead of run " <<
runNo << endreq;
273 if(e != 0 && e != 7) {
274 log << MSG::ERROR <<
"Could not find Bunch infor., exit." << endreq;
277 for(
unsigned int i = 0; i < sbunch.size(); i++)
279 bunchInfo.push_back(atof(sbunch[i].c_str()));
283 if(bunchInfo.size() == 6)
286 m_bunch_x = 10*bunchInfo[0];
287 m_bunch_y = 10*bunchInfo[1];
288 m_bunch_z = 10*bunchInfo[2];
289 m_sigma_x = 10*bunchInfo[3];
290 m_sigma_y = 10*bunchInfo[4];
291 m_sigma_z = 10*bunchInfo[5];
292 log << MSG::INFO <<
"BunchPosX: " << m_bunch_x <<
" BunchPosY: " << m_bunch_y <<
" BunchPosZ: " << m_bunch_z <<
" in Run " <<
runNo << endreq;
293 log << MSG::INFO <<
"BunchSigmaX: " << m_sigma_x <<
" BunchSigmaY: " << m_sigma_y <<
" BunchSigmaZ: " << m_sigma_z <<
" in Run " <<
runNo << endreq;
296 log << MSG::ERROR <<
"Please check the bunch information, the size is " << bunchInfo.size() << endreq;
302 if(m_ifReadTrg ==
true) {
304 std::vector<std::string> strgTable;
307 log << MSG::ERROR <<
"Could not find TrgTable infor., exit." << endreq;
310 for(
unsigned int i = 0; i < strgTable.size(); i++)
313 for (
unsigned int j = 0; j < (strgTable[i]).
length(); j++)
315 value = value*10 + (strgTable[i][j] -
'0');
317 m_trgTable.push_back(uint32_t(value));
320 if(m_trgTable.size() != 65) log << MSG::ERROR <<
"Please check the TrgTable information, the size is " << m_trgTable.size() << endreq;
322 std::vector<double> vtrgGain;
325 log << MSG::ERROR <<
"Could not find emc gain infor., exit." << endreq;
328 for(
unsigned int i = 0; i < vtrgGain.size(); i++) {
329 m_trgGain[i] = vtrgGain[i];
335 log << MSG::ERROR <<
"Could not find Trigger config infor., exit." << endreq;
352 if(m_ifReadRandTrg ==
true) {
353 std::vector<std::string> fileInfor;
357 for(
int id = 1;
true;
id++) {
367 if(last ==
true) log << MSG::INFO <<
"Use Bg files of run " <<
runNo+
id <<
" instead of run " <<
runNo << endreq;
368 if(last ==
false) log << MSG::INFO <<
"Use Bg files of run " <<
runNo-
id <<
" instead of run " <<
runNo << endreq;
373 if(e != 0 && e != 7) {
374 log << MSG::ERROR <<
"Could not find background infor., exit." << endreq;
377 m_bgfilename.clear();
378 for(
unsigned int i = 0; i < fileInfor.size(); i+=2)
380 m_bgfilename.push_back(fileInfor[i]+
"/"+fileInfor[i+1]);
383 for(
unsigned int i = 0; i < m_bgfilename.size(); i++) {
384 log << MSG::INFO <<
"Background file name: " << m_bgfilename[i] <<
" in run " <<
runNo << endreq;
388 std::string srunTime;
389 std::string stau_value;
390 e = m_connect->
getLumCurvePar(srunTime, stau_value,
runNo, m_SftVer, m_ParVer, m_bossRelease);
392 log << MSG::ERROR <<
"Could not find Luminosity curve parameters, exit." << endreq;
395 m_runTotalTime = std::atof(srunTime.c_str());
396 m_tauValue = std::atof(stau_value.c_str());
397 log << MSG::INFO <<
"Total time is " << m_runTotalTime <<
", tau is " << m_tauValue <<
" in run " <<
runNo <<
". " << endreq;
401 if(m_ifReadTFEE ==
true) {
405 log << MSG::ERROR <<
"Could not find TFEE infor., exit." << endreq;
409 for(
unsigned int i = 0; i < m_tfee.size(); i++) {
410 log << MSG::INFO <<
"TFEE ----> " << m_tfee[i] << endreq;
415 if(m_ifReadRunInfo ==
true) {
417 std::vector<std::string> srunInfo;
420 log << MSG::ERROR <<
"Could not find run infor., exit." << endreq;
423 for(
unsigned int i = 0; i < srunInfo.size(); i++)
425 m_runInfo.push_back(atof(srunInfo[i].c_str()));
429 for(
unsigned int i = 0; i < m_runInfo.size(); i++) {
430 log << MSG::INFO <<
"runInfo ----> " << m_runInfo[i] << endreq;
static const InterfaceID & interfaceID()
ConnectionProvider::eRet getRunInfo(std::vector< std::string > &runInfo, int runNo)
ConnectionProvider::eRet getReadBunchInfo(std::vector< std::string > &bunch, int runNo, std::string SftVer, std::string ParVer, std::string BossRelease)
ConnectionProvider::eRet getLumCurvePar(std::string &runTotalTime, std::string &tau_value, int runNo, std::string SftVer, std::string ParVer, std::string BossRelease)
ConnectionProvider::eRet getTrgConfigInfo(int runNo)
ConnectionProvider::eRet getReadLumInfo(std::string &Lum, int runNo, std::string SftVer, std::string ParVer, std::string BossRelease)
ConnectionProvider::eRet getEmcGain(std::vector< double > &emcGain, int runNo)
ConnectionProvider::eRet getReadTrgTableInfo(std::vector< std::string > &trgTable, int runNo)
ConnectionProvider::eRet getReadBackgroundInfo(std::vector< std::string > &fileInfor, int runNo)
ConnectionProvider::eRet getReadTofThreshInfo(std::vector< std::string > &tofThresh, int runNo)
RealizationSvc(const std::string &name, ISvcLocator *svcloc)
virtual StatusCode finalize()
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
virtual StatusCode initialize()
std::vector< std::string > getBgFileName()
void handle(const Incident &)