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