The Gaudi Framework  v36r1 (3e2fb5a8)
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 172 of file Main.py.

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

◆ getAllOpts()

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

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

Definition at line 222 of file Main.py.

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

◆ 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 284 of file Main.py.

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

◆ 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 261 of file Main.py.

261 def toOpt(value):
262  '''
263  Helper to convert values to old .opts format.
264 
265  >>> print(toOpt('some "text"'))
266  "some \\"text\\""
267  >>> print(toOpt('first\\nsecond'))
268  "first
269  second"
270  >>> print(toOpt({'a': [1, 2, '3']}))
271  {"a": [1, 2, "3"]}
272  '''
273  if isinstance(value, six.string_types):
274  return '"{0}"'.format(value.replace('"', '\\"'))
275  elif isinstance(value, dict):
276  return '{{{0}}}'.format(', '.join(
277  '{0}: {1}'.format(toOpt(k), toOpt(v)) for k, v in value.items()))
278  elif hasattr(value, '__iter__'):
279  return '[{0}]'.format(', '.join(map(toOpt, value)))
280  else:
281  return repr(value)
282 
283 

Variable Documentation

◆ log

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

Definition at line 20 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:31
Gaudi.Main.parseOpt
def parseOpt(s)
Definition: Main.py:284
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
gaudirun.type
type
Definition: gaudirun.py:154
Gaudi.Main._getAllOpts_old
def _getAllOpts_old(explicit_defaults=False)
Definition: Main.py:172
Gaudi.Main.toOpt
def toOpt(value)
Definition: Main.py:261
Gaudi.Main.getAllOpts
def getAllOpts(explicit_defaults=False)
Definition: Main.py:222
GaudiPython.Pythonizations.items
items
Definition: Pythonizations.py:526