The Gaudi Framework  v36r7 (7f57a304)
Gaudi.Main Namespace Reference

Classes

class  BootstrapHelper
 
class  gaudimain
 

Functions

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

Variables

 log = logging.getLogger(__name__)
 

Function Documentation

◆ _getAllOpts_old()

def Gaudi.Main._getAllOpts_old (   explicit_defaults = False)
private
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 182 of file Main.py.

182 def _getAllOpts_old(explicit_defaults=False):
183  """
184  Return all options from the old configuration system as a dictionary.
185 
186  If explicit_defaults is true, include default values of unset properties in the dictionary.
187  """
188  from itertools import chain
189 
190  from GaudiKernel.Proxy.Configurable import Configurable, getNeededConfigurables
191 
192  old_opts = {}
193 
194  # some algorithms may be generater when we call "getValuedProperties"
195  # so we need a few iterations before we get the full list
196  # (see GaudiConfig.ControlFlow)
197  needed_conf = []
198  count = 0
199  new_count = -1
200  while count != new_count:
201  count = new_count
202  needed_conf = getNeededConfigurables()
203  new_count = len(needed_conf)
204  for n in needed_conf:
205  c = Configurable.allConfigurables[n]
206  if hasattr(c, "getValuedProperties"):
207  c.getValuedProperties()
208 
209  for n in needed_conf:
210  c = Configurable.allConfigurables[n]
211  items = (
212  chain(c.getDefaultProperties().items(), c.getValuedProperties().items())
213  if explicit_defaults
214  else c.getValuedProperties().items()
215  )
216  for p, v in items:
217  # Note: AthenaCommon.Configurable does not have Configurable.PropertyReference
218  if (
219  hasattr(Configurable, "PropertyReference")
220  and type(v) == Configurable.PropertyReference
221  ):
222  # this is done in "getFullName", but the exception is ignored,
223  # so we do it again to get it
224  v = v.__resolve__()
225  if isinstance(v, str):
226  # properly escape quotes in the string (see gaudi/Gaudi#78)
227  v = '"%s"' % v.replace('"', '\\"')
228  elif sys.version_info < (3,) and isinstance(v, long):
229  v = "%d" % v # prevent pending 'L'
230  elif hasattr(v, "__opt_value__"):
231  v = v.__opt_value__()
232  old_opts[".".join((n, p))] = str(v)
233 
234  return old_opts
235 
236 

◆ getAllOpts()

def 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 237 of file Main.py.

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

◆ parseOpt()

def 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 299 of file Main.py.

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

◆ toOpt()

def 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 275 of file Main.py.

275 def toOpt(value):
276  """
277  Helper to convert values to old .opts format.
278 
279  >>> print(toOpt('some "text"'))
280  "some \\"text\\""
281  >>> print(toOpt('first\\nsecond'))
282  "first
283  second"
284  >>> print(toOpt({'a': [1, 2, '3']}))
285  {"a": [1, 2, "3"]}
286  """
287  if isinstance(value, six.string_types):
288  return '"{0}"'.format(value.replace('"', '\\"'))
289  elif isinstance(value, dict):
290  return "{{{0}}}".format(
291  ", ".join("{0}: {1}".format(toOpt(k), toOpt(v)) for k, v in value.items())
292  )
293  elif hasattr(value, "__iter__"):
294  return "[{0}]".format(", ".join(map(toOpt, value)))
295  else:
296  return repr(value)
297 
298 

Variable Documentation

◆ log

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

Definition at line 22 of file Main.py.

Containers::map
struct GAUDI_API map
Parametrisation class for map-like implementation.
Definition: KeyedObjectManager.h:35
GaudiKernel.Proxy.getNeededConfigurables
getNeededConfigurables
Definition: Proxy.py:30
Gaudi.Main.parseOpt
def parseOpt(s)
Definition: Main.py:299
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
gaudirun.type
type
Definition: gaudirun.py:160
Gaudi.Main._getAllOpts_old
def _getAllOpts_old(explicit_defaults=False)
Definition: Main.py:182
Gaudi.Main.toOpt
def toOpt(value)
Definition: Main.py:275
Gaudi.Main.getAllOpts
def getAllOpts(explicit_defaults=False)
Definition: Main.py:237
GaudiPython.Pythonizations.items
items
Definition: Pythonizations.py:546