The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
Gaudi.Main Namespace Reference

Classes

class  BootstrapHelper
 
class  gaudimain
 

Functions

 _getAllOpts_old (explicit_defaults=False)
 
 getAllOpts (explicit_defaults=False)
 
 toOpt (value)
 
 parseOpt (s)
 

Variables

 log = logging.getLogger(__name__)
 

Function Documentation

◆ _getAllOpts_old()

Gaudi.Main._getAllOpts_old ( explicit_defaults = False)
protected
Return all options from the old configuration system as a dictionary.

If explicit_defaults is true, include default values of unset properties in the dictionary.

Definition at line 178 of file Main.py.

178def _getAllOpts_old(explicit_defaults=False):
179 """
180 Return all options from the old configuration system as a dictionary.
181
182 If explicit_defaults is true, include default values of unset properties in the dictionary.
183 """
184 from itertools import chain
185
186 from GaudiKernel.Proxy.Configurable import Configurable, getNeededConfigurables
187
188 old_opts = {}
189
190 # Keep track of which algorithms we have already processed to avoid
191 # computing them many times
192 done_conf = set()
193 # More algorithms may be generated when we call "getValuedProperties" so we
194 # may need a few iterations before we get the full list
195 # (see GaudiConfig.ControlFlow)
196 while True:
197 needed_conf = [n for n in getNeededConfigurables() if n not in done_conf]
198 if not needed_conf:
199 break
200
201 for n in needed_conf:
202 done_conf.add(n)
203 c = Configurable.allConfigurables[n]
204 items = getattr(c, "getValuedProperties", dict)().items()
205 if explicit_defaults:
206 items = chain(c.getDefaultProperties().items(), items)
207 for p, v in items:
208 # Note: AthenaCommon.Configurable does not have Configurable.PropertyReference
209 if hasattr(Configurable, "PropertyReference") and isinstance(
210 v, Configurable.PropertyReference
211 ):
212 # this is done in "getFullName", but the exception is ignored,
213 # so we do it again to get it
214 v = v.__resolve__()
215 if isinstance(v, str):
216 # properly escape quotes in the string (see gaudi/Gaudi#78)
217 v = '"%s"' % v.replace('"', '\\"')
218 elif hasattr(v, "__opt_value__"):
219 v = v.__opt_value__()
220 old_opts[".".join((n, p))] = str(v)
221
222 return old_opts
223
224

◆ getAllOpts()

Gaudi.Main.getAllOpts ( explicit_defaults = False)
Return all options from the old and new configuration system as a dictionary.

If explicit_defaults is true, include default values of unset properties in the dictionary.

Definition at line 225 of file Main.py.

225def getAllOpts(explicit_defaults=False):
226 """
227 Return all options from the old and new configuration system as a dictionary.
228
229 If explicit_defaults is true, include default values of unset properties in the dictionary.
230 """
231 import GaudiConfig2
232
233 # We need to run normal (without defaults) collection first (regardless of explicit_defaults)
234 # as the conflicts detection makes sense only for explicitly set options
235 old_opts = _getAllOpts_old(False)
236 opts = GaudiConfig2.all_options(False)
237
238 conflicts = [n for n in set(opts).intersection(old_opts) if opts[n] != old_opts[n]]
239 if conflicts:
240 conflicts.sort()
241 log.error("Some properties are set in old and new style configuration")
242 log.warning("name: old -> new")
243 for n in conflicts:
244 log.warning("%s: %s -> %s", n, old_opts[n], opts[n])
245 sys.exit(10)
246
247 opts.update(old_opts)
248
249 if explicit_defaults:
250 # If we are asked to print also the defaults, we collect everything
251 # and blindly merge to make sure we have the full set of configurables
252 all_opts = _getAllOpts_old(True)
253 all_opts.update(GaudiConfig2.all_options(True))
254 # the we override the dictionary with the explicitly set options
255 # (that leaves the defaults untouched and the set options with the
256 # correct value)
257 all_opts.update(opts)
258 opts = all_opts
259
260 return opts
261
262

◆ parseOpt()

Gaudi.Main.parseOpt ( s)
Helper to parse option strings to Python values.

Ideally it should just be "eval", but the string parser of Gaudi
is different from the Python one, so we get string options that
cannot be just evaluated.

>>> print(parseOpt('123'))
123
>>> print(parseOpt('"some\\n\\\\"text\\\\""'))
some
"text"
>>> print(parseOpt(''))
<BLANKLINE>

(see gaudi/Gaudi#78)

Definition at line 287 of file Main.py.

287def parseOpt(s):
288 """
289 Helper to parse option strings to Python values.
290
291 Ideally it should just be "eval", but the string parser of Gaudi
292 is different from the Python one, so we get string options that
293 cannot be just evaluated.
294
295 >>> print(parseOpt('123'))
296 123
297 >>> print(parseOpt('"some\\n\\\\"text\\\\""'))
298 some
299 "text"
300 >>> print(parseOpt(''))
301 <BLANKLINE>
302
303 (see gaudi/Gaudi#78)
304 """
305 import re
306
307 quoted_string = re.compile(r'^"(.*)"$', re.DOTALL)
308 # FIXME: this is needed because we cannot use repr for strings
309 # (see gaudi/Gaudi#78)
310 if not s: # pass through empty strings
311 return s
312 m = quoted_string.match(s)
313 if m:
314 return m.group(1).replace('\\"', '"')
315 return eval(s)
316
317

◆ toOpt()

Gaudi.Main.toOpt ( value)
Helper to convert values to old .opts format.

>>> print(toOpt('some "text"'))
"some \\"text\\""
>>> print(toOpt('first\\nsecond'))
"first
second"
>>> print(toOpt({'a': [1, 2, '3']}))
{"a": [1, 2, "3"]}

Definition at line 263 of file Main.py.

263def toOpt(value):
264 """
265 Helper to convert values to old .opts format.
266
267 >>> print(toOpt('some "text"'))
268 "some \\"text\\""
269 >>> print(toOpt('first\\nsecond'))
270 "first
271 second"
272 >>> print(toOpt({'a': [1, 2, '3']}))
273 {"a": [1, 2, "3"]}
274 """
275 if isinstance(value, str):
276 return '"{0}"'.format(value.replace('"', '\\"'))
277 elif isinstance(value, dict):
278 return "{{{0}}}".format(
279 ", ".join("{0}: {1}".format(toOpt(k), toOpt(v)) for k, v in value.items())
280 )
281 elif hasattr(value, "__iter__"):
282 return "[{0}]".format(", ".join(map(toOpt, value)))
283 else:
284 return repr(value)
285
286
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition MsgStream.cpp:93

Variable Documentation

◆ log

Gaudi.Main.log = logging.getLogger(__name__)

Definition at line 18 of file Main.py.