BOSS 7.0.2
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 declareProperty("MeasuredEcmsMin", MeasuredEcmsMin=23463);
8 declareProperty("MeasuredEcmsMax", MeasuredEcmsMax=38140);
9 declareProperty("TableName", table="RunParams");
10 declareProperty("ColumnName", column="beam_energy");
11}
12
14
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;
21 return status;
22 }
23 IIncidentSvc* incsvc;
24 status=service("IncidentSvc", incsvc);
25 int priority = 100;
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;
30 return status;
31 }
32 status=serviceLocator()->service("EventDataSvc", m_eventSvc, true);
33 if(!status.isSuccess()){
34 log<<MSG::ERROR<<"MeasuredEcmsSvc Unable to find EventDataSvc "<<endreq;
35 return status;
36 }
37 log<<MSG::INFO<<"MeasuredEcmsSvc initialized successfully"<<endreq;
38 return StatusCode::SUCCESS;
39}
40
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;
47 return status;
48 }
49 log<<MSG::INFO<<"MeasuredEcmsSvc finalized successfully"<<endreq;
50 return StatusCode::SUCCESS;
51}
52
53StatusCode MeasuredEcmsSvc::queryInterface(const InterfaceID& riid, void** ppvIF){
54 if(IMeasuredEcmsSvc::interfaceID().versionMatch(riid)) *ppvIF = dynamic_cast<IMeasuredEcmsSvc*>(this);
55 else return Service::queryInterface(riid, ppvIF);
56 addRef();
57 return StatusCode::SUCCESS;
58}
59
60void MeasuredEcmsSvc::handle(const Incident& inc){
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;
66 m_callRead=true;
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;
71 m_info=0;
72 }
73}
74
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;
81 char stmt[400];
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; }
86 else{
87 DatabaseRecord* records=res[0];
88 log<<MSG::INFO<<"MeasuredEcmsSvc first read the runNo, read the MeasuredEcms database"<<runNo<<endreq;
89 m_runFrom=records->GetDouble("RunFrom");
90 m_runTo=records->GetDouble("RunTo");
91 m_sampleName=records->GetDouble("sample");
92 m_ecms=records->GetDouble("Ecms");
93 m_ecmsErr=records->GetDouble("Ecms_err");
94 m_aveEcms=records->GetDouble("Ave_Ecms");
95 m_aveEcmsErr=records->GetDouble("Ave_Ecms_err");
96 m_runNoValid=true;
97 }
98}
99
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;
106 char stmt1[400];
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;}
111 else{
112 DatabaseRecord* records = res[0];
113 log<<MSG::INFO<<"MeasuredEcmsSvc first read the runNo, read the RunParams database"<<runNo<<endreq;
114 double bE=0;
115 bE=records->GetDouble("beam_energy");
116 m_px=records->GetDouble("px");
117 m_py=records->GetDouble("py");
118 m_pz=records->GetDouble("pz");
119 m_ecms=bE*2.00;
120 m_runNoValid=true;
121 }
122}
123
124void MeasuredEcmsSvc::readInfo(int runNo, char *tab, char *col){
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;
130 char stmt1[400];
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;}
135 else{
136 DatabaseRecord* records = res[0];
137 log<<MSG::INFO<<"MeasuredEcmsSvc first read the runNo, read the "<<tab<<" database "<<runNo<<endreq;
138 m_info=records->GetDouble(col);
139 m_runNoValid=true;
140 }
141}
142
144 char tab[100];
145 char col[100];
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;
153 char stmt1[500];
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;}
158 else{
159 DatabaseRecord* records = res[0];
160 log<<MSG::INFO<<"MeasuredEcmsSvc first read the runNo, read the "<<tab<<" database "<<runNo<<endreq;
161 m_info=records->GetDouble(col);
162 m_runNoValid=true;
163 }
164}
165
167 if(std::abs(runNo)>=RunParamsMin&&std::abs(runNo)<=RunParamsMax) readRunParams(runNo);
168 if(std::abs(runNo)>=MeasuredEcmsMin&&std::abs(runNo)<=MeasuredEcmsMax) readMeasuredEcms(runNo);
169}
170
171double MeasuredEcmsSvc::getInfo(int runNo, char *tab, char *col){
172 MsgStream log(msgSvc(), name());
173 log<<MSG::INFO<<"MeasuredEcmsSvc read the "<<tab<<"-"<<col<<endreq;
174 if(m_recallRead&&m_callRead){
175 readInfo(runNo, tab, col);
176 }
177 return m_info;
178}
179
181 char tab[100];
182 char col[100];
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){
189 }
190 return m_info;
191}
192
194 MsgStream log(msgSvc(), name());
195 log<<MSG::INFO<<"MeasuredEcmsSvc read the sample name"<<endreq;
196 if(m_recallRead&&m_callRead){
197 readDB(runNo);
198 m_recallRead=false;
199 }
200 return m_sampleName;
201}
202
204 MsgStream log(msgSvc(), name());
205 log<<MSG::INFO<<"MeasuredEcmsSvc read the RunFrom"<<endreq;
206 if(m_recallRead&&m_callRead){
207 readDB(runNo);
208 m_recallRead=false;
209 }
210 return m_runFrom;
211}
212
214 MsgStream log(msgSvc(), name());
215 log<<MSG::INFO<<"MeasuredEcmsSvc read the RunTo"<<endreq;
216 if(m_recallRead&&m_callRead){
217 readDB(runNo);
218 m_recallRead=false;
219 }
220 return m_runTo;
221}
222
224 MsgStream log(msgSvc(), name());
225 log<<MSG::INFO<<"MeasuredEcmsSvc read the ecms"<<endreq;
226 if(m_recallRead&&m_callRead){
227 readDB(runNo);
228 m_recallRead=false;
229 }
230 return m_ecms;
231}
232
234 MsgStream log(msgSvc(), name());
235 log<<MSG::INFO<<"MeasuredEcmsSvc read the ecms"<<endreq;
236 if(m_recallRead&&m_callRead){
237 readDB(runNo);
238 m_recallRead=false;
239 }
240 return m_px;
241}
242
243
245 MsgStream log(msgSvc(), name());
246 log<<MSG::INFO<<"MeasuredEcmsSvc read the ecms"<<endreq;
247 if(m_recallRead&&m_callRead){
248 readDB(runNo);
249 m_recallRead=false;
250 }
251 return m_py;
252}
253
255 MsgStream log(msgSvc(), name());
256 log<<MSG::INFO<<"MeasuredEcmsSvc read the ecms"<<endreq;
257 if(m_recallRead&&m_callRead){
258 readDB(runNo);
259 m_recallRead=false;
260 }
261 return m_pz;
262}
263
265 MsgStream log(msgSvc(), name());
266 log<<MSG::INFO<<"MeasuredEcmsSvc read the error of ecms"<<endreq;
267 if(m_recallRead&&m_callRead){
268 readDB(runNo);
269 m_recallRead=false;
270 }
271 return m_ecmsErr;
272}
273
275 MsgStream log(msgSvc(), name());
276 log<<MSG::INFO<<"MeasuredEcmsSvc read the average ecms"<<endreq;
277 if(m_recallRead&&m_callRead){
278 readDB(runNo);
279 m_recallRead=false;
280 }
281 return m_aveEcms;
282}
283
285 MsgStream log(msgSvc(), name());
286 log<<MSG::INFO<<"MeasuredEcmsSvc read the error of the average ecms"<<endreq;
287 if(m_recallRead&&m_callRead){
288 readDB(runNo);
289 m_recallRead=false;
290 }
291 return m_aveEcmsErr;
292}
293
294bool MeasuredEcmsSvc::isReadDBValid(int runNo, char *tab, char *col){
295 MsgStream log(msgSvc(), name());
296 log<<MSG::INFO<<"MeasuredEcmsSvc judge the valid of "<<tab<<"-"<<col<<endreq;
297 if(m_callRead){
298 readInfo(runNo, tab, col);
299 m_recallRead=false;
300 }
301 return m_runNoValid;
302}
303
305 char tab[100];
306 char col[100];
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;
311 if(m_callRead){
313 m_recallRead=false;
314 }
315 return m_runNoValid;
316}
317
319 MsgStream log(msgSvc(), name());
320 log<<MSG::INFO<<"MeasuredEcmsSvc judge the valid of runNo"<<endreq;
321 if(m_callRead){
322 readDB(runNo);
323 m_recallRead=false;
324 }
325 return m_runNoValid;
326}
int runNo
Definition: DQA_TO_DB.cxx:12
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0
double getEcmsErr(int runNo)
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvIF)
void readRunParams(int runNo)
int getRunTo(int runNo)
double getPz(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 &)
double getPy(int runNo)
virtual StatusCode initialize()
void readInfo(int runNo, char *tab, char *col)
bool isReadDBValid(int runNo, char *tab, char *col)
void readDB(int runNo)
bool isRunNoValid(int runNo)
MeasuredEcmsSvc(const std::string &name, ISvcLocator *svcLoc)
double getAveEcmsErr(int runNo)
virtual StatusCode finalize()
double getPx(int runNo)
double getAveEcms(int runNo)
void readMeasuredEcms(int runNo)