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