BOSS 8.0.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 26 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.

17 : base_class( name, svcLoc ) {
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}

Referenced by MeasuredEcmsSvc().

◆ ~MeasuredEcmsSvc()

MeasuredEcmsSvc::~MeasuredEcmsSvc ( )
virtual

Destructor

Definition at line 26 of file MeasuredEcmsSvc.cxx.

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

Member Function Documentation

◆ finalize()

StatusCode MeasuredEcmsSvc::finalize ( )
virtual

Finalize

Definition at line 72 of file MeasuredEcmsSvc.cxx.

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

◆ getAverageEcms()

double MeasuredEcmsSvc::getAverageEcms ( )
inline

Return average Ecms

Definition at line 66 of file MeasuredEcmsSvc.h.

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

◆ getAverageEcmsError()

double MeasuredEcmsSvc::getAverageEcmsError ( )
inline

Return average Ecms error

Definition at line 71 of file MeasuredEcmsSvc.h.

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

◆ getBeamEnergy() [1/2]

double MeasuredEcmsSvc::getBeamEnergy ( )
inline

Return beam energy

Definition at line 58 of file MeasuredEcmsSvc.h.

58{ 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 110 of file MeasuredEcmsSvc.h.

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

◆ getBeamEnergyError()

double MeasuredEcmsSvc::getBeamEnergyError ( )
inline

Return beam energy error

Definition at line 97 of file MeasuredEcmsSvc.h.

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

◆ getEcms() [1/2]

double MeasuredEcmsSvc::getEcms ( )

Return Ecms ( Ecms = beam_energy * 2 )

Definition at line 133 of file MeasuredEcmsSvc.cxx.

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

Referenced by getBeamEnergy(), and 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 156 of file MeasuredEcmsSvc.cxx.

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

◆ getEcmsError()

double MeasuredEcmsSvc::getEcmsError ( )
inline

Return error for Ecms

Definition at line 61 of file MeasuredEcmsSvc.h.

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

◆ getPx()

double MeasuredEcmsSvc::getPx ( )
inline

Return x momentum

Definition at line 82 of file MeasuredEcmsSvc.h.

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

◆ getPy()

double MeasuredEcmsSvc::getPy ( )
inline

Return y momentum

Definition at line 87 of file MeasuredEcmsSvc.h.

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

◆ getPz()

double MeasuredEcmsSvc::getPz ( )
inline

Return z momentum

Definition at line 92 of file MeasuredEcmsSvc.h.

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

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

379 {
380 std::string strRecord;
381 m_isRunNoValid = false;
382
383 MsgStream log( msgSvc(), name() );
384 log << MSG::INFO << "MeasuredEcmsSvc begin read database " << tab << "-" << col << endmsg;
385
386 int runNum = std::abs( runNo );
387
388 if ( runNo < 0 ) log << MSG::INFO << "MeasuredEcmsSvc for MC events" << endmsg;
389 else log << MSG::INFO << "MeasuredEcmsSvc for DT events" << endmsg;
390
391 char stmt[500];
392 snprintf( stmt, 1024, "select %s from %s where %s <= %d and %s >= %d", col, tab, min_col,
393 runNum, max_col, runNum );
394
395 DatabaseRecordVector res;
396 int row_no = m_dbSvc->query( "offlinedb", stmt, res );
397
398 if ( row_no == 0 )
399 {
400 log << MSG::ERROR << "RowNo can not be 0 for " << tab << ", failed to read DB for "
401 << runNo << endmsg;
402 }
403 else
404 {
405 log << MSG::INFO << "MeasuredEcmsSvc first read the runNo, read the " << tab
406 << " database " << runNo << endmsg;
407 strRecord = res[m_sele]->GetString( col );
408 m_isRunNoValid = true;
409 }
410
411 return strRecord;
412}

◆ getSampleName()

double MeasuredEcmsSvc::getSampleName ( )
inline

Return sample name

Definition at line 77 of file MeasuredEcmsSvc.h.

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

◆ handle()

void MeasuredEcmsSvc::handle ( const Incident & inc)

Handle. Process after initialization

Definition at line 99 of file MeasuredEcmsSvc.cxx.

99 {
100 MsgStream log( msgSvc(), name() );
101 log << MSG::DEBUG << "handle: " << inc.type() << endmsg;
102
103 SmartDataPtr<Event::EventHeader> eventHeader( m_eventSvc, "/Event/EventHeader" );
104 int runNo = eventHeader->runNumber();
105 m_runNo = std::abs( runNo );
106 if ( inc.type() == "NewRun" )
107 {
108 log << MSG::INFO << "RunNo is new, call the readMeasuredEcms again" << endmsg;
109 if ( !m_readOneTime )
110 {
111 m_sele = 0;
113 }
114 else
115 {
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 {
121 m_isRunNoValid = true;
122 m_sele = m_mapBeamE[run];
123 }
124 else
125 {
126 std::cout << "MeasuredEcmsSvc, could not get Ecm infor in handle new run" << std::endl;
127 }
128 }
129 }
130}
std::map< int, int > m_mapBeamE

◆ initialize()

StatusCode MeasuredEcmsSvc::initialize ( )
virtual

Query interface Initialize

Definition at line 32 of file MeasuredEcmsSvc.cxx.

32 {
33 MsgStream log( msgSvc(), name() );
34 log << MSG::INFO << "initialize begin here" << endmsg;
35
36 StatusCode status = Service::initialize();
37 if ( !status.isSuccess() )
38 {
39 log << MSG::ERROR << "can not initialize" << endmsg;
40 return status;
41 }
42 IIncidentSvc* incsvc;
43 status = service( "IncidentSvc", incsvc );
44 int priority = 100;
45 if ( status.isSuccess() ) incsvc->addListener( this, "NewRun", priority );
46
47 status = serviceLocator()->service( "DatabaseSvc", m_dbSvc, true );
48 if ( !status.isSuccess() )
49 {
50 log << MSG::ERROR << "unable to find DatabaseSvc" << endmsg;
51 return status;
52 }
53
54 status = serviceLocator()->service( "EventDataSvc", m_eventSvc, true );
55 if ( !status.isSuccess() )
56 {
57 log << MSG::ERROR << "unable to find EventDataSvc " << endmsg;
58 return status;
59 }
60 if ( m_readOneTime )
61 {
62 if ( m_runFrom >= 8093 ) { readDBTable( m_runFrom, m_runTo ); }
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" << endmsg;
68 return StatusCode::SUCCESS;
69}

◆ isRunNoValid()

bool MeasuredEcmsSvc::isRunNoValid ( )
inline

Return true or false for runNo

Definition at line 52 of file MeasuredEcmsSvc.h.

52{ return m_isRunNoValid; }

◆ readDBTable() [1/2]

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

Definition at line 269 of file MeasuredEcmsSvc.cxx.

269 {
270 MsgStream log( msgSvc(), name() );
271 log << MSG::INFO << "begin read database MeasuredEcmsSvc from " << m_runFrom << " to "
272 << m_runTo << endmsg;
273 m_dbRecordVector.clear();
274
275 m_rowNo1 = 0;
276 m_rowNo2 = 0;
277 m_isRunNoValid = false;
278 char stmt[400];
279
280 if ( ( runFrom >= 23463 && runFrom <= 38140 ) || ( runFrom >= 47543 && runFrom <= 51498 ) )
281 {
282 if ( ( runTo >= 23463 && runTo <= 38140 ) || ( runTo >= 47543 && runTo <= 51498 ) )
283 {
284 log << MSG::INFO << "read table MeasuredEcms2 for " << runFrom << ":" << runTo << endmsg;
285 snprintf( stmt, 1024,
286 "select sample, RunFrom, RunTo, Ecms, Ecms_err, Ave_Ecms, Ave_Ecms_err from "
287 "MeasuredEcms2 where RunFrom >= %d and RunTo <= %d",
288 runFrom, runTo );
289 m_tableOption = 1;
290 }
291 }
292 else if ( ( runFrom >= 11414 && runFrom <= 23454 ) ||
293 ( runFrom >= 43716 && runFrom <= 47066 ) ||
294 ( runFrom >= 70522 && runFrom <= 73929 ) ||
295 ( runFrom >= 74031 && runFrom <= 78536 ) ||
296 ( runFrom >= 78615 && runFrom <= 81631 ) )
297 {
298 if ( ( runTo >= 11414 && runTo <= 23454 ) || ( runTo >= 43716 && runTo <= 47066 ) ||
299 ( runFrom >= 70522 && runFrom <= 73929 ) ||
300 ( runFrom >= 74031 && runFrom <= 78536 ) || ( runFrom >= 78615 && runFrom <= 81631 ) )
301 {
302 log << MSG::INFO << "read table RunParams for " << runFrom << ":" << runTo << endmsg;
303 snprintf( stmt, 1024,
304 "select run_number, beam_energy, px, py, pz, beam_energy_err from RunParams "
305 "where run_number >= %d and run_number <= %d",
306 runFrom, runTo );
307 m_tableOption = 2;
308 }
309 }
310 else { m_tableOption = -1; }
311
312 if ( m_tableOption == 1 || m_tableOption == 2 )
313 {
314 int rowNo = m_dbSvc->query( "offlinedb", stmt, m_dbRecordVector );
315 if ( rowNo == 0 )
316 {
317 log << MSG::ERROR << "RowNo can not be 0, failed to read DB for " << runFrom << ":"
318 << runTo << endmsg;
319 cout << "RowNo can not be 0, failed to read DB for " << runFrom << ":" << runTo << endl;
320 }
321 else
322 {
323 if ( m_tableOption == 1 ) m_rowNo1 = 1;
324 if ( m_tableOption == 2 ) m_rowNo2 = 1;
325 log << MSG::INFO << "initialize the DatabaseRecordVector OK for " << runFrom << ":"
326 << runTo << endmsg;
327 cout << "MeasuredEcmsSvc: initialize the DatabaseRecordVector OK for " << runFrom << ":"
328 << runTo << ", Nrecord = " << rowNo << "." << endl;
329 m_isRunNoValid = true;
330 }
331 if ( m_rowNo2 == 1 )
332 {
333 for ( int i = 0; i < rowNo; i++ )
334 {
335 int runnumber = m_dbRecordVector[i]->GetInt( "run_number" );
336 m_mapBeamE[runnumber] = i;
337 }
338 }
339 if ( m_rowNo1 == 1 )
340 {
341 for ( int i = 0; i < rowNo; i++ )
342 {
343 int run0 = m_dbRecordVector[i]->GetInt( "RunFrom" );
344 int run1 = m_dbRecordVector[i]->GetInt( "RunTo" );
345 for ( int j = run0; j <= run1; j++ ) { m_mapBeamE[j] = i; }
346 }
347 }
348 }
349}

◆ readDBTable() [2/2]

void MeasuredEcmsSvc::readDBTable ( int runNo)
protected

Read database table

Definition at line 183 of file MeasuredEcmsSvc.cxx.

183 {
184 if ( runNo == m_runflag ) return;
185 m_runflag = runNo;
186 MsgStream log( msgSvc(), name() );
187 log << MSG::INFO << "begin read database MeasuredEcmsSvc" << endmsg;
188
189 m_dbRecordVector.clear();
190
191 m_rowNo1 = 0;
192 m_rowNo2 = 0;
193
194 m_isRunNoValid = false;
195 int runNum = std::abs( runNo );
196
197 if ( runNo < 0 ) log << MSG::INFO << "MeasuredEcmsSvc for MC events" << endmsg;
198 else log << MSG::INFO << "MeasuredEcmsSvc for DT events" << endmsg;
199
200 triggerDBTable( runNum );
201
202 char stmt[400];
203
204 char stmt1[400];
205 char stmt2[400];
206
207 switch ( m_tableOption )
208 {
209 case 1:
210 snprintf( stmt, 1024,
211 "select sample, RunFrom, RunTo, Ecms, Ecms_err, Ave_Ecms, Ave_Ecms_err from "
212 "MeasuredEcms2 where RunFrom <= %d and RunTo >= %d",
213 runNum, runNum );
214 break;
215
216 case 2:
217 snprintf(
218 stmt, 1024,
219 "select beam_energy, px, py, pz, beam_energy_err from RunParams where run_number = %d",
220 runNum );
221 break;
222
223 default:
224 snprintf( stmt1, 1024,
225 "select sample, RunFrom, RunTo, Ecms, Ecms_err, Ave_Ecms, Ave_Ecms_err from "
226 "MeasuredEcms2 where RunFrom <= %d and RunTo >= %d",
227 runNum, runNum );
228 snprintf(
229 stmt2, 1024,
230 "select beam_energy, px, py, pz, beam_energy_err from RunParams where run_number = %d",
231 runNum );
232 break;
233 }
234
235 if ( m_tableOption == 1 || m_tableOption == 2 )
236 {
237 int rowNo = m_dbSvc->query( "offlinedb", stmt, m_dbRecordVector );
238
239 if ( rowNo == 0 )
240 { log << MSG::ERROR << "RowNo can not be 0, failed to read DB for " << runNo << endmsg; }
241 else
242 {
243 if ( m_tableOption == 1 ) m_rowNo1 = 1;
244 if ( m_tableOption == 2 ) m_rowNo2 = 1;
245 log << MSG::INFO << "initialize the DatabaseRecordVector OK for " << runNo << endmsg;
246 m_isRunNoValid = true;
247 }
248 }
249 else
250 {
251 m_rowNo1 = m_dbSvc->query( "offlinedb", stmt1, m_dbRecordVector );
252 if ( m_rowNo1 == 0 )
253 {
254 m_dbRecordVector.clear();
255 m_rowNo2 = m_dbSvc->query( "offlinedb", stmt2, m_dbRecordVector );
256 }
257
258 if ( m_rowNo1 == 0 && m_rowNo2 == 0 )
259 { log << MSG::ERROR << "RowNo can not be 0, failed to read DB for " << runNo << endmsg; }
260 else
261 {
262 log << MSG::INFO << "initialize the DatabaseRecordVector OK for " << runNo << endmsg;
263 m_isRunNoValid = true;
264 }
265 }
266}
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 352 of file MeasuredEcmsSvc.cxx.

352 {
353 MsgStream log( msgSvc(), name() );
354 log << MSG::INFO << "triggerDBTable based on runNo" << endl;
355
356 int runNum = std::abs( runNo );
357
358 if ( ( runNum >= 23463 && runNum <= 38140 ) || ( runNum >= 47543 && runNum <= 51498 ) )
359 {
360 log << MSG::INFO << "read table MeasuredEcms2 for " << runNo << endmsg;
361 m_tableOption = 1;
362 }
363
364 else if ( ( runNum >= 11414 && runNum <= 23454 ) || ( runNum >= 43716 && runNum <= 47066 ) ||
365 ( runNum >= 70522 && runNum <= 73929 ) || ( runNum >= 74031 && runNum <= 78536 ) ||
366 ( runNum >= 78615 && runNum <= 81631 ) )
367 {
368 log << MSG::INFO << "read table RunParams for " << runNo << endmsg;
369 m_tableOption = 2;
370 }
371
372 else m_tableOption = -1;
373
374 return m_tableOption;
375}

Referenced by readDBTable().

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

Referenced by handle(), and readDBTable().

◆ m_readOneTime

bool MeasuredEcmsSvc::m_readOneTime

Definition at line 125 of file MeasuredEcmsSvc.h.

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

◆ m_runFrom

int MeasuredEcmsSvc::m_runFrom

Definition at line 126 of file MeasuredEcmsSvc.h.

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

◆ m_runTo

int MeasuredEcmsSvc::m_runTo

Definition at line 127 of file MeasuredEcmsSvc.h.

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

◆ m_sele


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