ATLAS Offline Software
RootNtupleEventSelector.h
Go to the documentation of this file.
1 
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
33 class ISvcLocator;
34 class StoreGateSvc;
35 class TTree;
36 class IClassIDSvc;
37 class IDictLoaderSvc;
38 namespace Athena { class RootNtupleEventContext; }
39 
40 namespace 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 
163  StatusCode createMetaDataRootBranchAddresses(StoreGateSvc *store,
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 
228  struct CollMetaData {
234  long entries;
235  };
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
SGTest::store
TestStore store
Definition: TestStore.cxx:23
Athena::RootNtupleEventSelector::m_skipEvts
long m_skipEvts
Number of events to skip at the beginning.
Definition: RootNtupleEventSelector.h:217
Athena::RootNtupleEventSelector::IIncSvc_t
ServiceHandle< IIncidentSvc > IIncSvc_t
Definition: RootNtupleEventSelector.h:203
Athena::RootNtupleEventSelector::m_incsvc
IIncSvc_t m_incsvc
Handle to the incident service.
Definition: RootNtupleEventSelector.h:205
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:50
Athena::RootNtupleEventSelector::StoreGateSvc_t
ServiceHandle< StoreGateSvc > StoreGateSvc_t
Definition: RootNtupleEventSelector.h:185
Athena::RootNtupleEventSelector::m_tupleName
StringProperty m_tupleName
Name of TTree to load from collection of input files.
Definition: RootNtupleEventSelector.h:211
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
IDictLoaderSvc
Definition: IDictLoaderSvc.h:37
Athena::RootNtupleEventSelector::CollMetaData::max_entries
long max_entries
number of entries after this collection
Definition: RootNtupleEventSelector.h:232
Athena::RootNtupleEventSelector::ICLIDSvc_t
ServiceHandle< IClassIDSvc > ICLIDSvc_t
Definition: RootNtupleEventSelector.h:195
Athena::RootNtupleEventSelector::m_inputCollectionsName
StringArrayProperty m_inputCollectionsName
List of input files containing TTree.
Definition: RootNtupleEventSelector.h:208
initialize
void initialize()
Definition: run_EoverP.cxx:894
tree
TChain * tree
Definition: tile_monitor.h:30
SG::TransientAddress
Definition: TransientAddress.h:32
python.HanMetadata.addMetadata
def addMetadata(f, key, mapping)
Definition: HanMetadata.py:29
Athena::RootNtupleEventSelector::m_dictsvc
IDictSvc_t m_dictsvc
Pointer to the IDictLoaderSvc.
Definition: RootNtupleEventSelector.h:201
Athena::RootNtupleEventSelector::m_nbrEvts
long m_nbrEvts
Number of Events read so far.
Definition: RootNtupleEventSelector.h:223
Athena::RootNtupleEventSelector::CollMetaData::min_entries
long min_entries
number of entries up to this collection
Definition: RootNtupleEventSelector.h:230
Athena::RootNtupleEventSelector::m_tuple
TTree * m_tuple
current tree being read
Definition: RootNtupleEventSelector.h:241
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:125
Athena::RootNtupleEventSelector
Class implementing the GAUDI IEvtSelector interface using ROOT TTree as a backend.
Definition: RootNtupleEventSelector.h:49
Athena::RootNtupleEventSelector::m_fireBIF
bool m_fireBIF
Definition: RootNtupleEventSelector.h:256
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
Athena::RootNtupleEventSelector::m_tupleNames
std::vector< std::string > m_tupleNames
Names of all trees over which to iterate.
Definition: RootNtupleEventSelector.h:220
Athena
Some weak symbol referencing magic...
Definition: AthLegacySequence.h:21
Athena::RootNtupleEventSelector::m_curEvt
long m_curEvt
current event index
Definition: RootNtupleEventSelector.h:226
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Athena::RootNtupleEventContext
Definition: RootNtupleEventSelector.cxx:131
Athena::RootNtupleEventSelector::m_ometaStore
StoreGateSvc_t m_ometaStore
Pointer to the StoreGateSvc output metadata store.
Definition: RootNtupleEventSelector.h:193
Athena::RootNtupleEventSelector::m_collEvts
std::vector< std::vector< CollMetaData > > m_collEvts
cache of the number of entries for each collection Indexed like [tuple][collection]
Definition: RootNtupleEventSelector.h:238
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
Athena::RootNtupleEventSelector::CollMetaData
Definition: RootNtupleEventSelector.h:228
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
Athena::RootNtupleEventSelector::m_needReload
bool m_needReload
The (python) selection function to apply on the TChain we are reading.
Definition: RootNtupleEventSelector.h:248
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Athena::RootNtupleEventSelector::m_files
std::vector< TFile * > m_files
Definition: RootNtupleEventSelector.h:265
python.AthDsoLogger.fname
string fname
Definition: AthDsoLogger.py:67
Athena::RootNtupleEventSelector::m_clidsvc
ICLIDSvc_t m_clidsvc
Pointer to the IClassIDSvc.
Definition: RootNtupleEventSelector.h:197
Athena::RootNtupleEventSelector::m_dataStore
StoreGateSvc_t m_dataStore
Pointer to the StoreGateSvc event store.
Definition: RootNtupleEventSelector.h:187
Athena::RootNtupleEventSelector::CollMetaData::entries
long entries
number of entries in this collection.
Definition: RootNtupleEventSelector.h:234
StoreID::type
type
Definition: StoreID.h:24
Athena::RootNtupleEventSelector::m_imetaStore
StoreGateSvc_t m_imetaStore
Pointer to the StoreGateSvc input metadata store.
Definition: RootNtupleEventSelector.h:190
AthService.h
IAddressProvider.h
IEvtSelectorSeek.h
Extension to IEvtSelector to allow for seeking.
checker_macros.h
Define macros for attributes used to control the static checker.
Athena::RootNtupleEventSelector::IDictSvc_t
ServiceHandle< IDictLoaderSvc > IDictSvc_t
Definition: RootNtupleEventSelector.h:199
Athena::ATLAS_NOT_THREAD_SAFE
void DebugAids::stacktraceLine ATLAS_NOT_THREAD_SAFE(IOFD fd, unsigned long addr)
Write out stack trace line to FD.
Definition: SealDebug.cxx:328
Trk::previous
@ previous
Definition: BinningData.h:32
ServiceHandle< StoreGateSvc >
Athena::RootNtupleEventSelector::m_activeBranchNames
StringArrayProperty m_activeBranchNames
List of branches to activate in the TTree.
Definition: RootNtupleEventSelector.h:214