ATLAS Offline Software
Loading...
Searching...
No Matches
GenerateDVIterators.py
Go to the documentation of this file.
1# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2#
3# Module used to generate proper Python iterators for all the known
4# DataVector container types.
5#
6
7# Pull in ROOT:
8import ROOT
9
10# Make sure that the transient trees are explicitly deleted when exiting
11# python:
12import atexit
13atexit.register( ROOT.xAOD.ClearTransientTrees )
14
15
20 for i in range( self.size() ):
21 yield self.at( i )
22
23
30
31 # Let the user know what's happening:
32 print( "generateDVIterators INFO Attaching iterators to all known DV "
33 "types" )
34 print( "generateDVIterators INFO This may take a moment..." )
35
36 # Load/access the dictionaries of all of the same types that xAOD::Init()
37 # accesses as well. Since apparently "the C++ side" and "the Python side"
38 # need to do this separately... :-/
39 for name in [ 'TruthParticleContainer',
40 'MuonRoIContainer',
41 'CaloClusterContainer',
42 'TrackParticleContainer',
43 'ElectronContainer',
44 'MuonContainer',
45 'JetContainer',
46 'TauJetContainer',
47 'PFOContainer',
48 'TrigElectronContainer',
49 'L2CombinedMuonContainer',
50 'ParticleContainer' ]:
51 getattr( ROOT.xAOD, name, None )
52 pass
53
54 # Iterate over all classes known to ROOT:
55 for typ in ROOT.gROOT.GetListOfClasses():
56 # Skip emulated classes:
57 if not typ.IsLoaded():
58 continue
59 # We're only interested in DataVector types:
60 if typ.GetName().find( "DataVector<" ) != 0:
61 continue
62 # Access the python type associated with this type:
63 ptyp = getattr( ROOT, typ.GetName(), None )
64 if not ptyp:
65 print( "generateDVIterators ERROR Couldn't get python type for " \
66 "\"%s\"" % typ.GetName() )
67 continue
68 # Massage the iterator of this type:
69 ptyp.__iter__ = DataVectorIterator
70 pass
71
72 # Return gracefully:
73 return
74
75# Call the function:
void print(char *figname, TCanvas *c1)
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
DataVectorIterator(self)
Generic iterator that can be used with any DataVector type.
generateDVIterators()
Function installing proper iterators for all the known DataVector types.