BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
MeasuredEcmsSvc Class Reference

#include <MeasuredEcmsSvc.h>

+ Inheritance diagram for MeasuredEcmsSvc:

Public Member Functions

 MeasuredEcmsSvc (const std::string &name, ISvcLocator *svcLoc)
 
virtual ~MeasuredEcmsSvc ()
 
virtual StatusCode initialize ()
 
virtual StatusCode finalize ()
 
void handle (const Incident &)
 
bool isRunNoValid ()
 
double getEcms ()
 
double getBeamEnergy ()
 
double getEcmsError ()
 
double getAverageEcms ()
 
double getAverageEcmsError ()
 
double getSampleName ()
 
double getPx ()
 
double getPy ()
 
double getPz ()
 
double getBeamEnergyError ()
 
double getEcms (int runNo)
 
double getBeamEnergy (int runNo)
 
std::string getRecord (int runNo, char *tab, char *col, char *min_col, char *max_col)
 

Public Attributes

bool m_readOneTime
 
int m_runFrom
 
int m_runTo
 
std::map< int, int > m_mapBeamE
 
int m_sele
 

Protected Member Functions

void readDBTable (int runNo)
 
int triggerDBTable (int runNo)
 
void readDBTable (int runFrom, int runTo)
 

Friends

class CnvFactory< MeasuredEcmsSvc >
 

Detailed Description

Class to read the data information from database, such as ECMS, ECMS Error ... ( beam_energy = ECMS / 2.0). Access to almost all the XYZ, 3773, and 4180 data.

Definition at line 25 of file MeasuredEcmsSvc.h.

Constructor & Destructor Documentation

◆ MeasuredEcmsSvc()

MeasuredEcmsSvc::MeasuredEcmsSvc ( const std::string &  name,
ISvcLocator *  svcLoc 
)

Constructor

Definition at line 16 of file MeasuredEcmsSvc.cxx.

16 : base_class(name, svcLoc)
17{
18 // declare properties
19 declareProperty("ReadOneTime", m_readOneTime=false);
20 declareProperty("RunFrom", m_runFrom=8093);
21 declareProperty("RunTo", m_runTo=9025);
22 m_runflag = -1;
23}

◆ ~MeasuredEcmsSvc()

MeasuredEcmsSvc::~MeasuredEcmsSvc ( )
virtual

Destructor

Definition at line 26 of file MeasuredEcmsSvc.cxx.

27{
28 MsgStream log(msgSvc(), name());
29 log << MSG::INFO << "destructor" << endreq;
30}
IMessageSvc * msgSvc()

Member Function Documentation

◆ finalize()

StatusCode MeasuredEcmsSvc::finalize ( )
virtual

Finalize

Definition at line 72 of file MeasuredEcmsSvc.cxx.

73{
74 MsgStream log(msgSvc(), name());
75 log << MSG::INFO << "finalize begin here" << endreq;
76
77 StatusCode status = Service::finalize();
78 if (! status.isSuccess()) {
79 log << MSG::ERROR << "can not finalize" << endreq;
80 return status;
81 }
82
83 log << MSG::INFO << "finalized successfully" << endreq;
84 return StatusCode::SUCCESS;
85}

◆ getAverageEcms()

double MeasuredEcmsSvc::getAverageEcms ( )
inline

Return average Ecms

Definition at line 63 of file MeasuredEcmsSvc.h.

63{ return (m_rowNo1 != 0) ? (double)m_dbRecordVector[m_sele]->GetDouble("Ave_Ecms") : 0.; }

◆ getAverageEcmsError()

double MeasuredEcmsSvc::getAverageEcmsError ( )
inline

Return average Ecms error

Definition at line 66 of file MeasuredEcmsSvc.h.

66{ return (m_rowNo1 != 0) ? (double)m_dbRecordVector[m_sele]->GetDouble("Ave_Ecms_err") : 0.; }

◆ getBeamEnergy() [1/2]

double MeasuredEcmsSvc::getBeamEnergy ( )
inline

Return beam energy

Definition at line 57 of file MeasuredEcmsSvc.h.

57{ return (double)getEcms() / 2.00; }

◆ getBeamEnergy() [2/2]

double MeasuredEcmsSvc::getBeamEnergy ( int  runNo)
inline

Return beam energy depend on runNo only. Here RunNo. can be set independ on event.

Definition at line 91 of file MeasuredEcmsSvc.h.

