The Gaudi Framework  v36r13 (995e4364)
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 180 of file Main.py.

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

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

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

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

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

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

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

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:30
Gaudi.Main.parseOpt
def parseOpt(s)
Definition: Main.py:295
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
gaudirun.type
type
Definition: gaudirun.py:162
Gaudi.Main._getAllOpts_old
def _getAllOpts_old(explicit_defaults=False)
Definition: Main.py:180
Gaudi.Main.toOpt
def toOpt(value)
Definition: Main.py:271
Gaudi.Main.getAllOpts
def getAllOpts(explicit_defaults=False)
Definition: Main.py:233
GaudiPython.Pythonizations.items
items
Definition: Pythonizations.py:546