BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
MeasuredEcmsSvc.cxx
Go to the documentation of this file.
1//<[email protected]> 2015.11.28 Modified
2#include "MeasuredEcmsSvc/MeasuredEcmsSvc.h"
3using namespace std;
4MeasuredEcmsSvc::MeasuredEcmsSvc(const std::string& name, ISvcLocator* svcLoc):Service(name, svcLoc){
5 declareProperty("RunParamsMin", RunParamsMin=11414);
6 declareProperty("RunParamsMax", RunParamsMax=23454);
7
8 declareProperty("MeasuredEcmsMin", MeasuredEcmsMin=23463);
9 declareProperty("MeasuredEcmsMax", MeasuredEcmsMax=38140);
10
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");
15}
16
18
20 MsgStream log(msgSvc(), name());
21 log<<MSG::INFO<<"MeasuredEcmsSvc initialize begin here"<<endreq;
22
23 StatusCode status=Service::initialize();
24 if(!status.isSuccess()){
25 log<<MSG::ERROR<<"MeasuredEcmsSvc Can not initialize"<<endreq;
26 return status;
27 }
28
29 IIncidentSvc* incsvc;
30 status=service("IncidentSvc", incsvc);
31 int priority = 100;
32 if(status.isSuccess()) incsvc->addListener(this, "NewRun", priority);
33
34 status=serviceLocator()->service("DatabaseSvc", m_dbSvc, true);
35 if(!status.isSuccess()){
36 log<<MSG::ERROR<<"MeasuredEcmsSvc Unable to find DatabaseSvc"<<endreq;
37 return status;
38 }
39
40 status=serviceLocator()->service("EventDataSvc", m_eventSvc, true);
41 if(!status.isSuccess()){
42 log<<MSG::ERROR<<"MeasuredEcmsSvc Unable to find EventDataSvc "<<endreq;
43 return status;
44 }
45
46 log<<MSG::INFO<<"MeasuredEcmsSvc initialized successfully"<<endreq;
47 return StatusCode::SUCCESS;
48}
49
51 MsgStream log(msgSvc(), name());
52 log<<MSG::INFO<<"MeasuredEcmsSvc finalize begin here"<<endreq;
53
54 StatusCode status= Service::finalize();
55 if(!status.isSuccess()){
56 log<<MSG::ERROR<<"MeasuredEcmsSvc Can not finalize"<<endreq;
57 return status;
58 }
59
60 log<<MSG::INFO<<"MeasuredEcmsSvc finalized successfully"<<endreq;
61 return StatusCode::SUCCESS;
62}
63
64StatusCode MeasuredEcmsSvc::queryInterface(const InterfaceID& riid, void** ppvIF){
65 if(IMeasuredEcmsSvc::interfaceID().versionMatch(riid)) *ppvIF = dynamic_cast<IMeasuredEcmsSvc*>(this);
66 else return Service::queryInterface(riid, ppvIF);
67
68 addRef();
69
70 return StatusCode::SUCCESS;
71}
72
73void MeasuredEcmsSvc::handle(const Incident& inc){
74 MsgStream log(messageService(), name());
75 log<<MSG::DEBUG<<"handle: "<<inc.type()<<endreq;
76
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;
81 if(std::abs(runNo)>=RunParamsMin&&std::abs(runNo)<=RunParamsMax) readRunParams2(runNo);
82 if(std::abs(runNo)>=MeasuredEcmsMin&&std::abs(runNo)<=MeasuredEcmsMax) readMeasuredEcms2(runNo);
83 }
84}
85
86//================================
87//================================
89 MsgStream log(msgSvc(), name());
90 log<<MSG::INFO<<"MeasuredEcmsSvc begin read database MeasuredEcmsSvc"<<endreq;
91
92 int runNum=std::abs(runNo);
93
94 if(runNo<0) log<<MSG::INFO<<"MeasuredEcmsSvc for MC events"<<endreq;
95 else log<<MSG::INFO<<"MeasuredEcmsSvc for DT events"<<endreq;
96
97 char stmt[400];
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; }
102 else{
103 DatabaseRecord* records=res[0];
104 log<<MSG::INFO<<"MeasuredEcmsSvc first read the runNo, read the MeasuredEcms database "<<runNo<<endreq;
105 m_runFrom=records->GetDouble("RunFrom");
106 m_runTo=records->GetDouble("RunTo");
107 m_sampleName=records->GetDouble("sample");
108 m_ecms=records->GetDouble("Ecms");
109 m_ecmsErr=records->GetDouble("Ecms_err");
110 m_aveEcms=records->GetDouble("Ave_Ecms");
111 m_aveEcmsErr=records->GetDouble("Ave_Ecms_err");
112 m_runNoValid=true;
113 }
114}
115
117 MsgStream log(msgSvc(), name());
118 log<<MSG::INFO<<"MeasuredEcmsSvc begin read database RunParams"<<endreq;
119
120 int runNum=std::abs(runNo);
121
122 if(runNo<0) log<<MSG::INFO<<"MeasuredEcmsSvc for MC events"<<endreq;
123 else log<<MSG::INFO<<"MeasuredEcmsSvc for DT events"<<endreq;
124
125 char stmt1[400];
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;}
130 else{
131 DatabaseRecord* records = res[0];
132 log<<MSG::INFO<<"MeasuredEcmsSvc first read the runNo, read the RunParams database"<<runNo<<endreq;
133 double bE=0;
134 bE=records->GetDouble("beam_energy");
135 m_px=records->GetDouble("px");
136 m_py=records->GetDouble("py");
137 m_pz=records->GetDouble("pz");
138 m_ecms=bE*2.00;
139 m_runNoValid=true;
140 }
141}
142
144 if(std::abs(runNo)>=RunParamsMin&&std::abs(runNo)<=RunParamsMax) readRunParams(runNo);
145 if(std::abs(runNo)>=MeasuredEcmsMin&&std::abs(runNo)<=MeasuredEcmsMax) readMeasuredEcms(runNo);
146}
147
149 MsgStream log(msgSvc(), name());
150 log<<MSG::INFO<<"MeasuredEcmsSvc read the sample name"<<endreq;
151 if(old_runNo!=runNo){
152 readDB(runNo);
153 old_runNo=runNo;
154 }
155 return m_sampleName;
156}
157
159 MsgStream log(msgSvc(), name());
160 log<<MSG::INFO<<"MeasuredEcmsSvc read the RunFrom"<<endreq;
161 if(old_runNo!=runNo){
162 readDB(runNo);
163 old_runNo=runNo;
164 }
165 return m_runFrom;
166}
167
169 MsgStream log(msgSvc(), name());
170 log<<MSG::INFO<<"MeasuredEcmsSvc read the RunTo"<<endreq;
171 if(old_runNo!=runNo){
172 readDB(runNo);
173 old_runNo=runNo;
174 }
175 return m_runTo;
176}
177
179 MsgStream log(msgSvc(), name());
180 log<<MSG::INFO<<"MeasuredEcmsSvc read the error of ecms"<<endreq;
181 if(old_runNo!=runNo){
182 readDB(runNo);
183 old_runNo=runNo;
184 }
185 return m_ecmsErr;
186}
187
189 MsgStream log(msgSvc(), name());
190 log<<MSG::INFO<<"MeasuredEcmsSvc read the average ecms"<<endreq;
191 if(old_runNo!=runNo){
192 readDB(runNo);
193 old_runNo=runNo;
194 }
195 return m_aveEcms;
196}
197
199 MsgStream log(msgSvc(), name());
200 log<<MSG::INFO<<"MeasuredEcmsSvc read the error of the average ecms"<<endreq;
201 if(old_runNo!=runNo){
202 readDB(runNo);
203 old_runNo=runNo;
204 }
205 return m_aveEcmsErr;
206}
207
209 MsgStream log(msgSvc(), name());
210 log<<MSG::INFO<<"MeasuredEcmsSvc read the ecms"<<endreq;
211 if(old_runNo!=runNo){
212 readDB(runNo);
213 old_runNo=runNo;
214 }
215 return m_ecms;
216}
217
219 MsgStream log(msgSvc(), name());
220 log<<MSG::INFO<<"MeasuredEcmsSvc read the ecms"<<endreq;
221 if(old_runNo!=runNo){
222 readDB(runNo);
223 old_runNo=runNo;
224 }
225 return m_px;
226}
227
229 MsgStream log(msgSvc(), name());
230 log<<MSG::INFO<<"MeasuredEcmsSvc read the ecms"<<endreq;
231 if(old_runNo!=runNo){
232 readDB(runNo);
233 old_runNo=runNo;
234 }
235 return m_py;
236}
237
239 MsgStream log(msgSvc(), name());
240 log<<MSG::INFO<<"MeasuredEcmsSvc read the ecms"<<endreq;
241 if(old_runNo!=runNo){
242 readDB(runNo);
243 old_runNo=runNo;
244 }
245 return m_pz;
246}
247
249 MsgStream log(msgSvc(), name());
250 log<<MSG::INFO<<"MeasuredEcmsSvc judge the valid of runNo"<<endreq;
251 if(old_runNo!=runNo){
252 readDB(runNo);
253 old_runNo=runNo;
254 }
255 return m_runNoValid;
256}
257
259 MsgStream log(msgSvc(), name());
260 log<<MSG::INFO<<"MeasuredEcmsSvc judge the valid of runNo"<<endreq;
261 if(old_runNo!=runNo){
262 readDB(runNo);
263 old_runNo=runNo;
264 }
265 return m_runNoValid;
266}
267
268//=====================================
269//=====================================
271 char tab[100];
272 char col[100];
273 char min_col[100];
274 char max_col[100];
275
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());
280
281 MsgStream log(msgSvc(), name());
282 log<<MSG::INFO<<"MeasuredEcmsSvc begin read database "<<tab<<"-"<<col<<endreq;
283
284 int runNum=std::abs(runNo);
285
286 if(runNo<0) log<<MSG::INFO<<"MeasuredEcmsSvc for MC events"<<endreq;
287 else log<<MSG::INFO<<"MeasuredEcmsSvc for DT events"<<endreq;
288
289 char stmt1[500];
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;}
294 else{
295 DatabaseRecord* records = res[0];
296 log<<MSG::INFO<<"MeasuredEcmsSvc first read the runNo, read the "<<tab<<" database "<<runNo<<endreq;
297 m_info1=records->GetDouble(col);
298 m_runNoValid1=true;
299 }
300}
301
303 char tab[100];
304 char col[100];
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){
311 old_runNo1=runNo;
312 }
313 return m_info1;
314}
315
317 char tab[100];
318 char col[100];
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){
325 old_runNo1=runNo;
326 }
327 return m_runNoValid1;
328}
329
330//==========================================
331//==========================================
332void MeasuredEcmsSvc::readInfo(int runNo, char *tab, char *col, char *min_col, char *max_col){
333 MsgStream log(msgSvc(), name());
334 log<<MSG::INFO<<"MeasuredEcmsSvc begin read database "<<tab<<"-"<<col<<endreq;
335
336 int runNum=std::abs(runNo);
337
338 if(runNo<0) log<<MSG::INFO<<"MeasuredEcmsSvc for MC events"<<endreq;
339 else log<<MSG::INFO<<"MeasuredEcmsSvc for DT events"<<endreq;
340
341 char stmt1[400];
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;}
346 else{
347 DatabaseRecord* records = res[0];
348 log<<MSG::INFO<<"MeasuredEcmsSvc first read the runNo, read the "<<tab<<" database "<<runNo<<endreq;
349 m_info2=records->GetDouble(col);
350 m_runNoValid2=true;
351 }
352}
353
354double MeasuredEcmsSvc::getInfo(int runNo, char *tab, char *col, char *min_col, char *max_col){
355 MsgStream log(msgSvc(), name());
356 log<<MSG::INFO<<"MeasuredEcmsSvc read the "<<tab<<"-"<<col<<endreq;
357 if(old_runNo2!=runNo){
358 readInfo(runNo, tab, col, min_col, max_col);
359 old_runNo2=runNo;
360 }
361 return m_info2;
362}
363
364bool MeasuredEcmsSvc::isGetInfoValid(int runNo, char *tab, char *col, char *min_col, char *max_col){
365 MsgStream log(msgSvc(), name());
366 log<<MSG::INFO<<"MeasuredEcmsSvc judge the valid of "<<tab<<"-"<<col<<endreq;
367 if(old_runNo2!=runNo){
368 readInfo(runNo, tab, col, min_col, max_col);
369 old_runNo2=runNo;
370 }
371 return m_runNoValid2;
372}
373
374//=====================================
375//=====================================
377 char tab[100];
378 char col[100];
379 char min_col[100];
380 char max_col[100];
381
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());
386
387 MsgStream log(msgSvc(), name());
388 log<<MSG::INFO<<"MeasuredEcmsSvc begin read database "<<tab<<"-"<<col<<endreq;
389
390 int runNum=std::abs(runNo);
391
392 if(runNo<0) log<<MSG::INFO<<"MeasuredEcmsSvc for MC events"<<endreq;
393 else log<<MSG::INFO<<"MeasuredEcmsSvc for DT events"<<endreq;
394
395 char stmt1[500];
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;}
400 else{
401 DatabaseRecord* records = res[0];
402 log<<MSG::INFO<<"MeasuredEcmsSvc first read the runNo, read the "<<tab<<" database "<<runNo<<endreq;
403 m_record1=records->GetString(col);
404 m_record_valid1=true;
405 }
406}
407
409 char tab[100];
410 char col[100];
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){
417 old_runNo3=runNo;
418 }
419 return m_record1;
420}
421
423 char tab[100];
424 char col[100];
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){
431 old_runNo3=runNo;
432 }
433 return m_record_valid1;
434}
435
436//==========================================
437//==========================================
438void MeasuredEcmsSvc::readRecord(int runNo, char *tab, char *col, char *min_col, char *max_col){
439 MsgStream log(msgSvc(), name());
440 log<<MSG::INFO<<"MeasuredEcmsSvc begin read database "<<tab<<"-"<<col<<endreq;
441
442 int runNum=std::abs(runNo);
443
444 if(runNo<0) log<<MSG::INFO<<"MeasuredEcmsSvc for MC events"<<endreq;
445 else log<<MSG::INFO<<"MeasuredEcmsSvc for DT events"<<endreq;
446
447 char stmt1[400];
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;}
452 else{
453 DatabaseRecord* records = res[0];
454 log<<MSG::INFO<<"MeasuredEcmsSvc first read the runNo, read the "<<tab<<" database "<<runNo<<endreq;
455 m_record2=records->GetString(col);
456 m_record_valid2=true;
457 }
458}
459
460string MeasuredEcmsSvc::getRecord(int runNo, char *tab, char *col, char *min_col, char *max_col){
461 MsgStream log(msgSvc(), name());
462 log<<MSG::INFO<<"MeasuredEcmsSvc read the "<<tab<<"-"<<col<<endreq;
463 if(old_runNo4!=runNo){
464 readRecord(runNo, tab, col, min_col, max_col);
465 old_runNo4=runNo;
466 }
467 return m_record2;
468}
469
470bool MeasuredEcmsSvc::isGetRecordValid(int runNo, char *tab, char *col, char *min_col, char *max_col){
471 MsgStream log(msgSvc(), name());
472 log<<MSG::INFO<<"MeasuredEcmsSvc judge the valid of "<<tab<<"-"<<col<<endreq;
473 if(old_runNo4!=runNo){
474 readRecord(runNo, tab, col, min_col, max_col);
475 old_runNo4=runNo;
476 }
477 return m_record_valid2;
478}
479
480//=============================================
481//=============================================
483 MsgStream log(msgSvc(), name());
484 log<<MSG::INFO<<"MeasuredEcmsSvc begin read database MeasuredEcmsSvc"<<endreq;
485
486 int runNum=std::abs(runNo);
487
488 if(runNo<0) log<<MSG::INFO<<"MeasuredEcmsSvc for MC events"<<endreq;
489 else log<<MSG::INFO<<"MeasuredEcmsSvc for DT events"<<endreq;
490
491 char stmt[400];
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; }
496 else{
497 DatabaseRecord* records=res[0];
498 log<<MSG::INFO<<"MeasuredEcmsSvc first read the runNo, read the MeasuredEcms database "<<runNo<<endreq;
499
500 m_runFrom2=records->GetDouble("RunFrom");
501 m_runTo2=records->GetDouble("RunTo");
502 m_sampleName2=records->GetDouble("sample");
503 m_ecms2=records->GetDouble("Ecms");
504 m_ecmsErr2=records->GetDouble("Ecms_err");
505 m_aveEcms2=records->GetDouble("Ave_Ecms");
506 m_aveEcmsErr2=records->GetDouble("Ave_Ecms_err");
507 m2_runNoValid=true;
508 }
509}
510
512 MsgStream log(msgSvc(), name());
513 log<<MSG::INFO<<"MeasuredEcmsSvc begin read database RunParams"<<endreq;
514
515 int runNum=std::abs(runNo);
516
517 if(runNo<0) log<<MSG::INFO<<"MeasuredEcmsSvc for MC events"<<endreq;
518 else log<<MSG::INFO<<"MeasuredEcmsSvc for DT events"<<endreq;
519
520 char stmt1[400];
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;}
525 else{
526 DatabaseRecord* records = res[0];
527 log<<MSG::INFO<<"MeasuredEcmsSvc first read the runNo, read the RunParams database"<<runNo<<endreq;
528 double bE=0;
529 bE=records->GetDouble("beam_energy");
530
531 m_px2=records->GetDouble("px");
532 m_py2=records->GetDouble("py");
533 m_pz2=records->GetDouble("pz");
534 m_ecms2=bE*2.00;
535 m2_runNoValid=true;
536 }
537}
538
539
540
541
int runNo
Definition: DQA_TO_DB.cxx:12
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0
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()
void readDB(int runNo)
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)