BOSS 7.0.1
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}
10
12
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;
19 return status;
20 }
21 IIncidentSvc* incsvc;
22 status=service("IncidentSvc", incsvc);
23 int priority = 100;
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;
28 return status;
29 }
30 status=serviceLocator()->service("EventDataSvc", m_eventSvc, true);
31 if(!status.isSuccess()){
32 log<<MSG::ERROR<<"MeasuredEcmsSvc Unable to find EventDataSvc "<<endreq;
33 return status;
34 }
35 log<<MSG::INFO<<"MeasuredEcmsSvc initialized successfully"<<endreq;
36 return StatusCode::SUCCESS;
37}
38
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;
45 return status;
46 }
47 log<<MSG::INFO<<"MeasuredEcmsSvc finalized successfully"<<endreq;
48 return StatusCode::SUCCESS;
49}
50
51StatusCode MeasuredEcmsSvc::queryInterface(const InterfaceID& riid, void** ppvIF){
52 if(IMeasuredEcmsSvc::interfaceID().versionMatch(riid)) *ppvIF = dynamic_cast<IMeasuredEcmsSvc*>(this);
53 else return Service::queryInterface(riid, ppvIF);
54 addRef();
55 return StatusCode::SUCCESS;
56}
57
58void MeasuredEcmsSvc::handle(const Incident& inc){
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;
64 m_callRead=true;
65 }
66}
67
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;
78 char stmt[400];
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; }
83 else{
84 DatabaseRecord* records=res[0];
85 log<<MSG::INFO<<"MeasuredEcmsSvc first read the runNo, read the MeasuredEcms database"<<runNo<<endreq;
86 m_runFrom=records->GetDouble("RunFrom");
87 m_runTo=records->GetDouble("RunTo");
88 m_sampleName=records->GetDouble("sample");
89 m_ecms=records->GetDouble("Ecms");
90 m_ecmsErr=records->GetDouble("Ecms_err");
91 m_aveEcms=records->GetDouble("Ave_Ecms");
92 m_aveEcmsErr=records->GetDouble("Ave_Ecms_err");
93 m_runNoValid=true;
94 }
95}
96
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;
107 char stmt1[400];
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;}
112 else{
113 DatabaseRecord* records = res[0];
114 log<<MSG::INFO<<"MeasuredEcmsSvc first read the runNo, read the RunParams database"<<runNo<<endreq;
115 double bE=0;
116 bE=records->GetDouble("beam_energy");
117 m_px=records->GetDouble("px");
118 m_py=records->GetDouble("py");
119 m_pz=records->GetDouble("pz");
120 m_ecms=bE*2.00;
121 m_runNoValid=true;
122 }
123}
124
126 if(std::abs(runNo)>=RunParamsMin&&std::abs(runNo)<=RunParamsMax) readRunParams(runNo);
127 if(std::abs(runNo)>=MeasuredEcmsMin&&std::abs(runNo)<=MeasuredEcmsMax) readMeasuredEcms(runNo);
128}
129
131 MsgStream log(msgSvc(), name());
132 log<<MSG::INFO<<"MeasuredEcmsSvc read the sample name"<<endreq;
133 if(m_recallRead&&m_callRead){
134 readDB(runNo);
135 m_recallRead=false;
136 }
137 return m_sampleName;
138}
139
141 MsgStream log(msgSvc(), name());
142 log<<MSG::INFO<<"MeasuredEcmsSvc read the RunFrom"<<endreq;
143 if(m_recallRead&&m_callRead){
144 readDB(runNo);
145 m_recallRead=false;
146 }
147 return m_runFrom;
148}
149
151 MsgStream log(msgSvc(), name());
152 log<<MSG::INFO<<"MeasuredEcmsSvc read the RunTo"<<endreq;
153 if(m_recallRead&&m_callRead){
154 readDB(runNo);
155 m_recallRead=false;
156 }
157 return m_runTo;
158}
159
161 MsgStream log(msgSvc(), name());
162 log<<MSG::INFO<<"MeasuredEcmsSvc read the ecms"<<endreq;
163 if(m_recallRead&&m_callRead){
164 readDB(runNo);
165 m_recallRead=false;
166 }
167 return m_ecms;
168}
169
171 MsgStream log(msgSvc(), name());
172 log<<MSG::INFO<<"MeasuredEcmsSvc read the error of ecms"<<endreq;
173 if(m_recallRead&&m_callRead){
174 readDB(runNo);
175 m_recallRead=false;
176 }
177 return m_ecmsErr;
178}
179
181 MsgStream log(msgSvc(), name());
182 log<<MSG::INFO<<"MeasuredEcmsSvc read the average ecms"<<endreq;
183 if(m_recallRead&&m_callRead){
184 readDB(runNo);
185 m_recallRead=false;
186 }
187 return m_aveEcms;
188}
189
191 MsgStream log(msgSvc(), name());
192 log<<MSG::INFO<<"MeasuredEcmsSvc read the error of the average ecms"<<endreq;
193 if(m_recallRead&&m_callRead){
194 readDB(runNo);
195 m_recallRead=false;
196 }
197 return m_aveEcmsErr;
198}
199
201 MsgStream log(msgSvc(), name());
202 log<<MSG::INFO<<"MeasuredEcmsSvc judge the valid of runNo"<<endreq;
203 if(m_callRead){
204 readDB(runNo);
205 m_recallRead=false;
206 }
207 return m_runNoValid;
208}
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)
int getRunFrom(int runNo)
int getSampleName(int runNo)
double getEcms(int runNo)
virtual ~MeasuredEcmsSvc()
void handle(const Incident &)
virtual StatusCode initialize()
void readDB(int runNo)
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)