The Gaudi Framework  v41r0 (bdbe7744)
Loading...
Searching...
No Matches
GaudiConfig2._db.ConfigurablesDB Class Reference

Public Member Functions

 __init__ (self, modulename, root=None)
 __getattr__ (self, name)
 getByType (self, typename)

Protected Member Functions

 _getEntries (self)

Protected Attributes

 _log = logging.getLogger(modulename)
 _root = root or modulename
str _namespace = modulename[len(root) + 1 :].replace(".", "::") if root else ""
 _namespaces
 _classes = self._getEntries()
dict _alt_names = {}

Private Attributes

 __name__ = modulename
 __loader__ = None
 __all__

Detailed Description

Helper to expose Configurables classes (from Configurables database) as
a tree of subpackages, each mapped to a namespace.

Definition at line 94 of file _db.py.

Constructor & Destructor Documentation

◆ __init__()

GaudiConfig2._db.ConfigurablesDB.__init__ ( self,
modulename,
root = None )
@param modulename: name of the module
@param root: name of the root modules (that pointing to the root C++
             namespace), None is ewuivalent to pass modulename as root

Definition at line 100 of file _db.py.

100 def __init__(self, modulename, root=None):
101 """
102 @param modulename: name of the module
103 @param root: name of the root modules (that pointing to the root C++
104 namespace), None is ewuivalent to pass modulename as root
105 """
106 self._log = logging.getLogger(modulename)
107 self._log.debug("initializing module %r (with root %r)", modulename, root)
108
109 self.__name__ = modulename
110 self.__loader__ = None
111 self._root = root or modulename
112 assert (not root) or modulename.startswith(
113 root + "."
114 ), "modulename should be (indirect submodule of root)"
115
116 self._namespace = modulename[len(root) + 1 :].replace(".", "::") if root else ""
117 self._log.debug("%r mapping namespace %r", modulename, self._namespace or "::")
118
119 self._namespaces, self._classes = self._getEntries()
120 self._alt_names = {}
121 for cname in self._classes:
122 alt_name = _normalize_cpp_type_name(cname)
123 if alt_name != cname:
124 self._alt_names[alt_name] = cname
125 if " " in cname: # allow matching of 'T<A, B>' a well as 'T<A,B>'
126 self._alt_names[cname.replace(" ", "")] = cname
127 self.__all__ = list(
128 self._namespaces.union(self._classes).union(self._alt_names)
129 )
130
131 sys.modules[modulename] = self
132
133 for submodule in self._namespaces:
134 setattr(
135 self,
136 submodule,
137 ConfigurablesDB(".".join([self.__name__, submodule]), self._root),
138 )
139

Member Function Documentation

◆ __getattr__()

GaudiConfig2._db.ConfigurablesDB.__getattr__ ( self,
name )
Helper to instantiate on demand Configurable classes.

Definition at line 164 of file _db.py.

164 def __getattr__(self, name):
165 """
166 Helper to instantiate on demand Configurable classes.
167 """
168 if name in self._classes:
169 fullname = "::".join([self._namespace, name]) if self._namespace else name
170 from ._configurables import makeConfigurableClass
171
172 self._log.debug("generating %r (%s)", name, fullname)
173 entry = makeConfigurableClass(
174 name,
175 __module__=self.__name__,
176 __qualname__=name,
177 __cpp_type__=fullname,
178 **_DB[fullname],
179 )
180 elif name.replace(" ", "") in self._alt_names:
181 entry = getattr(self, self._alt_names[name.replace(" ", "")])
182 elif name == "__spec__": # pragma no cover
183 import importlib
184
185 entry = importlib.machinery.ModuleSpec(
186 name=self.__package__,
187 loader=self.__loader__,
188 )
189 elif name == "__package__": # pragma no cover
190 entry = self.__name__
191 else:
192 raise AttributeError(f"module {self.__name__!r} has no attribute {name!r}")
193 setattr(self, name, entry)
194 return entry
195

◆ _getEntries()

GaudiConfig2._db.ConfigurablesDB._getEntries ( self)
protected
Extract from the Configurables DB the namespaces and classes names in
the namespace this instance represents.

Definition at line 140 of file _db.py.

140 def _getEntries(self):
141 """
142 Extract from the Configurables DB the namespaces and classes names in
143 the namespace this instance represents.
144 """
145 self._log.debug("getting list of entries under %r", self._namespace)
146 prefix = self._namespace + "::" if self._namespace else ""
147 prefix_len = len(prefix)
148
149 namespaces = set()
150 classes = set()
151 for name in _DB:
152 if name.startswith(prefix):
153 head, tail = split_namespace(name[prefix_len:])
154 if head:
155 namespaces.add(head)
156 else:
157 classes.add(tail)
158
159 self._log.debug(
160 "found %d namespaces and %d classes", len(namespaces), len(classes)
161 )
162 return (namespaces, classes)
163

◆ getByType()

GaudiConfig2._db.ConfigurablesDB.getByType ( self,
typename )
Return a configurable from the fully qualified type name (relative to
the current namespace).any

Definition at line 196 of file _db.py.

196 def getByType(self, typename):
197 """
198 Return a configurable from the fully qualified type name (relative to
199 the current namespace).any
200 """
201 head, tail = split_namespace(typename)
202 if head:
203 return getattr(self, head).getByType(tail)
204 else:
205 return getattr(self, tail)

Member Data Documentation

◆ __all__

GaudiConfig2._db.ConfigurablesDB.__all__
private
Initial value:
= list(
self._namespaces.union(self._classes).union(self._alt_names)
)

Definition at line 127 of file _db.py.

◆ __loader__

GaudiConfig2._db.ConfigurablesDB.__loader__ = None
private

Definition at line 110 of file _db.py.

◆ __name__

GaudiConfig2._db.ConfigurablesDB.__name__ = modulename
private

Definition at line 109 of file _db.py.

◆ _alt_names

dict GaudiConfig2._db.ConfigurablesDB._alt_names = {}
protected

Definition at line 120 of file _db.py.

◆ _classes

GaudiConfig2._db.ConfigurablesDB._classes = self._getEntries()
protected

Definition at line 119 of file _db.py.

◆ _log

GaudiConfig2._db.ConfigurablesDB._log = logging.getLogger(modulename)
protected

Definition at line 106 of file _db.py.

◆ _namespace

GaudiConfig2._db.ConfigurablesDB._namespace = modulename[len(root) + 1 :].replace(".", "::") if root else ""
protected

Definition at line 116 of file _db.py.

◆ _namespaces

GaudiConfig2._db.ConfigurablesDB._namespaces
protected

Definition at line 119 of file _db.py.

◆ _root

GaudiConfig2._db.ConfigurablesDB._root = root or modulename
protected

Definition at line 111 of file _db.py.


The documentation for this class was generated from the following file:
  • GaudiConfiguration/python/GaudiConfig2/_db.py