ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigDataAccess
TrigSerializeResult
python
StreamerInfoGenerator.py
Go to the documentation of this file.
1
#!/usr/bin/env pyroot.py
2
3
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4
import
cppyy
5
import
ROOT
6
7
class
StreamerInfoGenerator
:
8
def
__init__
(self):
9
self.
debug
=
False
10
print
(
"StreamerInfoGenerator v1.0.0"
)
11
self.
classlist
= []
12
self.
problemclasses
= []
13
#MN: ROOT6 strips std:: from types, so we need to check the names
14
self.
blocklist
= [
'std::'
,
'vector<'
,
'map<'
,
'queue<'
,
'list<'
]
15
self.
type
= cppyy.gbl.RootType
16
self.
type
.EnableCintex()
17
cppyy.load_library(
'libAtlasSTLAddReflexDict'
)
18
#MN: switch off auto dict generation - god knows what that can mess up
19
ROOT.gROOT.ProcessLine(
".autodict"
)
20
21
22
def
inspect
(self, typename):
23
if
self.
debug
:
print
(
'inspecting '
, typename)
24
25
dontAdd =
False
26
27
for
b
in
self.
blocklist
:
28
if
typename.find(b) == 0:
29
if
self.
debug
:
print
(
'blocklisted '
, typename)
30
dontAdd =
True
31
32
# print self.classlist
33
if
typename
in
self.
classlist
:
34
if
self.
debug
:
print
(
'seen before '
, typename)
35
dontAdd =
True
36
37
try
:
38
t = self.
type
.ByName(typename)
39
if
self.
debug
:
print
(
type
(t))
40
if
t.IsFundamental():
41
if
self.
debug
:
print
(typename,
' is fundamental'
)
42
return
43
if
t.IsAbstract():
44
dontAdd =
True
45
except
Exception:
46
pass
47
48
# can't handle anonymous types
49
exceptions = [
"string::(anonymous)"
,
"string::(unnamed)"
]
50
try
:
51
# This doesn't work in ROOT 6.22 anymore
52
# cl = cppyy.makeClass(typename)
53
#
54
bind_name = typename
55
# If it's a type with template argument, replace outermost <...> with ['...']
56
bind_name = bind_name.replace(
"<"
,
"['"
, 1)[::-1].
replace
(
">"
,
"]'"
, 1)[::-1]
57
# Replace "::" with "." to set namespace, for the base type
58
base_and_arg = bind_name.split(
"["
)
59
base_and_arg[0] = base_and_arg[0].
replace
(
"::"
,
"."
)
60
bind_name =
"["
.join(base_and_arg)
61
bind_name =
"ROOT."
+ bind_name
62
if
self.
debug
:
63
print
(
"Making class {} -> {}"
.format(typename, bind_name))
64
print
(
"cl = "
+ bind_name)
65
exec(
"cl = "
+ bind_name, globals())
66
if
self.
debug
:
print
(cl)
# noqa: F821
67
if
not
dontAdd:
68
self.
classlist
.append(typename)
69
if
self.
debug
:
print
(
"appended type to the classlist"
)
70
except
Exception
as
ex:
71
if
self.
debug
:
print
(
'Cannot create class of {}: {}'
.format(typename, ex))
72
if
typename
not
in
exceptions:
73
raise
ex
74
75
t = self.
type
.ByName(typename)
76
77
if
t.IsComplete():
78
if
self.
debug
:
print
(typename,
'is complete'
)
79
else
:
80
if
self.
debug
:
print
(typename,
' isn\'t complete'
)
81
82
if
t.IsPointer():
83
if
self.
debug
:
print
(typename,
' is a pointer'
)
84
elif
t.IsTypedef():
85
if
self.
debug
:
print
(typename,
' is typedef'
)
86
underlying = t.ToType()
87
if
(underlying):
88
self.
inspect
(underlying.Name(7))
89
elif
t.IsArray():
90
if
self.
debug
:
print
(typename,
' is an array'
)
91
elif
t.IsTemplateInstance():
92
if
self.
debug
:
print
(typename,
' is template'
)
93
if
typename.find(
'std::'
)==0:
94
if
self.
debug
:
print
(
'std::business removed'
)
95
try
:
96
self.
classlist
.remove(typename)
97
except
Exception:
98
pass
99
for
i
in
range(t.TemplateArgumentSize()):
100
tt = t.TemplateArgumentAt(i)
101
ttname = tt.Name(7)
102
if
tt.IsPointer()
or
tt.IsArray()
or
tt.IsTypedef():
103
ttname = tt.ToType().Name(7)
104
self.
inspect
(ttname)
105
elif
t.IsClass():
106
if
self.
debug
:
print
(typename,
' is a class'
)
107
cname = t.Name(7)
108
if
self.
debug
:
print
(cname)
109
110
for
i
in
range(t.DataMemberSize()):
111
d = t.DataMemberAt(i)
112
dname = d.Name()
113
dtype = d.TypeOf().Name(7)
114
if
self.
debug
:
115
print
(
'DataMember: '
, dname,
' '
, dtype,
' transient='
, d.IsTransient())
116
if
not
d.IsTransient():
117
self.
inspect
(dtype)
118
119
else
:
120
print
(
'what to do about '
, typename,
'?'
)
121
self.
problemclasses
.append( typename )
122
return
123
124
125
126
def
streamers
(self):
127
print
(self.
classlist
)
128
129
130
if
__name__ ==
'__main__'
:
131
from
ROOT
import
TClass, TFile
# noqa: F401
132
a =
StreamerInfoGenerator
()
133
a.inspect(
'TrigTauClusterContainer_tlp1'
)
134
135
print
(a.classlist)
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
StreamerInfoGenerator.StreamerInfoGenerator
Definition
StreamerInfoGenerator.py:7
StreamerInfoGenerator.StreamerInfoGenerator.inspect
inspect(self, typename)
Definition
StreamerInfoGenerator.py:22
StreamerInfoGenerator.StreamerInfoGenerator.problemclasses
list problemclasses
Definition
StreamerInfoGenerator.py:12
StreamerInfoGenerator.StreamerInfoGenerator.debug
bool debug
Definition
StreamerInfoGenerator.py:9
StreamerInfoGenerator.StreamerInfoGenerator.__init__
__init__(self)
Definition
StreamerInfoGenerator.py:8
StreamerInfoGenerator.StreamerInfoGenerator.classlist
list classlist
Definition
StreamerInfoGenerator.py:11
StreamerInfoGenerator.StreamerInfoGenerator.streamers
streamers(self)
Definition
StreamerInfoGenerator.py:126
StreamerInfoGenerator.StreamerInfoGenerator.blocklist
list blocklist
Definition
StreamerInfoGenerator.py:14
StreamerInfoGenerator.StreamerInfoGenerator.type
type
Definition
StreamerInfoGenerator.py:15
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition
hcg.cxx:312
type
Generated on
for ATLAS Offline Software by
1.17.0