ATLAS Offline Software
Loading...
Searching...
No Matches
Control/AthenaServices/python/Dso.py
Go to the documentation of this file.
1# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
3# @file: AthenaServices/python/Dso.py
4# @purpose: simple interface to the rootmap files to easily locate reflex
5# dictionaries (and load them)
6# @author: Sebastien Binet <binet@cern.ch>
7# @date: September 2008
8
9
10__version__ = "$Revision: 1.12 $"
11__author__ = "Sebastien Binet <binet@cern.ch>"
12__doc__ = """\
13simple interface to the rootmap files to easily locate reflex dictionaries \
14(and load them)
15"""
16
17__all__ = [
18 'registry',
19 ]
20
21
22import os
23from PyUtils import Dso as _Dso
24from PyUtils.Dso import _aliases
25
26try:
27 # attempt at fixing up the pyroot iterators...
28 import RootUtils.PyROOTFixes # noqa: F401
29except ImportError:
30 pass
31
32_cpp_builtins = (
33 'char', 'unsigned char', 'signed char',
34 'signed',
35 'short int', 'short signed', 'short signed int',
36 'short', 'unsigned short', 'signed short',
37 'int', 'unsigned int',
38
39 'long int',
40 'long signed int',
41 'signed long int',
42
43 'long',
44 'long signed', 'signed long',
45 'unsigned long',
46 'unsigned long int',
47 'long unsigned int',
48
49 'long long',
50 'long long int',
51 'unsigned long long',
52
53 'float',
54 'double',
55 'long double',
56 'bool',
57 )
58
59
60
61class RflxEnums(object):
62 S = 4 # SCOPED
63 SF = 5 # SCOPED|FINAL
64 SQ = 6 # SCOPED|QUALIFIED
65 SFQ = 7 # SCOPED|FINAL|QUALIFIED
66 DICTSCOPE =SF
67
68class DsoDb(_Dso.PyDsoDb):
69 """
70 The repository of 'rootmap' files (location, content,...) and a set of
71 operations one can apply on them (load dict, query dicts,...)
72 """
73 def __init__(self):
74 super(DsoDb, self).__init__('AthenaDsoDb')
75 import AthenaCommon.Logging
76 self.msg = AthenaCommon.Logging.logging.getLogger("AthenaDsoDb")
77 #self.msg.setLevel(AthenaCommon.Logging.logging.VERBOSE)
78
79 # inject the known aliases NOW
80 for k,v in _aliases.iteritems():
81 try:
82 self.db[k] = self.db[v]
83 except KeyError:
84 self.msg.info("could not install alias [%s] -> [%s]", k,v)
85 # make sure we'll be able to load dicts
86 import cppyy
87 #self._load_dict = cppyy.loadDict
88 self._rflx_type = cppyy.gbl.RootType.ByName
89 return
90
91 def has_type (self, typename):
92 if typename in _cpp_builtins:
93 return True
94 # need to massage a bit the typename to match ROOT naming convention
95 typename = self._to_rootmap_name (typename)
96 return self.db.has_key (typename) or \
97 self.pf.has_key (typename)
98
99 def load_type (self, typename):
100 rflx_type = self.rflx_type(typename)
101 if rflx_type is not None:
102 rflx_name = rflx_type.Name(RflxEnums.DICTSCOPE)
103 if rflx_name != '':
104 return rflx_name
105 return None
106
107 def rflx_type(self, typename):
108 _rootmap_name = self._to_rootmap_name (typename)
109 _rflx_name = self._to_rflx_name (typename)
110 self.msg.verbose("------- loading type [%s]...", typename)
111
112 if typename in _cpp_builtins:
113 self.msg.verbose(" ==> [ok] (builtin)")
114 return self._rflx_type (_rflx_name)
115
116 if not self.has_type (_rootmap_name):
117 self.msg.verbose(" ==> [err] (no '%s')",_rootmap_name)
118 return None
119 libs = (self.db.get(_rootmap_name) or
120 self.pf.get(_rootmap_name))
121 if libs is None or len(libs) <= 0:
122 return None
123 from ctypes import cdll
124 _load = cdll.LoadLibrary
125 from cppyy import loadDict as _load
126 lib = libs[0]
127 self.msg.verbose("... %s",lib)
128 _load (os.path.basename(lib.strip()))
129 self.msg.verbose("... %s [done]",lib)
130 self.msg.verbose(" ==> [ok]")
131
132 # give the non-massaged name to reflex as this is what it expects
133 # ...ROOT is sooo self-consistent...
134 rflx_type = self._rflx_type (_rflx_name)
135 if rflx_type.Name() != '':
136 return rflx_type
137 return None
138
139
140 def visit(self, typename, visitor=None, ctx=None):
141 self.msg.verbose("=== visiting %s", typename)
142 if ctx is None:
143 ctx = set()
144 if isinstance (typename, str):
145 rflx_type = self.load_type (typename)
146 typename = rflx_type.Name (RflxEnums.DICTSCOPE)
147 else:
148 rflx_type = typename
149
150 if not rflx_type:
151 self.msg.verbose("**warning** no dict for [%s] !!", typename)
152 return ctx
153
154 ctx.add (typename)
155 if visitor:
156 visitor (rflx_type)
157
158 if rflx_type.IsClass() or rflx_type.IsStruct():
159 for i in range(rflx_type.BaseSize()):
160 itype = rflx_type.BaseAt(i).ToType()
161 itype_name = itype.Name(RflxEnums.DICTSCOPE)
162 if itype_name != '' and not (itype_name in ctx):
163 self.load_type (itype_name)
164 ctx.add (itype_name)
165 ctx.update (self.visit (itype, visitor, ctx))
166
167 for i in range(rflx_type.DataMemberSize()):
168 itype = rflx_type.DataMemberAt (i).TypeOf()
169 itype = itype.RawType() if itype.IsPointer() else itype
170 itype_name = itype.Name(RflxEnums.DICTSCOPE)
171 if itype_name != '' and not (itype_name in ctx):
172 self.load_type (itype_name)
173 ctx.add (itype_name)
174 # restore original type
175 itype = rflx_type.DataMemberAt (i).TypeOf()
176 itype_name = itype.Name(RflxEnums.DICTSCOPE)
177 ctx.update (self.visit (itype, visitor, ctx))
178 return ctx
179
180 pass # class DsoDb
181
182
183registry = _Dso.DsoDb()
visit(self, typename, visitor=None, ctx=None)
classes ----------------------------------------------------------------—
STL class.
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:132
bool verbose
Definition hcg.cxx:75