2#include "MeasuredEcmsSvc/MeasuredEcmsSvc.h"
5 declareProperty(
"RunParamsMin", RunParamsMin=11414);
6 declareProperty(
"RunParamsMax", RunParamsMax=23454);
8 declareProperty(
"MeasuredEcmsMin", MeasuredEcmsMin=23463);
9 declareProperty(
"MeasuredEcmsMax", MeasuredEcmsMax=38140);
11 declareProperty(
"TableName", table=
"RunParams");
12 declareProperty(
"ColumnName", column=
"beam_energy");
13 declareProperty(
"DownRangeColumnName", down_column=
"run_number");
14 declareProperty(
"UpRangeColumnName", up_column=
"run_number");
20 MsgStream log(
msgSvc(), name());
21 log<<MSG::INFO<<
"MeasuredEcmsSvc initialize begin here"<<endreq;
23 StatusCode status=Service::initialize();
24 if(!status.isSuccess()){
25 log<<MSG::ERROR<<
"MeasuredEcmsSvc Can not initialize"<<endreq;
30 status=service(
"IncidentSvc", incsvc);
32 if(status.isSuccess()) incsvc->addListener(
this,
"NewRun", priority);
34 status=serviceLocator()->service(
"DatabaseSvc", m_dbSvc,
true);
35 if(!status.isSuccess()){
36 log<<MSG::ERROR<<
"MeasuredEcmsSvc Unable to find DatabaseSvc"<<endreq;
40 status=serviceLocator()->service(
"EventDataSvc", m_eventSvc,
true);
41 if(!status.isSuccess()){
42 log<<MSG::ERROR<<
"MeasuredEcmsSvc Unable to find EventDataSvc "<<endreq;
46 log<<MSG::INFO<<
"MeasuredEcmsSvc initialized successfully"<<endreq;
47 return StatusCode::SUCCESS;
51 MsgStream log(
msgSvc(), name());
52 log<<MSG::INFO<<
"MeasuredEcmsSvc finalize begin here"<<endreq;
54 StatusCode status= Service::finalize();
55 if(!status.isSuccess()){
56 log<<MSG::ERROR<<
"MeasuredEcmsSvc Can not finalize"<<endreq;
60 log<<MSG::INFO<<
"MeasuredEcmsSvc finalized successfully"<<endreq;
61 return StatusCode::SUCCESS;
66 else return Service::queryInterface(riid, ppvIF);
70 return StatusCode::SUCCESS;
74 MsgStream log(messageService(), name());
75 log<<MSG::DEBUG<<
"handle: "<<inc.type()<<endreq;
77 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,
"/Event/EventHeader");
78 int runNo=eventHeader->runNumber();
79 if(inc.type()==
"NewRun"){
80 log<<MSG::INFO<<
"RunNo is new, call the readMeasuredEcms again"<<endreq;
89 MsgStream log(
msgSvc(), name());
90 log<<MSG::INFO<<
"MeasuredEcmsSvc begin read database MeasuredEcmsSvc"<<endreq;
92 int runNum=std::abs(
runNo);
94 if(
runNo<0) log<<MSG::INFO<<
"MeasuredEcmsSvc for MC events"<<endreq;
95 else log<<MSG::INFO<<
"MeasuredEcmsSvc for DT events"<<endreq;
98 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);
100 int rowNo=m_dbSvc->
query(
"offlinedb", stmt, res);
101 if(rowNo==0){ log<<MSG::ERROR<<
"RowNo can not be 0 for MeasuredEcmsSvc, failed to read DB for "<<
runNo<<endreq; }
104 log<<MSG::INFO<<
"MeasuredEcmsSvc first read the runNo, read the MeasuredEcms database "<<
runNo<<endreq;
107 m_sampleName=records->
GetDouble(
"sample");
109 m_ecmsErr=records->
GetDouble(
"Ecms_err");
110 m_aveEcms=records->
GetDouble(
"Ave_Ecms");
111 m_aveEcmsErr=records->
GetDouble(
"Ave_Ecms_err");
117 MsgStream log(
msgSvc(), name());
118 log<<MSG::INFO<<
"MeasuredEcmsSvc begin read database RunParams"<<endreq;
120 int runNum=std::abs(
runNo);
122 if(
runNo<0) log<<MSG::INFO<<
"MeasuredEcmsSvc for MC events"<<endreq;
123 else log<<MSG::INFO<<
"MeasuredEcmsSvc for DT events"<<endreq;
126 snprintf(stmt1, 1024,
"select beam_energy, px, py, pz from RunParams where run_number = %d", runNum);
128 int row_no = m_dbSvc->
query(
"offlinedb", stmt1, res);
129 if(row_no==0){log<<MSG::ERROR<<
"RowNo can not be 0 for RunParams, failed to read DB for "<<
runNo<<endreq;}
132 log<<MSG::INFO<<
"MeasuredEcmsSvc first read the runNo, read the RunParams database"<<
runNo<<endreq;
149 MsgStream log(
msgSvc(), name());
150 log<<MSG::INFO<<
"MeasuredEcmsSvc read the sample name"<<endreq;
151 if(old_runNo!=
runNo){
159 MsgStream log(
msgSvc(), name());
160 log<<MSG::INFO<<
"MeasuredEcmsSvc read the RunFrom"<<endreq;
161 if(old_runNo!=
runNo){
169 MsgStream log(
msgSvc(), name());
170 log<<MSG::INFO<<
"MeasuredEcmsSvc read the RunTo"<<endreq;
171 if(old_runNo!=
runNo){
179 MsgStream log(
msgSvc(), name());
180 log<<MSG::INFO<<
"MeasuredEcmsSvc read the error of ecms"<<endreq;
181 if(old_runNo!=
runNo){
189 MsgStream log(
msgSvc(), name());
190 log<<MSG::INFO<<
"MeasuredEcmsSvc read the average ecms"<<endreq;
191 if(old_runNo!=
runNo){
199 MsgStream log(
msgSvc(), name());
200 log<<MSG::INFO<<
"MeasuredEcmsSvc read the error of the average ecms"<<endreq;
201 if(old_runNo!=
runNo){
209 MsgStream log(
msgSvc(), name());
210 log<<MSG::INFO<<
"MeasuredEcmsSvc read the ecms"<<endreq;
211 if(old_runNo!=
runNo){
219 MsgStream log(
msgSvc(), name());
220 log<<MSG::INFO<<
"MeasuredEcmsSvc read the ecms"<<endreq;
221 if(old_runNo!=
runNo){
229 MsgStream log(
msgSvc(), name());
230 log<<MSG::INFO<<
"MeasuredEcmsSvc read the ecms"<<endreq;
231 if(old_runNo!=
runNo){
239 MsgStream log(
msgSvc(), name());
240 log<<MSG::INFO<<
"MeasuredEcmsSvc read the ecms"<<endreq;
241 if(old_runNo!=
runNo){
249 MsgStream log(
msgSvc(), name());
250 log<<MSG::INFO<<
"MeasuredEcmsSvc judge the valid of runNo"<<endreq;
251 if(old_runNo!=
runNo){
259 MsgStream log(
msgSvc(), name());
260 log<<MSG::INFO<<
"MeasuredEcmsSvc judge the valid of runNo"<<endreq;
261 if(old_runNo!=
runNo){
276 strcpy(tab, table.c_str());
277 strcpy(col, column.c_str());
278 strcpy(min_col, down_column.c_str());
279 strcpy(max_col, up_column.c_str());
281 MsgStream log(
msgSvc(), name());
282 log<<MSG::INFO<<
"MeasuredEcmsSvc begin read database "<<tab<<
"-"<<col<<endreq;
284 int runNum=std::abs(
runNo);
286 if(
runNo<0) log<<MSG::INFO<<
"MeasuredEcmsSvc for MC events"<<endreq;
287 else log<<MSG::INFO<<
"MeasuredEcmsSvc for DT events"<<endreq;
290 snprintf(stmt1, 1024,
"select %s from %s where %s <= %d and %s >= %d", col, tab, min_col, runNum, max_col, runNum);
292 int row_no = m_dbSvc->
query(
"offlinedb", stmt1, res);
293 if(row_no==0){log<<MSG::ERROR<<
"RowNo can not be 0 for "<<tab<<
", failed to read DB for "<<
runNo<<endreq;}
296 log<<MSG::INFO<<
"MeasuredEcmsSvc first read the runNo, read the "<<tab<<
" database "<<
runNo<<endreq;
305 strcpy(tab, table.c_str());
306 strcpy(col, column.c_str());
307 MsgStream log(
msgSvc(), name());
308 log<<MSG::INFO<<
"MeasuredEcmsSvc read the "<<tab<<
"-"<<col<<endreq;
309 if(old_runNo1!=
runNo){
319 strcpy(tab, table.c_str());
320 strcpy(col, column.c_str());
321 MsgStream log(
msgSvc(), name());
322 log<<MSG::INFO<<
"MeasuredEcmsSvc judge the valid of "<<tab<<
"-"<<col<<endreq;
323 if(old_runNo1!=
runNo){
327 return m_runNoValid1;
333 MsgStream log(
msgSvc(), name());
334 log<<MSG::INFO<<
"MeasuredEcmsSvc begin read database "<<tab<<
"-"<<col<<endreq;
336 int runNum=std::abs(
runNo);
338 if(
runNo<0) log<<MSG::INFO<<
"MeasuredEcmsSvc for MC events"<<endreq;
339 else log<<MSG::INFO<<
"MeasuredEcmsSvc for DT events"<<endreq;
342 snprintf(stmt1, 1024,
"select %s from %s where %s <= %d and %s >=%d", col, tab, min_col, runNum, max_col, runNum);
344 int row_no = m_dbSvc->
query(
"offlinedb", stmt1, res);
345 if(row_no==0){log<<MSG::ERROR<<
"RowNo can not be 0 for "<<tab<<
", failed to read DB for "<<
runNo<<endreq;}
348 log<<MSG::INFO<<
"MeasuredEcmsSvc first read the runNo, read the "<<tab<<
" database "<<
runNo<<endreq;
355 MsgStream log(
msgSvc(), name());
356 log<<MSG::INFO<<
"MeasuredEcmsSvc read the "<<tab<<
"-"<<col<<endreq;
357 if(old_runNo2!=
runNo){
365 MsgStream log(
msgSvc(), name());
366 log<<MSG::INFO<<
"MeasuredEcmsSvc judge the valid of "<<tab<<
"-"<<col<<endreq;
367 if(old_runNo2!=
runNo){
371 return m_runNoValid2;
382 strcpy(tab, table.c_str());
383 strcpy(col, column.c_str());
384 strcpy(min_col, down_column.c_str());
385 strcpy(max_col, up_column.c_str());
387 MsgStream log(
msgSvc(), name());
388 log<<MSG::INFO<<
"MeasuredEcmsSvc begin read database "<<tab<<
"-"<<col<<endreq;
390 int runNum=std::abs(
runNo);
392 if(
runNo<0) log<<MSG::INFO<<
"MeasuredEcmsSvc for MC events"<<endreq;
393 else log<<MSG::INFO<<
"MeasuredEcmsSvc for DT events"<<endreq;
396 snprintf(stmt1, 1024,
"select %s from %s where %s <= %d and %s >= %d", col, tab, min_col, runNum, max_col, runNum);
398 int row_no = m_dbSvc->
query(
"offlinedb", stmt1, res);
399 if(row_no==0){log<<MSG::ERROR<<
"RowNo can not be 0 for "<<tab<<
", failed to read DB for "<<
runNo<<endreq;}
402 log<<MSG::INFO<<
"MeasuredEcmsSvc first read the runNo, read the "<<tab<<
" database "<<
runNo<<endreq;
404 m_record_valid1=
true;
411 strcpy(tab, table.c_str());
412 strcpy(col, column.c_str());
413 MsgStream log(
msgSvc(), name());
414 log<<MSG::INFO<<
"MeasuredEcmsSvc read the "<<tab<<
"-"<<col<<endreq;
415 if(old_runNo3!=
runNo){
425 strcpy(tab, table.c_str());
426 strcpy(col, column.c_str());
427 MsgStream log(
msgSvc(), name());
428 log<<MSG::INFO<<
"MeasuredEcmsSvc judge the valid of "<<tab<<
"-"<<col<<endreq;
429 if(old_runNo3!=
runNo){
433 return m_record_valid1;
439 MsgStream log(
msgSvc(), name());
440 log<<MSG::INFO<<
"MeasuredEcmsSvc begin read database "<<tab<<
"-"<<col<<endreq;
442 int runNum=std::abs(
runNo);
444 if(
runNo<0) log<<MSG::INFO<<
"MeasuredEcmsSvc for MC events"<<endreq;
445 else log<<MSG::INFO<<
"MeasuredEcmsSvc for DT events"<<endreq;
448 snprintf(stmt1, 1024,
"select %s from %s where %s <= %d and %s >=%d", col, tab, min_col, runNum, max_col, runNum);
450 int row_no = m_dbSvc->
query(
"offlinedb", stmt1, res);
451 if(row_no==0){log<<MSG::ERROR<<
"RowNo can not be 0 for "<<tab<<
", failed to read DB for "<<
runNo<<endreq;}
454 log<<MSG::INFO<<
"MeasuredEcmsSvc first read the runNo, read the "<<tab<<
" database "<<
runNo<<endreq;
456 m_record_valid2=
true;
461 MsgStream log(
msgSvc(), name());
462 log<<MSG::INFO<<
"MeasuredEcmsSvc read the "<<tab<<
"-"<<col<<endreq;
463 if(old_runNo4!=
runNo){
471 MsgStream log(
msgSvc(), name());
472 log<<MSG::INFO<<
"MeasuredEcmsSvc judge the valid of "<<tab<<
"-"<<col<<endreq;
473 if(old_runNo4!=
runNo){
477 return m_record_valid2;
483 MsgStream log(
msgSvc(), name());
484 log<<MSG::INFO<<
"MeasuredEcmsSvc begin read database MeasuredEcmsSvc"<<endreq;
486 int runNum=std::abs(
runNo);
488 if(
runNo<0) log<<MSG::INFO<<
"MeasuredEcmsSvc for MC events"<<endreq;
489 else log<<MSG::INFO<<
"MeasuredEcmsSvc for DT events"<<endreq;
492 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);
494 int rowNo=m_dbSvc->
query(
"offlinedb", stmt, res);
495 if(rowNo==0){ log<<MSG::ERROR<<
"RowNo can not be 0 for MeasuredEcmsSvc, failed to read DB for "<<
runNo<<endreq; }
498 log<<MSG::INFO<<
"MeasuredEcmsSvc first read the runNo, read the MeasuredEcms database "<<
runNo<<endreq;
500 m_runFrom2=records->
GetDouble(
"RunFrom");
502 m_sampleName2=records->
GetDouble(
"sample");
504 m_ecmsErr2=records->
GetDouble(
"Ecms_err");
505 m_aveEcms2=records->
GetDouble(
"Ave_Ecms");
506 m_aveEcmsErr2=records->
GetDouble(
"Ave_Ecms_err");
512 MsgStream log(
msgSvc(), name());
513 log<<MSG::INFO<<
"MeasuredEcmsSvc begin read database RunParams"<<endreq;
515 int runNum=std::abs(
runNo);
517 if(
runNo<0) log<<MSG::INFO<<
"MeasuredEcmsSvc for MC events"<<endreq;
518 else log<<MSG::INFO<<
"MeasuredEcmsSvc for DT events"<<endreq;
521 snprintf(stmt1, 1024,
"select beam_energy, px, py, pz from RunParams where run_number = %d", runNum);
523 int row_no = m_dbSvc->
query(
"offlinedb", stmt1, res);
524 if(row_no==0){log<<MSG::ERROR<<
"RowNo can not be 0 for RunParams, failed to read DB for "<<
runNo<<endreq;}
527 log<<MSG::INFO<<
"MeasuredEcmsSvc first read the runNo, read the RunParams database"<<
runNo<<endreq;
double GetDouble(std::string key)
std::string GetString(std::string key)
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0
static const InterfaceID & interfaceID()
std::string getRecord(int runNo, char *tab, char *col, char *min_col, char *max_col)
void readMeasuredEcms2(int runNo)
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvIF)
void readRunParams2(int runNo)
void readRunParams(int runNo)
bool isGetRecordValid(int runNo, char *tab, char *col, char *min_col, char *max_col)
virtual ~MeasuredEcmsSvc()
void handle(const Incident &)
virtual StatusCode initialize()
MeasuredEcmsSvc(const std::string &name, ISvcLocator *svcLoc)
double getInfo(int runNo, char *tab, char *col, char *min_col, char *max_col)
virtual StatusCode finalize()
void readRecord(int runNo, char *tab, char *col, char *min_col, char *max_col)
void readInfo(int runNo, char *tab, char *col, char *min_col, char *max_col)
void readMeasuredEcms(int runNo)
bool isGetInfoValid(int runNo, char *tab, char *col, char *min_col, char *max_col)