19 declareProperty(
"ReadOneTime", m_readOneTime=
false);
20 declareProperty(
"RunFrom", m_runFrom=8093);
21 declareProperty(
"RunTo", m_runTo=9025);
28 MsgStream log(
msgSvc(), name());
29 log << MSG::INFO <<
"destructor" << endreq;
35 MsgStream log(
msgSvc(), name());
36 log << MSG::INFO <<
"initialize begin here" << endreq;
38 StatusCode status = Service::initialize();
39 if (! status.isSuccess()) {
40 log << MSG::ERROR <<
"can not initialize" << endreq;
44 status = service(
"IncidentSvc", incsvc);
46 if (status.isSuccess()) incsvc->addListener(
this,
"NewRun", priority);
48 status = serviceLocator()->service(
"DatabaseSvc", m_dbSvc,
true);
49 if (! status.isSuccess()) {
50 log << MSG::ERROR<<
"unable to find DatabaseSvc" << endreq;
54 status = serviceLocator()->service(
"EventDataSvc", m_eventSvc,
true);
55 if (! status.isSuccess()) {
56 log << MSG::ERROR <<
"unable to find EventDataSvc " << endreq;
64 std::cout<<
"MeasuredEcmsSvc, invalid RunFrom, RunFrom should be >=8093"<<std::endl;
67 log << MSG::INFO <<
"initialized successfully" << endreq;
68 return StatusCode::SUCCESS;
74 MsgStream log(
msgSvc(), name());
75 log << MSG::INFO <<
"finalize begin here" << endreq;
77 StatusCode status = Service::finalize();
78 if (! status.isSuccess()) {
79 log << MSG::ERROR <<
"can not finalize" << endreq;
83 log << MSG::INFO <<
"finalized successfully" << endreq;
84 return StatusCode::SUCCESS;
101 MsgStream log(messageService(), name());
102 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
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;
113 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,
"/Event/EventHeader");
114 int run = eventHeader->runNumber();
117 m_isRunNoValid =
true;
120 std::cout<<
"MeasuredEcmsSvc, could not get Ecm infor in handle new run"<<std::endl;
129 switch (m_tableOption) {
131 return (m_rowNo1 != 0) ? (double)m_dbRecordVector[
m_sele]->GetDouble(
"Ecms") : 0.00;
135 return (m_rowNo2 != 0) ? (double)m_dbRecordVector[
m_sele]->GetDouble(
"beam_energy") * 2.00 : 0.00;
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;
150 m_runNo = std::abs(
runNo);
154 switch (m_tableOption) {
156 return (m_rowNo1 != 0) ? (double)m_dbRecordVector[
m_sele]->GetDouble(
"Ecms") : 0.00;
160 return (m_rowNo2 != 0) ? (double)m_dbRecordVector[
m_sele]->GetDouble(
"beam_energy") * 2.00 : 0.00;
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;
174 if (
runNo == m_runflag)
return;
176 MsgStream log(
msgSvc(), name());
177 log << MSG::INFO <<
"begin read database MeasuredEcmsSvc" << endreq;
179 m_dbRecordVector.
clear();
184 m_isRunNoValid =
false;
185 int runNum = std::abs(
runNo);
187 if (
runNo < 0) log << MSG::INFO <<
"MeasuredEcmsSvc for MC events" << endreq;
188 else log << MSG::INFO <<
"MeasuredEcmsSvc for DT events" << endreq;
197 switch(m_tableOption) {
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);
203 snprintf(stmt, 1024,
"select beam_energy, px, py, pz, beam_energy_err from RunParams where run_number = %d", runNum);
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);
212 if (m_tableOption == 1 || m_tableOption == 2) {
213 int rowNo = m_dbSvc->
query(
"offlinedb", stmt, m_dbRecordVector);
216 log << MSG::ERROR <<
"RowNo can not be 0, failed to read DB for " <<
runNo << endreq;
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;
226 m_rowNo1 = m_dbSvc->
query(
"offlinedb", stmt1, m_dbRecordVector);
228 m_dbRecordVector.
clear();
229 m_rowNo2 = m_dbSvc->
query(
"offlinedb", stmt2, m_dbRecordVector);
232 if (m_rowNo1 == 0 && m_rowNo2 == 0) {
233 log << MSG::ERROR <<
"RowNo can not be 0, failed to read DB for " <<
runNo << endreq;
236 log << MSG::INFO <<
"initialize the DatabaseRecordVector OK for " <<
runNo << endreq;
237 m_isRunNoValid =
true;
245 MsgStream log(
msgSvc(), name());
246 log << MSG::INFO <<
"begin read database MeasuredEcmsSvc from " <<
m_runFrom <<
" to " <<
m_runTo << endreq;
247 m_dbRecordVector.
clear();
251 m_isRunNoValid =
false;
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);
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);
272 if (m_tableOption == 1 || m_tableOption == 2) {
273 int rowNo = m_dbSvc->
query(
"offlinedb", stmt, m_dbRecordVector);
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;
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;
285 for (
int i=0; i<rowNo; i++ ) {
286 int runnumber = m_dbRecordVector[i]->GetInt(
"run_number");
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++) {
305 MsgStream log(
msgSvc(), name());
306 log << MSG::INFO <<
"triggerDBTable based on runNo" << endl;
308 int runNum = std::abs(
runNo);
310 if ((runNum >= 23463 && runNum <= 38140) || (runNum >= 47543 && runNum <= 51498)) {
311 log << MSG::INFO <<
"read table MeasuredEcms2 for " <<
runNo << endreq;
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;
320 else m_tableOption = -1;
322 return m_tableOption;
329 std::string strRecord;
330 m_isRunNoValid =
false;
332 MsgStream log(
msgSvc(), name());
333 log << MSG::INFO <<
"MeasuredEcmsSvc begin read database " << tab <<
"-" << col << endreq;
335 int runNum = std::abs(
runNo);
337 if (
runNo < 0) log << MSG::INFO <<
"MeasuredEcmsSvc for MC events" << endreq;
338 else log << MSG::INFO <<
"MeasuredEcmsSvc for DT events" << endreq;
341 snprintf(stmt, 1024,
"select %s from %s where %s <= %d and %s >= %d", col, tab, min_col, runNum, max_col, runNum);
344 int row_no = m_dbSvc->
query(
"offlinedb", stmt, res);
347 log << MSG::ERROR <<
"RowNo can not be 0 for " << tab <<
", failed to read DB for " <<
runNo << endreq;
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;
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0
std::map< int, int > m_mapBeamE
virtual ~MeasuredEcmsSvc()
void handle(const Incident &)
int triggerDBTable(int runNo)
virtual StatusCode initialize()
virtual StatusCode finalize()
std::string getRecord(int runNo, char *tab, char *col, char *min_col, char *max_col)
void readDBTable(int runNo)