2#include "MeasuredEcmsSvc/MeasuredEcmsSvc.h"
5 declareProperty(
"RunParamsMin", RunParamsMin=11414);
6 declareProperty(
"RunParamsMax", RunParamsMax=23454);
7 declareProperty(
"MeasuredEcmsMin", MeasuredEcmsMin=23463);
8 declareProperty(
"MeasuredEcmsMax", MeasuredEcmsMax=38140);
14 MsgStream log(
msgSvc(), name());
15 log<<MSG::INFO<<
"MeasuredEcmsSvc initialize begin here"<<endreq;
16 StatusCode status=Service::initialize();
17 if(!status.isSuccess()){
18 log<<MSG::ERROR<<
"MeasuredEcmsSvc Can not initialize"<<endreq;
22 status=service(
"IncidentSvc", incsvc);
24 if(status.isSuccess()) incsvc->addListener(
this,
"NewRun", priority);
25 status=serviceLocator()->service(
"DatabaseSvc", m_dbSvc,
true);
26 if(!status.isSuccess()){
27 log<<MSG::ERROR<<
"MeasuredEcmsSvc Unable to find DatabaseSvc"<<endreq;
30 status=serviceLocator()->service(
"EventDataSvc", m_eventSvc,
true);
31 if(!status.isSuccess()){
32 log<<MSG::ERROR<<
"MeasuredEcmsSvc Unable to find EventDataSvc "<<endreq;
35 log<<MSG::INFO<<
"MeasuredEcmsSvc initialized successfully"<<endreq;
36 return StatusCode::SUCCESS;
40 MsgStream log(
msgSvc(), name());
41 log<<MSG::INFO<<
"MeasuredEcmsSvc finalize begin here"<<endreq;
42 StatusCode status= Service::finalize();
43 if(!status.isSuccess()){
44 log<<MSG::ERROR<<
"MeasuredEcmsSvc Can not finalize"<<endreq;
47 log<<MSG::INFO<<
"MeasuredEcmsSvc finalized successfully"<<endreq;
48 return StatusCode::SUCCESS;
53 else return Service::queryInterface(riid, ppvIF);
55 return StatusCode::SUCCESS;
59 MsgStream log(messageService(), name());
60 log<<MSG::DEBUG<<
"handle: "<<inc.type()<<endreq;
61 m_callRead=
false; m_recallRead=
true;
62 if(inc.type()==
"NewRun"){
63 log<<MSG::INFO<<
"RunNo is new, call the readMeasuredEcms again"<<endreq;
69 MsgStream log(
msgSvc(), name());
70 log<<MSG::INFO<<
"MeasuredEcmsSvc begin read database MeasuredEcmsSvc"<<endreq;
71 m_sampleName=0; m_ecms=0; m_ecmsErr=0;
72 m_aveEcms=0; m_aveEcmsErr=0; m_runFrom=0;
73 m_runTo=0; m_runNoValid=
false;
74 m_px=0; m_py=0; m_pz=0;
75 int runNum=std::abs(
runNo);
76 if(
runNo<0) log<<MSG::INFO<<
"MeasuredEcmsSvc for MC events"<<endreq;
77 else log<<MSG::INFO<<
"MeasuredEcmsSvc for DT events"<<endreq;
79 snprintf(stmt, 1024,
"select sample, RunFrom, RunTo, Ecms, Ecms_err, Ave_Ecms, Ave_Ecms_err from MeasuredEcms2 where RunFrom <= %d and RunTo >= %d", runNum, runNum);
81 int rowNo=m_dbSvc->
query(
"offlinedb", stmt, res);
82 if(rowNo==0){ log<<MSG::ERROR<<
"RowNo can not be 0 for MeasuredEcmsSvc, failed to read DB"<<endreq; }
85 log<<MSG::INFO<<
"MeasuredEcmsSvc first read the runNo, read the MeasuredEcms database"<<
runNo<<endreq;
88 m_sampleName=records->
GetDouble(
"sample");
92 m_aveEcmsErr=records->
GetDouble(
"Ave_Ecms_err");
98 MsgStream log(
msgSvc(), name());
99 log<<MSG::INFO<<
"MeasuredEcmsSvc begin read database RunParams"<<endreq;
100 m_sampleName=0; m_ecms=0; m_ecmsErr=0;
101 m_aveEcms=0; m_aveEcmsErr=0; m_runFrom=0;
102 m_runTo=0; m_runNoValid=
false;
103 m_px=0; m_py=0; m_pz=0;
104 int runNum=std::abs(
runNo);
105 if(
runNo<0) log<<MSG::INFO<<
"MeasuredEcmsSvc for MC events"<<endreq;
106 else log<<MSG::INFO<<
"MeasuredEcmsSvc for DT events"<<endreq;
108 snprintf(stmt1, 1024,
"select beam_energy, px, py, pz from RunParams where run_number = %d", runNum);
110 int row_no = m_dbSvc->
query(
"offlinedb", stmt1, res);
111 if(row_no==0){log<<MSG::ERROR<<
"RowNo can not be 0 for RunParams, failed to read DB"<<endreq;}
114 log<<MSG::INFO<<
"MeasuredEcmsSvc first read the runNo, read the RunParams database"<<
runNo<<endreq;
131 MsgStream log(
msgSvc(), name());
132 log<<MSG::INFO<<
"MeasuredEcmsSvc read the sample name"<<endreq;
133 if(m_recallRead&&m_callRead){
141 MsgStream log(
msgSvc(), name());
142 log<<MSG::INFO<<
"MeasuredEcmsSvc read the RunFrom"<<endreq;
143 if(m_recallRead&&m_callRead){
151 MsgStream log(
msgSvc(), name());
152 log<<MSG::INFO<<
"MeasuredEcmsSvc read the RunTo"<<endreq;
153 if(m_recallRead&&m_callRead){
161 MsgStream log(
msgSvc(), name());
162 log<<MSG::INFO<<
"MeasuredEcmsSvc read the ecms"<<endreq;
163 if(m_recallRead&&m_callRead){
171 MsgStream log(
msgSvc(), name());
172 log<<MSG::INFO<<
"MeasuredEcmsSvc read the error of ecms"<<endreq;
173 if(m_recallRead&&m_callRead){
181 MsgStream log(
msgSvc(), name());
182 log<<MSG::INFO<<
"MeasuredEcmsSvc read the average ecms"<<endreq;
183 if(m_recallRead&&m_callRead){
191 MsgStream log(
msgSvc(), name());
192 log<<MSG::INFO<<
"MeasuredEcmsSvc read the error of the average ecms"<<endreq;
193 if(m_recallRead&&m_callRead){
201 MsgStream log(
msgSvc(), name());
202 log<<MSG::INFO<<
"MeasuredEcmsSvc judge the valid of runNo"<<endreq;
double GetDouble(std::string key)
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0
static const InterfaceID & interfaceID()
double getEcmsErr(int runNo)
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvIF)
void readRunParams(int runNo)
int getRunFrom(int runNo)
int getSampleName(int runNo)
double getEcms(int runNo)
virtual ~MeasuredEcmsSvc()
void handle(const Incident &)
virtual StatusCode initialize()
bool isRunNoValid(int runNo)
MeasuredEcmsSvc(const std::string &name, ISvcLocator *svcLoc)
double getAveEcmsErr(int runNo)
virtual StatusCode finalize()
double getAveEcms(int runNo)
void readMeasuredEcms(int runNo)