91{ return (double)getEcms(runNo) / 2.00; }
int runNo
Definition: DQA_TO_DB.cxx:12

◆ getBeamEnergyError()

double MeasuredEcmsSvc::getBeamEnergyError ( )
inline

Return beam energy error

Definition at line 81 of file MeasuredEcmsSvc.h.

81{ return (m_rowNo2 != 0) ? (double)m_dbRecordVector[m_sele]->GetDouble("beam_energy_err") : 0.; }

◆ getEcms() [1/2]

double MeasuredEcmsSvc::getEcms ( )

Return Ecms ( Ecms = beam_energy * 2 )

Definition at line 127 of file MeasuredEcmsSvc.cxx.

128{
129 switch (m_tableOption) {
130 case 1:
131 return (m_rowNo1 != 0) ? (double)m_dbRecordVector[m_sele]->GetDouble("Ecms") : 0.00;
132 break;
133
134 case 2:
135 return (m_rowNo2 != 0) ? (double)m_dbRecordVector[m_sele]->GetDouble("beam_energy") * 2.00 : 0.00;
136 break;
137
138 default:
139 if (m_rowNo1 != 0) return (double)m_dbRecordVector[m_sele]->GetDouble("Ecms");
140 else if (m_rowNo2 != 0) return (double)m_dbRecordVector[m_sele]->GetDouble("beam_energy") * 2.00;
141 else return 0.00;
142 break;
143 }
144}

Referenced by getBeamEnergy().

◆ getEcms() [2/2]

double MeasuredEcmsSvc::getEcms ( int  runNo)

Return Ecms depend on runNo only. Here RunNo. can be set independ on event.

Definition at line 148 of file MeasuredEcmsSvc.cxx.

149{
150 m_runNo = std::abs(runNo);
151
153
154 switch (m_tableOption) {
155 case 1:
156 return (m_rowNo1 != 0) ? (double)m_dbRecordVector[m_sele]->GetDouble("Ecms") : 0.00;
157 break;
158
159 case 2:
160 return (m_rowNo2 != 0) ? (double)m_dbRecordVector[m_sele]->GetDouble("beam_energy") * 2.00 : 0.00;
161 break;
162
163 default:
164 if (m_rowNo1 != 0) return (double)m_dbRecordVector[m_sele]->GetDouble("Ecms");
165 else if (m_rowNo2 != 0) return (double)m_dbRecordVector[m_sele]->GetDouble("beam_energy") * 2.00;
166 else return 0.00;
167 break;
168 }
169}
void readDBTable(int runNo)

◆ getEcmsError()

double MeasuredEcmsSvc::getEcmsError ( )
inline

Return error for Ecms

Definition at line 60 of file MeasuredEcmsSvc.h.

60{ return (m_rowNo1 != 0) ? (double)m_dbRecordVector[m_sele]->GetDouble("Ecms_err") : 0.; }

◆ getPx()

double MeasuredEcmsSvc::getPx ( )
inline

Return x momentum

Definition at line 72 of file MeasuredEcmsSvc.h.

72{ return (m_rowNo2 != 0) ? (double)m_dbRecordVector[m_sele]->GetDouble("px") : 0.011; }

◆ getPy()

double MeasuredEcmsSvc::getPy ( )
inline

Return y momentum

Definition at line 75 of file MeasuredEcmsSvc.h.

75{ return (m_rowNo2 != 0) ? (double)m_dbRecordVector[m_sele]->GetDouble("py") : 0.; }

◆ getPz()

double MeasuredEcmsSvc::getPz ( )
inline

Return z momentum

Definition at line 78 of file MeasuredEcmsSvc.h.

78{ return (m_rowNo2 != 0) ? (double)m_dbRecordVector[m_sele]->GetDouble("pz") : 0.; }

◆ getRecord()

std::string MeasuredEcmsSvc::getRecord ( int  runNo,
char *  tab,
char *  col,
char *  min_col,
char *  max_col 
)

Return the string depend on the parameters

Parameters
runNorunNo. input (independent)
tabtable name in database, such as MeasuredEcms2, RunParams
colthe variable name which you want to read, such as Ecms
min_colthe down limits variable name, such as Run_From
max_colthe upper limits variable name, such as Run_To

Definition at line 327 of file MeasuredEcmsSvc.cxx.

