ATLAS Offline Software
Loading...
Searching...
No Matches
RootNtupleEventSelector.h
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2026 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"
29
30#include "TFile.h"
31#include "TObjString.h"
32
33#include <optional>
34
35// Forward declaration
36class ISvcLocator;
37class StoreGateSvc;
38class TTree;
39class IClassIDSvc;
40class IDictLoaderSvc;
41namespace Athena { class RootNtupleEventContext; }
42
43namespace Athena {
44
49 public extends<AthService,
50 IEvtSelector, IEvtSelectorSeek,
51 IAddressProvider, IIoComponent, IIncidentListener>
52{
54
55
56
58 // Public methods:
60 public:
61
63 RootNtupleEventSelector( const std::string& name, ISvcLocator* svcLoc );
64
66 virtual ~RootNtupleEventSelector();
67
68 // Athena hooks
69 virtual StatusCode initialize() override;
70 virtual StatusCode stop() override;
71 virtual StatusCode finalize() override;
72
73 virtual void handle(const Incident& incident) override;
74
77 virtual StatusCode createContext( Context*& refpCtxt ) const override;
78
79 virtual StatusCode last( Context& refContext ) const override;
80 virtual StatusCode next( Context& refCtxt ) const override;
81 virtual StatusCode next( Context& refCtxt, int jump ) const override;
82 virtual StatusCode previous( Context& refCtxt ) const override;
83 virtual StatusCode previous( Context& refCtxt, int jump ) const override;
84 virtual StatusCode rewind( Context& refCtxt ) const override;
85
86 virtual StatusCode createAddress( const Context& refCtxt,
87 IOpaqueAddress*& ) const override;
88 virtual StatusCode releaseContext( Context*& refCtxt ) const override;
89 virtual StatusCode resetCriteria( const std::string& cr,
90 Context& ctx )const override;
92
95
99 virtual StatusCode seek (Context& refCtxt, int evtnum) const override;
100
105 virtual int curEvent (const Context& refCtxt) const override;
107
110 virtual StatusCode io_reinit() override;
111
115 virtual
116 StatusCode preLoadAddresses(StoreID::type storeID, tadList& list) override;
117
119 virtual
120 StatusCode loadAddresses(StoreID::type storeID, tadList& list) override;
121
123 virtual
124 StatusCode updateAddress(StoreID::type storeID, SG::TransientAddress* tad,
125 const EventContext& ctx) override;
127
129 virtual int size (Context& refCtxt) const override;
130
132 // Const methods:
134
136 // Non-const methods:
138
140 // Private methods:
142 private:
143
144 StatusCode endInputFile (RootNtupleEventContext* rctx) const;
145
147 void setupInputCollection( Gaudi::Details::PropertyBase& inputCollectionsName );
148
150 StatusCode createRootBranchAddresses(StoreID::type storeID,
151 tadList &tads);
152
153
155 TTree* fetchNtuple(const std::string& fname,
156 const std::string& tupleName) const;
157
158 void addMetadataFromDirectoryName(const std::string &metadirname,
159 TFile *fileObj,
160 const std::string &prefix = "") const;
161 void addMetadataFromDirectory(TDirectoryFile *metadir,
162 const std::string &prefix = "") const;
163 void addMetadata(TTree *metatree, const std::string &path = "") const;
164 void addMetadata(TObjString *metastring, const std::string &path = "") const;
165
168 TTree *tree,
169 const std::string& prefix) const;
170
172 StatusCode do_init_io();
173
178 void find_coll_idx(int evtidx, long& coll_idx, long& tuple_idx) const;
179
181 RootNtupleEventSelector *self() const
182 { return const_cast<RootNtupleEventSelector*>(this); }
183
185 // Private data:
187 private:
188
189 typedef ServiceHandle<StoreGateSvc> StoreGateSvc_t;
191 StoreGateSvc_t m_dataStore;
192
194 StoreGateSvc_t m_imetaStore;
195
197 StoreGateSvc_t m_ometaStore;
198
199 typedef ServiceHandle<IClassIDSvc> ICLIDSvc_t;
201 ICLIDSvc_t m_clidsvc;
202
203 typedef ServiceHandle<IDictLoaderSvc> IDictSvc_t;
205 IDictSvc_t m_dictsvc;
206
207 typedef ServiceHandle<IIncidentSvc> IIncSvc_t;
209 IIncSvc_t m_incsvc;
210
212 StringArrayProperty m_inputCollectionsName;
213
215 StringProperty m_tupleName;
216
218 StringArrayProperty m_activeBranchNames;
219
221 StringProperty m_eventNumberVar
222 { this, "EventNumberVar", "", "Optional event number variable to propagate to EventInfo" };
224 StringProperty m_runNumberVar
225 { this, "RunNumberVar", "", "Optional run number variable to propagate to EventInfo" };
227 StringProperty m_lbnVar
228 { this, "LBNVar", "", "Optional LBN variable to propagate to EventInfo" };
229
231 long m_skipEvts;
232
234 std::vector<std::string> m_tupleNames;
235
237 mutable long m_nbrEvts;
238
240 mutable long m_curEvt;
241
242 struct CollMetaData {
244 long min_entries;
246 long max_entries;
248 long entries;
249 };
252 mutable std::vector<std::vector<CollMetaData> > m_collEvts;
253
255 mutable TTree *m_tuple;
256
259 //PyObject* m_pySelectionFct;
260
261 // flag to trigger reloading of root branch addresses
262 mutable bool m_needReload;
263
267 mutable std::optional<InputFileIncidentGuard> m_inputFileGuard;
269 mutable bool m_fireBIF{true};
270
271 // the list of transient addresses we "manage" or know about
272 // these addresses are the actual TTree's branch names
273 // for the metadata tree(s)
274 //Addrs_t m_rootAddressesMetaData;
275
276 // List of files that we've created, so that we can delete them
277 // during finalize. FIXME: get rid of the mutable.
278 mutable std::vector<TFile*> m_files;
279};
280
282// Inline methods:
284
285} //> namespace Athena
286
287#endif //> ATHENAROOTCOMPS_ATHENA_ROOTNTUPLEEVENTSELECTOR_H
Extension to IEvtSelector to allow for seeking.
RAII guard that guarantees a matching end-incident for every begin-incident.
Define macros for attributes used to control the static checker.
ROOT specific event selector context.
virtual StatusCode seek(Context &refCtxt, int evtnum) const override
Seek to a given event number.
virtual StatusCode finalize() override
virtual int size(Context &refCtxt) const override
ICollectionSize interface
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.
virtual StatusCode last(Context &refContext) const override
virtual StatusCode resetCriteria(const std::string &cr, Context &ctx) const override
virtual StatusCode preLoadAddresses(StoreID::type storeID, tadList &list) override
TTree * m_tuple
current tree being read
std::vector< std::vector< CollMetaData > > m_collEvts
helper method to get the collection index (into m_inputCollectionsName) and tuple index (into m_tuple...
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
virtual StatusCode next(Context &refCtxt) const override
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
bool m_fireBIF
Flag to fire BeginInputFile on the next BeginEvent incident.
void addMetadataFromDirectoryName(const std::string &metadirname, TFile *fileObj, const std::string &prefix="") const
virtual StatusCode createContext(Context *&refpCtxt) const override
std::optional< InputFileIncidentGuard > m_inputFileGuard
RAII guard: guarantees a matching EndInputFile for every BeginInputFile.
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
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
a simple interface to interact with the Reflex dictionaries and abstract/workaround a few ROOT bugs.
The Athena Transient Store API.
double entries
Definition listroot.cxx:49
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....
Definition AthDsoUtils.h:10
find_coll_idx(-1, coll_idx, tuple_idx)
StatusCode ROOTMessageFilterSvc::initialize ATLAS_NOT_THREAD_SAFE()
Return the file descriptor fataldump() uses for output.
void initialize()
TChain * tree