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);
9 declareProperty(
"TableName", table=
"RunParams");
10 declareProperty(
"ColumnName", column=
"beam_energy");
16 MsgStream log(
msgSvc(), name());
17 log<<MSG::INFO<<
"MeasuredEcmsSvc initialize begin here"<<endreq;
18 StatusCode status=Service::initialize();
19 if(!status.isSuccess()){
20 log<<MSG::ERROR<<
"MeasuredEcmsSvc Can not initialize"<<endreq;
24 status=service(
"IncidentSvc", incsvc);
26 if(status.isSuccess()) incsvc->addListener(
this,
"NewRun", priority);
27 status=serviceLocator()->service(
"DatabaseSvc", m_dbSvc,
true);
28 if(!status.isSuccess()){
29 log<<MSG::ERROR<<
"MeasuredEcmsSvc Unable to find DatabaseSvc"<<endreq;
32 status=serviceLocator()->service(
"EventDataSvc", m_eventSvc,
true);
33 if(!status.isSuccess()){
34 log<<MSG::ERROR<<
"MeasuredEcmsSvc Unable to find EventDataSvc "<<endreq;
37 log<<MSG::INFO<<
"MeasuredEcmsSvc initialized successfully"<<endreq;
38 return StatusCode::SUCCESS;
42 MsgStream log(
msgSvc(), name());
43 log<<MSG::INFO<<
"MeasuredEcmsSvc finalize begin here"<<endreq;
44 StatusCode status= Service::finalize();
45 if(!status.isSuccess()){
46 log<<MSG::ERROR<<
"MeasuredEcmsSvc Can not finalize"<<endreq;
49 log<<MSG::INFO<<
"MeasuredEcmsSvc finalized successfully"<<endreq;
50 return StatusCode::SUCCESS;
55 else return Service::queryInterface(riid, ppvIF);
57 return StatusCode::SUCCESS;
61 MsgStream log(messageService(), name());
62 log<<MSG::DEBUG<<
"handle: "<<inc.type()<<endreq;
63 m_callRead=
false; m_recallRead=
true;
64 if(inc.type()==
"NewRun"){
65 log<<MSG::INFO<<
"RunNo is new, call the readMeasuredEcms again"<<endreq;
67 m_sampleName=0; m_ecms=0; m_ecmsErr=0;
68 m_aveEcms=0; m_aveEcmsErr=0; m_runFrom=0;
69 m_runTo=0; m_runNoValid=
false;
70 m_px=0; m_py=0; m_pz=0;
76 MsgStream log(
msgSvc(), name());
77 log<<MSG::INFO<<
"MeasuredEcmsSvc begin read database MeasuredEcmsSvc"<<endreq;
78 int runNum=std::abs(
runNo);
79 if(
runNo<0) log<<MSG::INFO<<
"MeasuredEcmsSvc for MC events"<<endreq;
80 else log<<MSG::INFO<<
"MeasuredEcmsSvc for DT events"<<endreq;
82 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);
84 int rowNo=m_dbSvc->
query(
"offlinedb", stmt, res);
85 if(rowNo==0){ log<<MSG::ERROR<<
"RowNo can not be 0 for MeasuredEcmsSvc, failed to read DB"<<endreq; }
88 log<<MSG::INFO<<
"MeasuredEcmsSvc first read the runNo, read the MeasuredEcms database"<<
runNo<<endreq;
91 m_sampleName=records->
GetDouble(
"sample");
95 m_aveEcmsErr=records->
GetDouble(
"Ave_Ecms_err");
101 MsgStream log(
msgSvc(), name());
102 log<<MSG::INFO<<
"MeasuredEcmsSvc begin read database RunParams"<<endreq;
103 int runNum=std::abs(
runNo);
104 if(
runNo<0) log<<MSG::INFO<<
"MeasuredEcmsSvc for MC events"<<endreq;
105 else log<<MSG::INFO<<
"MeasuredEcmsSvc for DT events"<<endreq;
107 snprintf(stmt1, 1024,
"select beam_energy, px, py, pz from RunParams where run_number = %d", runNum);
109 int row_no = m_dbSvc->
query(
"offlinedb", stmt1, res);
110 if(row_no==0){log<<MSG::ERROR<<
"RowNo can not be 0 for RunParams, failed to read DB"<<endreq;}
113 log<<MSG::INFO<<
"MeasuredEcmsSvc first read the runNo, read the RunParams database"<<
runNo<<endreq;
125 MsgStream log(
msgSvc(), name());
126 log<<MSG::INFO<<
"MeasuredEcmsSvc begin read database "<<tab<<
"-"<<col<<endreq;
127 int runNum=std::abs(
runNo);
128 if(
runNo<0) log<<MSG::INFO<<
"MeasuredEcmsSvc for MC events"<<endreq;
129 else log<<MSG::INFO<<
"MeasuredEcmsSvc for DT events"<<endreq;
131 snprintf(stmt1, 1024,
"select %s from %s where run_number = %d", col, tab, runNum);
133 int row_no = m_dbSvc->
query(
"offlinedb", stmt1, res);
134 if(row_no==0){log<<MSG::ERROR<<
"RowNo can not be 0 for "<<tab<<
", failed to read DB"<<endreq;}
137 log<<MSG::INFO<<
"MeasuredEcmsSvc first read the runNo, read the "<<tab<<
" database "<<
runNo<<endreq;
146 strcpy(tab, table.c_str());
147 strcpy(col, column.c_str());
148 MsgStream log(
msgSvc(), name());
149 log<<MSG::INFO<<
"MeasuredEcmsSvc begin read database "<<tab<<
"-"<<col<<endreq;
150 int runNum=std::abs(
runNo);
151 if(
runNo<0) log<<MSG::INFO<<
"MeasuredEcmsSvc for MC events"<<endreq;
152 else log<<MSG::INFO<<
"MeasuredEcmsSvc for DT events"<<endreq;
154 snprintf(stmt1, 1024,
"select %s from %s where run_number = %d", col, tab, runNum);
156 int row_no = m_dbSvc->
query(
"offlinedb", stmt1, res);
157 if(row_no==0){log<<MSG::ERROR<<
"RowNo can not be 0 for "<<tab<<
", failed to read DB"<<endreq;}
160 log<<MSG::INFO<<
"MeasuredEcmsSvc first read the runNo, read the "<<tab<<
" database "<<
runNo<<endreq;
172 MsgStream log(
msgSvc(), name());
173 log<<MSG::INFO<<
"MeasuredEcmsSvc read the "<<tab<<
"-"<<col<<endreq;
174 if(m_recallRead&&m_callRead){
183 strcpy(tab, table.c_str());
184 strcpy(col, column.c_str());
185 MsgStream log(
msgSvc(), name());
186 log<<MSG::INFO<<
"MeasuredEcmsSvc read the "<<tab<<
"-"<<col<<endreq;
187 if(m_recallRead&&m_callRead){
194 MsgStream log(
msgSvc(), name());
195 log<<MSG::INFO<<
"MeasuredEcmsSvc read the sample name"<<endreq;
196 if(m_recallRead&&m_callRead){
204 MsgStream log(
msgSvc(), name());
205 log<<MSG::INFO<<
"MeasuredEcmsSvc read the RunFrom"<<endreq;
206 if(m_recallRead&&m_callRead){
214 MsgStream log(
msgSvc(), name());
215 log<<MSG::INFO<<
"MeasuredEcmsSvc read the RunTo"<<endreq;
216 if(m_recallRead&&m_callRead){
224 MsgStream log(
msgSvc(), name());
225 log<<MSG::INFO<<
"MeasuredEcmsSvc read the ecms"<<endreq;
226 if(m_recallRead&&m_callRead){
234 MsgStream log(
msgSvc(), name());
235 log<<MSG::INFO<<
"MeasuredEcmsSvc read the ecms"<<endreq;
236 if(m_recallRead&&m_callRead){
245 MsgStream log(
msgSvc(), name());
246 log<<MSG::INFO<<
"MeasuredEcmsSvc read the ecms"<<endreq;
247 if(m_recallRead&&m_callRead){
255 MsgStream log(
msgSvc(), name());
256 log<<MSG::INFO<<
"MeasuredEcmsSvc read the ecms"<<endreq;
257 if(m_recallRead&&m_callRead){
265 MsgStream log(
msgSvc(), name());
266 log<<MSG::INFO<<
"MeasuredEcmsSvc read the error of ecms"<<endreq;
267 if(m_recallRead&&m_callRead){
275 MsgStream log(
msgSvc(), name());
276 log<<MSG::INFO<<
"MeasuredEcmsSvc read the average ecms"<<endreq;
277 if(m_recallRead&&m_callRead){
285 MsgStream log(
msgSvc(), name());
286 log<<MSG::INFO<<
"MeasuredEcmsSvc read the error of the average ecms"<<endreq;
287 if(m_recallRead&&m_callRead){
295 MsgStream log(
msgSvc(), name());
296 log<<MSG::INFO<<
"MeasuredEcmsSvc judge the valid of "<<tab<<
"-"<<col<<endreq;
307 strcpy(tab, table.c_str());
308 strcpy(col, column.c_str());
309 MsgStream log(
msgSvc(), name());
310 log<<MSG::INFO<<
"MeasuredEcmsSvc judge the valid of "<<tab<<
"-"<<col<<endreq;
319 MsgStream log(
msgSvc(), name());
320 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 getInfo(int runNo, char *tab, char *col)
double getEcms(int runNo)
virtual ~MeasuredEcmsSvc()
void handle(const Incident &)
virtual StatusCode initialize()
void readInfo(int runNo, char *tab, char *col)
bool isReadDBValid(int runNo, char *tab, char *col)
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)