328{
329 std::string strRecord;
330 m_isRunNoValid = false;
331
332 MsgStream log(msgSvc(), name());
333 log << MSG::INFO << "MeasuredEcmsSvc begin read database " << tab << "-" << col << endreq;
334
335 int runNum = std::abs(runNo);
336
337 if (runNo < 0) log << MSG::INFO << "MeasuredEcmsSvc for MC events" << endreq;
338 else log << MSG::INFO << "MeasuredEcmsSvc for DT events" << endreq;
339
340 char stmt[500];
341 snprintf(stmt, 1024, "select %s from %s where %s <= %d and %s >= %d", col, tab, min_col, runNum, max_col, runNum);
342
344 int row_no = m_dbSvc->query("offlinedb", stmt, res);
345
346 if(row_no == 0) {
347 log << MSG::ERROR << "RowNo can not be 0 for " << tab << ", failed to read DB for " << runNo << endreq;
348 }
349 else {
350 log << MSG::INFO << "MeasuredEcmsSvc first read the runNo, read the " << tab << " database " << runNo << endreq;
351 strRecord = res[m_sele]->GetString(col);
352 m_isRunNoValid = true;
353 }
354
355 return strRecord;
356}
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0

◆ getSampleName()

double MeasuredEcmsSvc::getSampleName ( )
inline

Return sample name

Definition at line 69 of file MeasuredEcmsSvc.h.

69{ return (m_rowNo1 != 0) ? (double)m_dbRecordVector[m_sele]->GetDouble("sample") : 0.; }

◆ handle()

void MeasuredEcmsSvc::handle ( const Incident &  inc)

Handle. Process after initialization

Definition at line 99 of file MeasuredEcmsSvc.cxx.

100{
101 MsgStream log(messageService(), name());
102 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
103
104 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc, "/Event/EventHeader");
105 int runNo = eventHeader->runNumber();
106 m_runNo = std::abs(runNo);
107 if (inc.type() == "NewRun") {
108 log << MSG::INFO << "RunNo is new, call the readMeasuredEcms again" << endreq;
109 if(!m_readOneTime) {
110 m_sele=0;
112 } else {
113 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,"/Event/EventHeader");
114 int run = eventHeader->runNumber();
115 if(run<0) run=-run;
116 if(m_mapBeamE[run]>=0) {
117 m_isRunNoValid = true;
118 m_sele=m_mapBeamE[run];
119 } else {
120 std::cout<<"MeasuredEcmsSvc, could not get Ecm infor in handle new run"<<std::endl;
121 }
122 }
123 }
124}
std::map< int, int > m_mapBeamE

◆ initialize()

StatusCode MeasuredEcmsSvc::initialize ( )
virtual

Query interface Initialize

Definition at line 33 of file MeasuredEcmsSvc.cxx.

34{
35 MsgStream log(msgSvc(), name());
36 log << MSG::INFO << "initialize begin here" << endreq;
37
38 StatusCode status = Service::initialize();
39 if (! status.isSuccess()) {
40 log << MSG::ERROR << "can not initialize" << endreq;
41 return status;
42 }
43 IIncidentSvc *incsvc;
44 status = service("IncidentSvc", incsvc);
45 int priority = 100;
46 if (status.isSuccess()) incsvc->addListener(this, "NewRun", priority);
47
48 status = serviceLocator()->service("DatabaseSvc", m_dbSvc, true);
49 if (! status.isSuccess()) {
50 log << MSG::ERROR<< "unable to find DatabaseSvc" << endreq;
51 return status;
52 }
53
54 status = serviceLocator()->service("EventDataSvc", m_eventSvc, true);
55 if (! status.isSuccess()) {
56 log << MSG::ERROR << "unable to find EventDataSvc " << endreq;
57 return status;
58 }
59 if(m_readOneTime){
60 if(m_runFrom>=8093){
62 }
63 else
64 std::cout<<"MeasuredEcmsSvc, invalid RunFrom, RunFrom should be >=8093"<<std::endl;
65 }
66 m_sele = 0;
67 log << MSG::INFO << "initialized successfully" << endreq;
68 return StatusCode::SUCCESS;
69}

◆ isRunNoValid()

bool MeasuredEcmsSvc::isRunNoValid ( )
inline

Return true or false for runNo

Definition at line 51 of file MeasuredEcmsSvc.h.

51{ return m_isRunNoValid; }

◆ readDBTable() [1/2]

void MeasuredEcmsSvc::readDBTable ( int  runFrom,
int  runTo 
)
protected

Definition at line 243 of file MeasuredEcmsSvc.cxx.

