BOSS 7.0.8
BESIII Offline Software System
Loading...
Searching...
No Matches
OfflineEvtFilterSvc.cxx
Go to the documentation of this file.
2
3#include "GaudiKernel/Kernel.h"
4#include "GaudiKernel/IInterface.h"
5#include "GaudiKernel/StatusCode.h"
6#include "GaudiKernel/SvcFactory.h"
7#include "GaudiKernel/MsgStream.h"
8#include "GaudiKernel/IIncidentSvc.h"
9#include "GaudiKernel/Incident.h"
10#include "GaudiKernel/ISvcLocator.h"
11#include "GaudiKernel/Bootstrap.h"
12#include "GaudiKernel/SmartDataPtr.h"
13#include "GaudiKernel/DataSvc.h"
14
18
19#include <iomanip>
20#include <iostream>
21#include <fstream>
22
23using namespace std;
24
25OfflineEvtFilterSvc::OfflineEvtFilterSvc( const string& name, ISvcLocator* svcloc) :
26 Service (name, svcloc) {
27}
28
30}
31
32StatusCode OfflineEvtFilterSvc::queryInterface(const InterfaceID& riid, void** ppvInterface){
33 if( IID_IOfflineEvtFilterSvc.versionMatch(riid) ){
34 *ppvInterface = static_cast<IOfflineEvtFilterSvc*> (this);
35 } else{
36 return Service::queryInterface(riid, ppvInterface);
37 }
38 return StatusCode::SUCCESS;
39}
40
42 MsgStream log(messageService(), name());
43 log << MSG::INFO << "OfflineEvtFilterSvc::initialize()" << endreq;
44
45 StatusCode sc = Service::initialize();
46 if( sc.isFailure() ) return sc;
47
48 IIncidentSvc* incsvc;
49 sc = service("IncidentSvc", incsvc);
50 int priority = 100;
51 if( sc.isSuccess() ){
52 incsvc -> addListener(this, "NewRun", priority);
53 }
54
55 sc = service("CalibDataSvc", m_pCalDataSvc, true);
56 if( sc == StatusCode::SUCCESS ){
57 log << MSG::INFO << "Retrieve IDataProviderSvc" << endreq;
58 }else{
59 log << MSG::FATAL << "can not get IDataProviderSvc" << endreq;
60 }
61
62 return StatusCode::SUCCESS;
63}
64
66 MsgStream log(messageService(), name());
67 log << MSG::INFO << "OfflineEvtFilterSvc::finalize()" << endreq;
68
69 m_npar = 0;
70 m_flag.clear();
71 m_tBegin.clear();
72 m_tEnd.clear();
73
74 return StatusCode::SUCCESS;
75}
76
77void OfflineEvtFilterSvc::handle(const Incident& inc){
78 MsgStream log( messageService(), name() );
79 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
80
81 if ( inc.type() == "NewRun" ){
82 log << MSG::DEBUG << "NewRun" << endreq;
83
84 if( ! initCalibConst() ){
85 log << MSG::ERROR
86 << "can not initilize OffEvtFilter Constants" << endreq;
87 }
88 }
89}
90
91
92bool OfflineEvtFilterSvc::initCalibConst(){
93 MsgStream log(messageService(), name());
94 log << MSG::INFO << "read calib const from TCDS" << endreq;
95
96 IDataProviderSvc* eventSvc = NULL;
97 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
98 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc,"/Event/EventHeader");
99 if (!eventHeader) {
100 log << MSG::FATAL << "Could not find Event Header" << endreq;
101 return false;
102 }
103
104 // clear calibration constants vectors
105 m_npar = 0;
106 m_flag.clear();
107 m_tBegin.clear();
108 m_tEnd.clear();
109
110 string fullPath = "/Calib/OffEvtFilter";
111 SmartDataPtr<CalibData::OffEvtFilterCal> calConst(m_pCalDataSvc, fullPath);
112 if( ! calConst ){
113 log << MSG::ERROR << "can not get OffEvtFilter via SmartPtr"
114 << endreq;
115 return false;
116 }
117
118 m_runFrom = calConst->getRunFrom();
119 m_runTo = calConst->getRunTo();
120 m_eventFrom = calConst->getEventFrom();
121 m_eventTo = calConst->getEventTo();
122 m_npar = calConst->getNpar();
123
124 std::vector<double> tBegin[2];
125 std::vector<double> tEnd[2];
126
127 for(int i=0; i<m_npar; i++) {
128 int flag = calConst->getFlag(i); // 0 or 1
129 tBegin[flag].push_back(calConst->getTBegin(i));
130 tEnd[flag].push_back(calConst->getTEnd(i));
131 }
132
133 for ( int i = 0; i < 2; ++i ) { // loop for flag: 0 or 1
134 std::vector<double>& _tBegin = tBegin[i];
135 std::vector<double>& _tEnd = tEnd[i];
136 int _nPar = _tBegin.size();
137 // sort
138 if ( _nPar > 1 ) {
139 for ( int j = 0; j < _nPar-1; ++j ) {
140 for ( int k = j+1; k < _nPar; ++k ) {
141 if ( _tBegin[j] > _tBegin[k] ) {
142 double _ttmp = _tBegin[j];
143 _tBegin[j] = _tBegin[k];
144 _tBegin[k] = _ttmp;
145 _ttmp = _tEnd[j];
146 _tEnd[j] = _tEnd[k];
147 _tEnd[k] = _ttmp;
148 }
149 }
150 }
151 }
152 // set to class data members
153 for ( int j = 0; j < _nPar; ++j ) {
154 m_flag.push_back(i); // 0 or 1
155 m_tBegin.push_back(_tBegin[j]);
156 m_tEnd.push_back(_tEnd[j]);
157 }
158 }
159
160 return true;
161}
#define NULL
virtual StatusCode initialize()
OfflineEvtFilterSvc(const std::string &name, ISvcLocator *svcloc)
virtual StatusCode finalize()
void handle(const Incident &)
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)