ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
xAODRootAccess
python
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:
8
import
ROOT
9
10
# Make sure that the transient trees are explicitly deleted when exiting
11
# python:
12
import
atexit
13
atexit.register( ROOT.xAOD.ClearTransientTrees )
14
15
19
def
DataVectorIterator
( self ):
20
for
i
in
range( self.size() ):
21
yield
self.at( i )
22
23
29
def
generateDVIterators
():
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:
76
generateDVIterators
()
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
find
std::string find(const std::string &s)
return a remapped string
Definition
hcg.cxx:140
ROOT.xAOD
python.GenerateDVIterators.generateDVIterators
generateDVIterators()
Function installing proper iterators for all the known DataVector types.
Definition
GenerateDVIterators.py:29
python.GenerateDVIterators.DataVectorIterator
DataVectorIterator(self)
Generic iterator that can be used with any DataVector type.
Definition
GenerateDVIterators.py:19
Generated on
for ATLAS Offline Software by
1.17.0