244{
245 MsgStream log(msgSvc(), name());
246 log << MSG::INFO << "begin read database MeasuredEcmsSvc from " << m_runFrom << " to " << m_runTo << endreq;
247 m_dbRecordVector.clear();
248
249 m_rowNo1 = 0;
250 m_rowNo2 = 0;
251 m_isRunNoValid = false;
252 char stmt[400];
253
254 if ((runFrom >= 23463 && runFrom <= 38140) || (runFrom >= 47543 && runFrom <= 51498)) {
255 if ((runTo >= 23463 && runTo <= 38140) || (runTo >= 47543 && runTo <= 51498)) {
256 log << MSG::INFO << "read table MeasuredEcms2 for " << runFrom <<":" << runTo << endreq;
257 snprintf(stmt, 1024, "select sample, RunFrom, RunTo, Ecms, Ecms_err, Ave_Ecms, Ave_Ecms_err from MeasuredEcms2 where RunFrom >= %d and RunTo <= %d", runFrom, runTo);
258 m_tableOption = 1;
259 }
260 }
261 else if ((runFrom >= 11414 && runFrom <= 23454) || (runFrom >= 43716 && runFrom <= 47066) || (runFrom >= 70522 && runFrom <= 73929)) {
262 if ((runTo >= 11414 && runTo <= 23454) || (runTo >= 43716 && runTo <= 47066) || (runFrom >= 70522 && runFrom <= 73929)) {
263 log << MSG::INFO << "read table RunParams for " << runFrom <<":" << runTo << endreq;
264 snprintf(stmt, 1024, "select run_number, beam_energy, px, py, pz, beam_energy_err from RunParams where run_number >= %d and run_number <= %d", runFrom, runTo);
265 m_tableOption = 2;
266 }
267 }
268 else {
269 m_tableOption = -1;
270 }
271
272 if (m_tableOption == 1 || m_tableOption == 2) {
273 int rowNo = m_dbSvc->query("offlinedb", stmt, m_dbRecordVector);
274 if (rowNo == 0) {
275 log << MSG::ERROR << "RowNo can not be 0, failed to read DB for " << runFrom <<":" << runTo << endreq;
276 cout << "RowNo can not be 0, failed to read DB for " << runFrom <<":" << runTo << endl;
277 } else {
278 if (m_tableOption == 1) m_rowNo1 = 1;
279 if (m_tableOption == 2) m_rowNo2 = 1;
280 log << MSG::INFO << "initialize the DatabaseRecordVector OK for " << runFrom <<":" << runTo << endreq;
281 cout << "MeasuredEcmsSvc: initialize the DatabaseRecordVector OK for " << runFrom <<":" << runTo << ", Nrecord = " << rowNo << "." << endl;
282 m_isRunNoValid = true;
283 }
284 if (m_rowNo2==1) {
285 for ( int i=0; i<rowNo; i++ ) {
286 int runnumber = m_dbRecordVector[i]->GetInt("run_number");
287 m_mapBeamE[runnumber] = i;
288 }
289 }
290 if (m_rowNo1==1) {
291 for ( int i=0; i<rowNo; i++ ) {
292 int run0 = m_dbRecordVector[i]->GetInt("RunFrom");
293 int run1 = m_dbRecordVector[i]->GetInt("RunTo");
294 for ( int j = run0; j<=run1; j++) {
295 m_mapBeamE[j] = i;
296 }
297 }
298 }
299 }
300}

◆ readDBTable() [2/2]

void MeasuredEcmsSvc::readDBTable ( int  runNo)
protected

Read database table

Definition at line 172 of file MeasuredEcmsSvc.cxx.

