5#include "RootCnvSvc/RootEvtSelector.h"
6#include "EventModel/EventModel.h"
7#include "GaudiKernel/GenericAddress.h"
8#include "GaudiKernel/IAddressCreator.h"
9#include "GaudiKernel/IDataManagerSvc.h"
10#include "GaudiKernel/MsgStream.h"
11#include "GaudiKernel/StatusCode.h"
12#include "RootCnvSvc/RootEventContext.h"
13#include "RootCnvSvc/RootInterface.h"
14#include "TagFilterSvc/ITagFilterSvc.h"
17#include "GaudiKernel/Bootstrap.h"
18#include "GaudiKernel/IAppMgrUI.h"
19#include "GaudiKernel/IProperty.h"
20#include "GaudiKernel/ISvcLocator.h"
21#include "GaudiKernel/SmartIF.h"
39 : base_class( name, svcloc ), p_beginContext( 0 ), p_endContext( 0 ) {
42 declareProperty(
"Input", m_jobInput =
"ROOT" );
49 MsgStream log(
msgSvc(), name() );
50 StatusCode sc = Service::initialize();
51 log << MSG::DEBUG <<
"RootEvtSelector::initialize" << endmsg;
56 else { log << MSG::ERROR <<
"Unable to initialize service " << endmsg; }
58 if ( m_jobInput.value() !=
" " )
63 log << MSG::ERROR <<
"Unable to get input value" << endmsg;
69 sc = serviceLocator()->service(
"EventCnvSvc", m_addrCreator );
70 if ( !sc.isSuccess() )
72 log << MSG::ERROR <<
"Unable to localize interface IID_IAddressCreator from service:"
73 <<
"RootEventSelector" << endmsg;
78 IDataManagerSvc* eds = 0;
79 sc = serviceLocator()->service(
"EventDataSvc", eds,
true );
80 if ( !sc.isSuccess() )
82 log << MSG::ERROR <<
"Unable to localize interface IID_IDataManagerSvc "
83 <<
"from RootEventSelector" << endmsg;
87 m_rootCLID = eds->rootCLID();
91 log << MSG::INFO <<
"currentFile in RootEvtSelector::initialize "
92 << m_rootInterface->getCurrentFileName() << endmsg;
93 if ( !m_rootInterface )
94 log << MSG::ERROR <<
"Unable to start Root service within RootCnvSvc" << endmsg;
99 ISvcLocator* svcLocator = Gaudi::svcLocator();
100 StatusCode status = svcLocator->service(
"TagFilterSvc", m_tagFilterSvc );
101 if ( status.isSuccess() ) { log << MSG::INFO <<
"get the TagFilterSvc" << endmsg; }
102 else { log << MSG::WARNING <<
"could not get the TagFilterSvc. Ignore it." << endmsg; }
104 auto tag_files = m_tagFilterSvc->getTagFiles();
105 cout <<
"RootEvtSelector, tag_files: " << tag_files.size() << endl;
107 m_rootInterface->setTagInputFile( tag_files );
111 vector<string> dstFiles = m_tagFilterSvc->getDstFiles();
112 int size = dstFiles.size();
113 std::string treeName =
"Event";
115 for (
int i = 0; i < size; i++ )
117 std::cout <<
"RootEvtSelector, dstFile: " << dstFiles[i] << std::endl;
118 m_rootInterface->addInput( treeName, dstFiles[i].c_str() );
125 MsgStream log(
msgSvc(), name() );
126 m_criteria = criteria;
128 if ( criteria ==
"ROOT" )
130 log << MSG::INFO <<
"RootEvtSelector input has been set to ROOT" << endmsg;
131 m_criteriaType =
ROOT;
133 else if ( criteria ==
"NONE" )
135 m_criteriaType = NONE;
136 log << MSG::INFO <<
"RootEvtSelector input has been set to NONE" << endmsg;
140 log << MSG::ERROR <<
"Invalid Event Selection Criteria: " << criteria << endmsg;
141 return StatusCode::FAILURE;
143 return StatusCode::SUCCESS;
148 return ( StatusCode::SUCCESS );
158 for (
int i = 0; i < jump; ++i )
160 StatusCode status =
next( ctxt );
161 if ( !status.isSuccess() ) {
return status; }
163 return StatusCode::SUCCESS;
165 return StatusCode::FAILURE;
169 MsgStream log(
msgSvc(), name() );
170 log << MSG::ERROR <<
"RootEvtSelector::previous() not implemented" << endmsg;
171 return ( StatusCode::FAILURE );
179 if ( it.identifier() == p_endContext->identifier() )
181 MsgStream log(
msgSvc(), name() );
182 log << MSG::DEBUG <<
"last(): Last event in InputStream." << endmsg;
183 return ( StatusCode::SUCCESS );
185 return ( StatusCode::FAILURE );
189 IEvtSelector::Context& )
const {
190 return ( StatusCode::SUCCESS );
194 MsgStream log(
msgSvc(), name() );
195 log << MSG::ERROR <<
"RootEvtSelector::rewind() not implemented" << endmsg;
196 return ( StatusCode::FAILURE );
200 return ( StatusCode::SUCCESS );
204 IOpaqueAddress*& iop )
const {
206 return ( StatusCode::SUCCESS );
212 MsgStream log(
msgSvc(), name() );
213 static std::string tempFile =
"";
214 log << MSG::DEBUG <<
"current file: " << m_rootInterface->getCurrentFileName() << endmsg;
216 static std::string tagFile;
218 static std::vector<int> ventry;
219 int num1 = m_rootInterface->getCurrentFileNum();
220 int num2 = m_rootInterface->getTotalFileNum();
222 if ( tempFile != m_rootInterface->getCurrentFileName() )
224 tempFile = m_rootInterface->getCurrentFileName();
225 log << MSG::DEBUG <<
"temp file: " << tempFile << endmsg;
228 log << MSG::DEBUG <<
"num1: " <<
num1 <<
" num2: " << num2 << endmsg;
229 tagFile = ( m_rootInterface->getTagInputFile() )[
num1];
230 log << MSG::DEBUG <<
"tag file: " << tagFile << endmsg;
231 m_tagFilterSvc->getVEntry( tagFile, ventry );
235 log << MSG::DEBUG <<
"ventry i: " << i << endmsg;
236 log << MSG::DEBUG <<
"ventry size: " << ventry.size() << endmsg;
237 if ( i < ventry.size() )
239 ( *m_recId ) = ventry[i];
240 log << MSG::DEBUG <<
"ventry[i]: " << ventry[i] << endmsg;
242 else ( *m_recId ) = -1;
244 log << MSG::DEBUG <<
"(*m_recId): " << ( *m_recId ) << endmsg;
246 int vs = ventry.size();
248 if ( ( i > ( vs - 1 ) ) && (
num1 < ( num2 - 1 ) ) )
250 bool endAll = m_rootInterface->checkEndOfTree();
253 if ( ( i > ( vs - 1 ) ) && (
num1 == ( num2 - 1 ) ) ) ( *m_recId ) = -1;
257 MsgStream log(
msgSvc(), name() );
258 if ( m_criteriaType ==
ROOT )
260 log << MSG::INFO <<
"m_criteriaType == ROOT" << endmsg;
261 if ( m_rootInterface->getSelectFromTag() != 0 )
264 if ( ( *m_recId ) < 0 )
return StatusCode::FAILURE;
275 static int entry = 0;
277 bool endOfFile = m_rootInterface->getEOF();
280 ( entry > m_rootInterface->getEntries() && m_rootInterface->getEntries() >= 0 );
281 if ( maxEntry ) entry = 1;
282 log << MSG::INFO <<
"entry = " << entry <<
" " << maxEntry <<
" " << endOfFile
284 if ( endOfFile || maxEntry )
286 bool endAll = m_rootInterface->checkEndOfTree();
290 return StatusCode::FAILURE;
296 else if ( m_criteriaType == NONE )
298 log << MSG::DEBUG <<
"Reading Event " << ( *m_recId ) << endmsg;
300 if ( ( *m_recId ) > m_evtMax ) {
return StatusCode::FAILURE; }
305 log << MSG::FATAL <<
"Cannot iterate a dead iterator" << endmsg;
306 return StatusCode::FAILURE;
309 log << MSG::DEBUG <<
"Reading Event " << ( *m_recId ) << endmsg;
310 log << MSG::DEBUG <<
"Max Event " << m_evtMax << endmsg;
311 return StatusCode::SUCCESS;
315 if ( riid == IID_IRootEvtSelector ) { *ppvInterface = (
RootEvtSelector*)
this; }
316 else if ( riid == IEvtSelector::interfaceID() ) { *ppvInterface = (IEvtSelector*)
this; }
317 else if ( riid == IProperty::interfaceID() ) { *ppvInterface = (IProperty*)
this; }
318 else {
return Service::queryInterface( riid, ppvInterface ); }
320 return StatusCode::SUCCESS;
323StatusCode RootEvtSelector::getMaxEvent() {
324 IProperty* appPropMgr = 0;
326 serviceLocator()->getService(
"ApplicationMgr", IProperty::interfaceID(),
327 reinterpret_cast<IInterface*&
>( appPropMgr ) );
328 if ( status.isFailure() )
return status;
330 IntegerProperty evtMax(
"EvtMax", 0 );
331 status = appPropMgr->getProperty( &evtMax );
332 if ( status.isFailure() )
return status;
334 m_evtMax = evtMax.value();
DECLARE_COMPONENT(BesBdkRc)
const long int ROOT_StorageType
This class provides the Context for RootEventSelector.
RootEvtSelector performs the function of controlling the ApplicationMgr loop.
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
virtual StatusCode setCriteria(const std::string &criteria)
virtual StatusCode rewind(Context &it) const
virtual StatusCode resetCriteria(const std::string &criteria, Context &context) const
virtual StatusCode initialize()
virtual StatusCode last(Context &it) const
virtual StatusCode releaseContext(Context *&it) const
void getEntryFromTag() const
virtual StatusCode previous(Context &it) const
virtual StatusCode createContext(Context *&it) const
virtual StatusCode createAddress(const Context &it, IOpaqueAddress *&iop) const
RootEvtSelector(const std::string &name, ISvcLocator *svcloc)
static RootInterface * Instance(const std::string &name)
singleton behaviour