BOSS 7.0.9
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 queryInterface (const InterfaceID &riid, void **ppvIF)
 
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 Member Functions inherited from IMeasuredEcmsSvc
virtual ~IMeasuredEcmsSvc ()
 
virtual bool isRunNoValid ()=0
 
virtual double getEcms ()=0
 
virtual double getBeamEnergy ()=0
 
virtual double getEcmsError ()=0
 
virtual double getAverageEcms ()=0
 
virtual double getAverageEcmsError ()=0
 
virtual double getSampleName ()=0
 
virtual double getPx ()=0
 
virtual double getPy ()=0
 
virtual double getPz ()=0
 
virtual double getEcms (int runNo)=0
 
virtual std::string getRecord (int runNo, char *tab, char *col, char *min_col, char *max_col)=0
 

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)
 
virtual void readDBTable (int runNo)=0
 
virtual int triggerDBTable (int runNo)=0
 

Friends

class CnvFactory< MeasuredEcmsSvc >
 

Additional Inherited Members

- Static Public Member Functions inherited from IMeasuredEcmsSvc
static const InterfaceID & interfaceID ()
 

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 24 of file MeasuredEcmsSvc.h.

Constructor & Destructor Documentation

◆ MeasuredEcmsSvc()

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

Constructor

Definition at line 15 of file MeasuredEcmsSvc.cxx.

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

◆ ~MeasuredEcmsSvc()

MeasuredEcmsSvc::~MeasuredEcmsSvc ( )
virtual

Destructor

Definition at line 25 of file MeasuredEcmsSvc.cxx.

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

Member Function Documentation

◆ finalize()

StatusCode MeasuredEcmsSvc::finalize ( )
virtual

Finalize

Definition at line 74 of file MeasuredEcmsSvc.cxx.

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

◆ getAverageEcms()

double MeasuredEcmsSvc::getAverageEcms ( )
inlinevirtual

Return average Ecms

Implements IMeasuredEcmsSvc.

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 ( )
inlinevirtual

Return average Ecms error

Implements IMeasuredEcmsSvc.

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 ( )
inlinevirtual

Return beam energy

Implements IMeasuredEcmsSvc.

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 ( )
virtual

Return Ecms ( Ecms = beam_energy * 2 )

Implements IMeasuredEcmsSvc.

Definition at line 130 of file MeasuredEcmsSvc.cxx.

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

Referenced by getBeamEnergy().

◆ getEcms() [2/2]

double MeasuredEcmsSvc::getEcms ( int  runNo)
virtual

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

Implements IMeasuredEcmsSvc.

Definition at line 151 of file MeasuredEcmsSvc.cxx.

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

◆ getEcmsError()

double MeasuredEcmsSvc::getEcmsError ( )
inlinevirtual

Return error for Ecms

Implements IMeasuredEcmsSvc.

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 ( )
inlinevirtual

Return x momentum

Implements IMeasuredEcmsSvc.

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 ( )
inlinevirtual

Return y momentum

Implements IMeasuredEcmsSvc.

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 ( )
inlinevirtual

Return z momentum

Implements IMeasuredEcmsSvc.

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 
)
virtual

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

Implements IMeasuredEcmsSvc.

Definition at line 331 of file MeasuredEcmsSvc.cxx.

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

◆ getSampleName()

double MeasuredEcmsSvc::getSampleName ( )
inlinevirtual

Return sample name

Implements IMeasuredEcmsSvc.

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 101 of file MeasuredEcmsSvc.cxx.

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

◆ initialize()

StatusCode MeasuredEcmsSvc::initialize ( )
virtual

Initialize

Definition at line 32 of file MeasuredEcmsSvc.cxx.

33{
34 MsgStream log(msgSvc(), name());
35 log << MSG::INFO << "initialize begin here" << endreq;
36
37 StatusCode status = Service::initialize();
38 if (! status.isSuccess()) {
39 log << MSG::ERROR << "can not initialize" << endreq;
40 return status;
41 }
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
60 if(m_readOneTime){
61 if(m_runFrom>=8093){
63 }
64 else
65 std::cout<<"MeasuredEcmsSvc, invalid RunFrom, RunFrom should be >=8093"<<std::endl;
66 }
67
68 m_sele = 0;
69 log << MSG::INFO << "initialized successfully" << endreq;
70 return StatusCode::SUCCESS;
71}

◆ isRunNoValid()

bool MeasuredEcmsSvc::isRunNoValid ( )
inlinevirtual

Return true or false for runNo

Implements IMeasuredEcmsSvc.

Definition at line 51 of file MeasuredEcmsSvc.h.

51{ return m_isRunNoValid; }

◆ queryInterface()

StatusCode MeasuredEcmsSvc::queryInterface ( const InterfaceID &  riid,
void **  ppvIF 
)
virtual

Query interface

Definition at line 90 of file MeasuredEcmsSvc.cxx.

91{
92 if (IMeasuredEcmsSvc::interfaceID().versionMatch(riid)) *ppvIF = dynamic_cast<IMeasuredEcmsSvc*>(this);
93 else return Service::queryInterface(riid, ppvIF);
94
95 addRef();
96
97 return StatusCode::SUCCESS;
98}
static const InterfaceID & interfaceID()

◆ readDBTable() [1/2]

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

Definition at line 247 of file MeasuredEcmsSvc.cxx.

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

◆ readDBTable() [2/2]

void MeasuredEcmsSvc::readDBTable ( int  runNo)
protectedvirtual

Read database table

Implements IMeasuredEcmsSvc.

Definition at line 175 of file MeasuredEcmsSvc.cxx.

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

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

◆ triggerDBTable()

int MeasuredEcmsSvc::triggerDBTable ( int  runNo)
protectedvirtual

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

Implements IMeasuredEcmsSvc.

Definition at line 307 of file MeasuredEcmsSvc.cxx.

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

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(), initialize(), and MeasuredEcmsSvc().

◆ m_runFrom

int MeasuredEcmsSvc::m_runFrom

Definition at line 104 of file MeasuredEcmsSvc.h.

Referenced by initialize(), MeasuredEcmsSvc(), and readDBTable().

◆ m_runTo

int MeasuredEcmsSvc::m_runTo

Definition at line 105 of file MeasuredEcmsSvc.h.

Referenced by initialize(), MeasuredEcmsSvc(), and readDBTable().

◆ m_sele


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