173{
174 if (runNo == m_runflag) return;
175 m_runflag = runNo;
176 MsgStream log(msgSvc(), name());
177 log << MSG::INFO << "begin read database MeasuredEcmsSvc" << endreq;
178
179 m_dbRecordVector.clear();
180
181 m_rowNo1 = 0;
182 m_rowNo2 = 0;
183
184 m_isRunNoValid = false;
185 int runNum = std::abs(runNo);
186
187 if (runNo < 0) log << MSG::INFO << "MeasuredEcmsSvc for MC events" << endreq;
188 else log << MSG::INFO << "MeasuredEcmsSvc for DT events" << endreq;
189
190 triggerDBTable(runNum);
191
192 char stmt[400];
193
194 char stmt1[400];
195 char stmt2[400];
196
197 switch(m_tableOption) {
198 case 1:
199 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);
200 break;
201
202 case 2:
203 snprintf(stmt, 1024, "select beam_energy, px, py, pz, beam_energy_err from RunParams where run_number = %d", runNum);
204 break;
205
206 default:
207 snprintf(stmt1, 1024, "select sample, RunFrom, RunTo, Ecms, Ecms_err, Ave_Ecms, Ave_Ecms_err from MeasuredEcms2 where RunFrom <= %d and RunTo >= %d", runNum, runNum);
208 snprintf(stmt2, 1024, "select beam_energy, px, py, pz, beam_energy_err from RunParams where run_number = %d", runNum);
209 break;
210 }
211
212 if (m_tableOption == 1 || m_tableOption == 2) {
213 int rowNo = m_dbSvc->query("offlinedb", stmt, m_dbRecordVector);
214
215 if (rowNo == 0) {
216 log << MSG::ERROR << "RowNo can not be 0, failed to read DB for " << runNo << endreq;
217 }
218 else {
219 if (m_tableOption == 1) m_rowNo1 = 1;
220 if (m_tableOption == 2) m_rowNo2 = 1;
221 log << MSG::INFO << "initialize the DatabaseRecordVector OK for " << runNo << endreq;
222 m_isRunNoValid = true;
223 }
224 }
225 else {
226 m_rowNo1 = m_dbSvc->query("offlinedb", stmt1, m_dbRecordVector);
227 if (m_rowNo1 == 0) {
228 m_dbRecordVector.clear();
229 m_rowNo2 = m_dbSvc->query("offlinedb", stmt2, m_dbRecordVector);
230 }
231
232 if (m_rowNo1 == 0 && m_rowNo2 == 0) {
233 log << MSG::ERROR << "RowNo can not be 0, failed to read DB for " << runNo << endreq;
234 }
235 else {
236 log << MSG::INFO << "initialize the DatabaseRecordVector OK for " << runNo << endreq;
237 m_isRunNoValid = true;
238 }
239 }
240}
int triggerDBTable(int runNo)

Referenced by getEcms(), handle(), and initialize().

◆ triggerDBTable()

int MeasuredEcmsSvc::triggerDBTable ( int  runNo)
protected

trigger based on runNo @option 1 MeasuredEcms2 table for XYZ (Charmonium data) @option 2 RunParams table for 3773, 4180 (Charm data)

Definition at line 303 of file MeasuredEcmsSvc.cxx.

304{
305 MsgStream log(msgSvc(), name());
306 log << MSG::INFO << "triggerDBTable based on runNo" << endl;
307
308 int runNum = std::abs(runNo);
309
310 if ((runNum >= 23463 && runNum <= 38140) || (runNum >= 47543 && runNum <= 51498)) {
311 log << MSG::INFO << "read table MeasuredEcms2 for " << runNo << endreq;
312 m_tableOption = 1;
313 }
314
315 else if ((runNum >= 11414 && runNum <= 23454) || (runNum >= 43716 && runNum <= 47066)|| (runNum >= 70522 && runNum <= 73929)) {
316 log << MSG::INFO << "read table RunParams for " << runNo << endreq;
317 m_tableOption = 2;
318 }
319
320 else m_tableOption = -1;
321
322 return m_tableOption;
323}

Referenced by readDBTable().

Friends And Related Function Documentation

◆ CnvFactory< MeasuredEcmsSvc >

friend class CnvFactory< MeasuredEcmsSvc >
friend

Definition at line 1 of file MeasuredEcmsSvc.h.

Member Data Documentation

◆ m_mapBeamE

std::map<int,int> MeasuredEcmsSvc::m_mapBeamE

Definition at line 106 of file MeasuredEcmsSvc.h.

Referenced by handle(), and readDBTable().

◆ m_readOneTime

bool MeasuredEcmsSvc::m_readOneTime

Definition at line 103 of file MeasuredEcmsSvc.h.

Referenced by handle(), and initialize().

◆ m_runFrom

int MeasuredEcmsSvc::m_runFrom

Definition at line 104 of file MeasuredEcmsSvc.h.

Referenced by initialize(), and readDBTable().

◆ m_runTo

int MeasuredEcmsSvc::m_runTo

Definition at line 105 of file MeasuredEcmsSvc.h.

Referenced by initialize(), and readDBTable().

◆ m_sele


The documentation for this class was generated from the following files: