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