ATLAS Offline Software
Loading...
Searching...
No Matches
RootNtupleEventSelector.h
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5*/
6
7// RootNtupleEventSelector.h
8// Header file for class RootNtupleEventSelector
9// Author: S.Binet<binet@cern.ch>
11#ifndef ATHENAROOTCOMPS_ATHENA_ROOTNTUPLEEVENTSELECTOR_H
12#define ATHENAROOTCOMPS_ATHENA_ROOTNTUPLEEVENTSELECTOR_H 1
13
14// STL includes
15#include <unordered_map>
16
17// framework includes
19#include "GaudiKernel/IEvtSelector.h"
20#include "GaudiKernel/IIoComponent.h"
21#include "GaudiKernel/IIncidentSvc.h"
22#include "GaudiKernel/MsgStream.h"
23#include "Gaudi/Property.h"
24#include "GaudiKernel/ServiceHandle.h"
28
29#include "TFile.h"
30#include "TObjString.h"
31
32// Forward declaration
33class ISvcLocator;
34class StoreGateSvc;
35class TTree;
36class IClassIDSvc;
37class IDictLoaderSvc;
38namespace Athena { class RootNtupleEventContext; }
39
40namespace Athena {
41
46 public extends<AthService,
47 IEvtSelector, IEvtSelectorSeek,
48 IAddressProvider, IIoComponent, IIncidentListener>
49{
51
52
53
55 // Public methods:
57 public:
58
60 RootNtupleEventSelector( const std::string& name, ISvcLocator* svcLoc );
61
63 virtual ~RootNtupleEventSelector();
64
65 // Athena hooks
66 virtual StatusCode initialize() override;
67 virtual StatusCode finalize() override;
68
69 virtual void handle(const Incident& incident) override;
70
73 virtual StatusCode createContext( Context*& refpCtxt ) const override;
74
75 virtual StatusCode last( Context& refContext ) const override;
76 virtual StatusCode next( Context& refCtxt ) const override;
77 virtual StatusCode next( Context& refCtxt, int jump ) const override;
78 virtual StatusCode previous( Context& refCtxt ) const override;
79 virtual StatusCode previous( Context& refCtxt, int jump ) const override;
80 virtual StatusCode rewind( Context& refCtxt ) const override;
81
82 virtual StatusCode createAddress( const Context& refCtxt,
83 IOpaqueAddress*& ) const override;
84 virtual StatusCode releaseContext( Context*& refCtxt ) const override;
85 virtual StatusCode resetCriteria( const std::string& cr,
86 Context& ctx )const override;
88
91
95 virtual StatusCode seek (Context& refCtxt, int evtnum) const override;
96
101 virtual int curEvent (const Context& refCtxt) const override;
103
106 virtual StatusCode io_reinit() override;
107
111 virtual
112 StatusCode preLoadAddresses(StoreID::type storeID, tadList& list) override;
113
115 virtual
116 StatusCode loadAddresses(StoreID::type storeID, tadList& list) override;
117
119 virtual
120 StatusCode updateAddress(StoreID::type storeID, SG::TransientAddress* tad,
121 const EventContext& ctx) override;
123
125 virtual int size (Context& refCtxt) const override;
126
128 // Const methods:
130
132 // Non-const methods:
134
136 // Private methods:
138 private:
139
140 StatusCode endInputFile (RootNtupleEventContext* rctx) const;
141
143 void setupInputCollection( Gaudi::Details::PropertyBase& inputCollectionsName );
144
146 StatusCode createRootBranchAddresses(StoreID::type storeID,
147 tadList &tads);
148
149
151 TTree* fetchNtuple(const std::string& fname,
152 const std::string& tupleName) const;
153
154 void addMetadataFromDirectoryName(const std::string &metadirname,
155 TFile *fileObj,
156 const std::string &prefix = "") const;
157 void addMetadataFromDirectory(TDirectoryFile *metadir,
158 const std::string &prefix = "") const;
159 void addMetadata(TTree *metatree, const std::string &path = "") const;
160 void addMetadata(TObjString *metastring, const std::string &path = "") const;
161
164 TTree *tree,
165 const std::string& prefix) const;
166
168 StatusCode do_init_io();
169
174 void find_coll_idx(int evtidx, long& coll_idx, long& tuple_idx) const;
175
178 { return const_cast<RootNtupleEventSelector*>(this); }
179
181 // Private data:
183 private:
184
188
191
194
198
202
206
208 StringArrayProperty m_inputCollectionsName;
209
211 StringProperty m_tupleName;
212
214 StringArrayProperty m_activeBranchNames;
215
218
220 std::vector<std::string> m_tupleNames;
221
223 mutable long m_nbrEvts;
224
226 mutable long m_curEvt;
227
235 };
236
238 mutable std::vector<std::vector<CollMetaData> > m_collEvts;
239
241 mutable TTree *m_tuple;
242
245 //PyObject* m_pySelectionFct;
246
247 // flag to trigger reloading of root branch addresses
248 mutable bool m_needReload;
249 // flag to trigger firing BeginInputFile incidents once the root branch
250 // addresses have been reloaded.
251 // Reloading addresses (we assume?) means a new TTree
252 // has been loaded from a new file in the list of input files.
253 //
254 // FIXME: use some kind of state-machine to couple
255 // m_needReload and m_fireBIF ?
256 mutable bool m_fireBIF;
257
258 // the list of transient addresses we "manage" or know about
259 // these addresses are the actual TTree's branch names
260 // for the metadata tree(s)
261 //Addrs_t m_rootAddressesMetaData;
262
263 // List of files that we've created, so that we can delete them
264 // during finalize. FIXME: get rid of the mutable.
265 mutable std::vector<TFile*> m_files;
266};
267
269// Inline methods:
271
272} //> namespace Athena
273
274#endif //> ATHENAROOTCOMPS_ATHENA_ROOTNTUPLEEVENTSELECTOR_H
Extension to IEvtSelector to allow for seeking.
Define macros for attributes used to control the static checker.
ROOT specific event selector context.
RootNtupleEventSelector * self() const
non-const access to self (b/c next() is const)
virtual StatusCode seek(Context &refCtxt, int evtnum) const override
Seek to a given event number.
virtual StatusCode finalize() override
RootNtupleEventSelector(const std::string &name, ISvcLocator *svcLoc)
Constructor with parameters:
virtual StatusCode releaseContext(Context *&refCtxt) const override
virtual int curEvent(const Context &refCtxt) const override
return the current event number.
void setupInputCollection(Gaudi::Details::PropertyBase &inputCollectionsName)
callback to synchronize the list of input files
virtual StatusCode loadAddresses(StoreID::type storeID, tadList &list) override
get all new addresses from Provider for this Event.
ServiceHandle< IDictLoaderSvc > IDictSvc_t
virtual StatusCode last(Context &refContext) const override
virtual int size(Context &refCtxt) const override
ICollectionSize interface
void find_coll_idx(int evtidx, long &coll_idx, long &tuple_idx) const
helper method to get the collection index (into m_inputCollectionsName) and tuple index (into ‘m_tupl...
virtual StatusCode resetCriteria(const std::string &cr, Context &ctx) const override
ServiceHandle< IIncidentSvc > IIncSvc_t
ServiceHandle< IClassIDSvc > ICLIDSvc_t
virtual StatusCode preLoadAddresses(StoreID::type storeID, tadList &list) override
IAddressProvider interface get all addresses from Provider : Called before Begin Event
StringArrayProperty m_activeBranchNames
List of branches to activate in the TTree.
TTree * m_tuple
current tree being read
std::vector< std::vector< CollMetaData > > m_collEvts
cache of the number of entries for each collection Indexed like [tuple][collection]
bool m_needReload
The (python) selection function to apply on the TChain we are reading.
virtual StatusCode updateAddress(StoreID::type storeID, SG::TransientAddress *tad, const EventContext &ctx) override
update a transient Address
IDictSvc_t m_dictsvc
Pointer to the IDictLoaderSvc.
std::vector< std::string > m_tupleNames
Names of all trees over which to iterate.
virtual StatusCode next(Context &refCtxt) const override
StoreGateSvc_t m_imetaStore
Pointer to the StoreGateSvc input metadata store.
StatusCode endInputFile(RootNtupleEventContext *rctx) const
StatusCode do_init_io()
helper method to init the i/o components
StatusCode createMetaDataRootBranchAddresses(StoreGateSvc *store, TTree *tree, const std::string &prefix) const
helper method to create proxies for the metadata store
ServiceHandle< StoreGateSvc > StoreGateSvc_t
IIncSvc_t m_incsvc
Handle to the incident service.
void addMetadataFromDirectoryName(const std::string &metadirname, TFile *fileObj, const std::string &prefix="") const
StringArrayProperty m_inputCollectionsName
List of input files containing TTree.
virtual StatusCode createContext(Context *&refpCtxt) const override
ICLIDSvc_t m_clidsvc
Pointer to the IClassIDSvc.
StringProperty m_tupleName
Name of TTree to load from collection of input files.
StoreGateSvc_t m_dataStore
Pointer to the StoreGateSvc event store.
void addMetadataFromDirectory(TDirectoryFile *metadir, const std::string &prefix="") const
void addMetadata(TTree *metatree, const std::string &path="") const
TTree * fetchNtuple(const std::string &fname, const std::string &tupleName) const
helper method to retrieve the correct tuple
virtual void handle(const Incident &incident) override
StatusCode createRootBranchAddresses(StoreID::type storeID, tadList &tads)
helper method to create proxies
virtual StatusCode previous(Context &refCtxt) const override
StoreGateSvc_t m_ometaStore
Pointer to the StoreGateSvc output metadata store.
long m_skipEvts
Number of events to skip at the beginning.
virtual StatusCode io_reinit() override
Callback method to reinitialize the internal state of the component for I/O purposes (e....
virtual StatusCode rewind(Context &refCtxt) const override
virtual StatusCode createAddress(const Context &refCtxt, IOpaqueAddress *&) const override
long m_nbrEvts
Number of Events read so far.
a simple interface to interact with the Reflex dictionaries and abstract/workaround a few ROOT bugs.
The Athena Transient Store API.
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....
StatusCode ROOTMessageFilterSvc::initialize ATLAS_NOT_THREAD_SAFE()
Return the file descriptor fataldump() uses for output.
void initialize()
long entries
number of entries in this collection.
long min_entries
number of entries up to this collection
long max_entries
number of entries after this collection
TChain * tree