5#include "GaudiKernel/MsgStream.h"
6#include "GaudiKernel/StatusCode.h"
7#include "GaudiKernel/SvcFactory.h"
8#include "GaudiKernel/IDataManagerSvc.h"
9#include "GaudiKernel/IAddressCreator.h"
10#include "GaudiKernel/GenericAddress.h"
11#include "RootCnvSvc/RootEvtSelector.h"
12#include "RootCnvSvc/RootInterface.h"
13#include "RootCnvSvc/RootEventContext.h"
14#include "EventModel/EventModel.h"
15#include "TagFilterSvc/ITagFilterSvc.h"
16#include "TagFilterSvc/TagFilterSvc.h"
18#include "GaudiKernel/SmartIF.h"
19#include "GaudiKernel/Bootstrap.h"
20#include "GaudiKernel/IAppMgrUI.h"
21#include "GaudiKernel/IProperty.h"
22#include "GaudiKernel/ISvcLocator.h"
38 : Service( name, svcloc),
43 declareProperty(
"Input", m_jobInput=
"ROOT");
52 MsgStream log(
msgSvc(), name());
53 StatusCode sc = Service::initialize();
54 log << MSG::DEBUG <<
"RootEvtSelector::initialize" << endreq;
if( sc.isSuccess() ) {
57 log << MSG::ERROR <<
"Unable to initialize service " << endreq;
60 if(m_jobInput.value() !=
" "){
63 log << MSG::ERROR <<
"Unable to get input value" << endreq;
69 sc = serviceLocator()->service(
"EventCnvSvc", m_addrCreator);
70 if( !sc.isSuccess() ) {
72 "Unable to localize interface IID_IAddressCreator from service:"
73 <<
"RootEventSelector"
79 IDataManagerSvc* eds = 0;
80 sc = serviceLocator()->service(
"EventDataSvc", eds,
true);
81 if( !sc.isSuccess() ) {
83 <<
"Unable to localize interface IID_IDataManagerSvc "
84 <<
"from RootEventSelector"
89 m_rootCLID = eds->rootCLID();
93 log << MSG::INFO <<
"currentFile in RootEvtSelector::initialize "<<m_rootInterface->
getCurrentFileName()<<endreq;
94 if (!m_rootInterface) log << MSG::ERROR <<
"Unable to start Root service within RootCnvSvc" << endreq;
102 ISvcLocator* svcLocator = Gaudi::svcLocator();
103 StatusCode status = svcLocator->service(
"TagFilterSvc",tmpSvc);
104 if (status.isSuccess()) {
105 log << MSG::INFO <<
"get the TagFilterSvc" << endreq;
108 log << MSG::WARNING <<
"could not get the TagFilterSvc. Ignore it." << endreq;
113 vector<string> dstFiles = m_tagFilterSvc->
getDstFiles();
114 int size = dstFiles.size();
115 std::string treeName=
"Event";
117 for(
int i=0;i<size;i++)
119 std::cout<<
"RootEvtSelector, dstFile: "<<dstFiles[i]<<std::endl;
120 m_rootInterface->
addInput(treeName, dstFiles[i].c_str());
127 MsgStream log(
msgSvc(), name());
128 m_criteria = criteria;
130 if( criteria ==
"ROOT" ) {
131 log << MSG::INFO <<
"RootEvtSelector input has been set to ROOT" << endreq;
132 m_criteriaType =
ROOT;
133 }
else if( criteria ==
"NONE"){
134 m_criteriaType = NONE;
135 log << MSG::INFO <<
"RootEvtSelector input has been set to NONE" << endreq;
138 log << MSG::ERROR <<
"Invalid Event Selection Criteria: " << criteria << endreq;
139 return StatusCode::FAILURE;
141 return StatusCode::SUCCESS;
148 return(StatusCode::SUCCESS);
160 for (
int i = 0; i < jump; ++i ) {
161 StatusCode status =
next(ctxt);
162 if ( !status.isSuccess() ) {
166 return StatusCode::SUCCESS;
168 return StatusCode::FAILURE;
172 MsgStream log(messageService(), name());
173 log << MSG::ERROR <<
"RootEvtSelector::previous() not implemented" << endreq;
174 return(StatusCode::FAILURE);
182 if (it.identifier() == p_endContext->
identifier()) {
183 MsgStream log(messageService(), name());
184 log << MSG::DEBUG <<
"last(): Last event in InputStream." <<endreq;
185 return(StatusCode::SUCCESS);
187 return (StatusCode::FAILURE);
191 return(StatusCode::SUCCESS);
196 MsgStream log(messageService(), name());
197 log << MSG::ERROR <<
"RootEvtSelector::rewind() not implemented" << endreq;
198 return(StatusCode::FAILURE);
203 return(StatusCode::SUCCESS);
207 IOpaqueAddress*& iop)
const {
209 return(StatusCode::SUCCESS);
214 MsgStream log(messageService(), name());
215 static std::string tempFile =
"";
218 static std::string tagFile;
220 static std::vector<int> ventry;
228 log << MSG::DEBUG<<
"temp file: "<<tempFile<<endreq;
231 log << MSG::DEBUG<<
"num1: "<<
num1<<
" num2: "<<num2<<endreq;
233 log << MSG::DEBUG <<
"tag file: "<<tagFile<<endreq;
234 m_tagFilterSvc->
getVEntry(tagFile, ventry);
238 log << MSG::DEBUG<<
"ventry i: "<<i<<endreq;
239 log << MSG::DEBUG<<
"ventry size: "<<ventry.size()<<endreq;
242 (*m_recId)=ventry[i];
243 log << MSG::DEBUG<<
"ventry[i]: "<<ventry[i]<<endreq;
248 log << MSG::DEBUG<<
"(*m_recId): "<<(*m_recId)<<endreq;
250 int vs = ventry.size();
252 if( (i>(vs-1)) && (
num1<(num2-1)))
257 if( (i>(vs-1)) && (
num1==(num2-1)))
263 MsgStream log(
msgSvc(), name());
264 if(m_criteriaType ==
ROOT)
266 log<<MSG::INFO<<
"m_criteriaType == ROOT"<<endreq;
271 return StatusCode::FAILURE;
282 static int entry = 0;
284 bool endOfFile = m_rootInterface->
getEOF();
287 if(maxEntry) entry =1;
288 log<<MSG::INFO<<
"entry = "<<entry<<
" "<<maxEntry<<
" "<<endOfFile<<endreq;
289 if(endOfFile || maxEntry){
293 return StatusCode::FAILURE;
299 else if( m_criteriaType == NONE)
301 log << MSG::DEBUG <<
"Reading Event " << (*m_recId) << endreq;
303 if((*m_recId) > m_evtMax) {
304 return StatusCode::FAILURE;
308 log << MSG::FATAL <<
"Cannot iterate a dead iterator" << endreq;
309 return StatusCode::FAILURE;
312 log << MSG::DEBUG <<
"Reading Event " << (*m_recId) << endreq;
313 log << MSG::DEBUG <<
"Max Event " << m_evtMax << endreq;
314 return StatusCode::SUCCESS;
318 if ( riid == IID_IRootEvtSelector ) {
321 else if ( riid == IEvtSelector::interfaceID() ) {
322 *ppvInterface = (IEvtSelector*)
this;
324 else if ( riid == IProperty::interfaceID() ) {
325 *ppvInterface = (IProperty*)
this;
328 return Service::queryInterface( riid, ppvInterface );
334StatusCode RootEvtSelector::getMaxEvent() {
335 IProperty* appPropMgr=0;
337 serviceLocator()->getService(
"ApplicationMgr", IProperty::interfaceID(),
338 reinterpret_cast<IInterface*&
>( appPropMgr ));
339 if( status.isFailure() )
return status;
341 IntegerProperty evtMax(
"EvtMax",0);
342 status = appPropMgr->getProperty( &evtMax );
343 if (status.isFailure())
return status;
345 m_evtMax = evtMax.value();
const long int ROOT_StorageType
const long int ROOT_StorageType
This class provides the Context for RootEventSelector.
virtual void * identifier() const
Inequality operator.
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)
virtual int getTotalFileNum()
virtual bool getSelectFromTag()
virtual bool checkEndOfTree()
check if all the files is over 2005-11-28
virtual Int_t getEntries()
get nr of entries
virtual void setTagInputFile(std::vector< std::string > input)
virtual bool getEOF()
get EOF flag
virtual StatusCode addInput(const std::string &treename, const std::string &file)
add input tree to the list
static RootInterface * Instance(MsgStream log)
singleton behaviour
virtual std::vector< std::string > getTagInputFile()
virtual int getCurrentFileNum()
virtual std::string getCurrentFileName()
vector< string > getTagFiles()
vector< string > getDstFiles()
StatusCode getVEntry(string, vector< int > &)