All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Public Attributes | Static Private Attributes | List of all members
galleryUtils.ConfigurationHelper Class Reference

Public Member Functions

def __init__
 
def get
 
def has
 
def pset
 
def __init__
 
def get
 
def has
 
def pset
 

Public Attributes

 config
 

Static Private Attributes

 __call__ = get
 

Detailed Description

Provides more user-friendly interface for the configuration access.

While FHiCL C++ interface is friendly enough, some of that is lost in Python
bindings.

This helper class keeps a reference to the FHiCL configuration object, and
provides some `get()` overloads to make the interface easier.

Definition at line 337 of file icarusalg/icarusalg/gallery/helpers/python/galleryUtils.py.

Constructor & Destructor Documentation

def galleryUtils.ConfigurationHelper.__init__ (   self,
  config 
)
def galleryUtils.ConfigurationHelper.__init__ (   self,
  config 
)

Definition at line 245 of file sbndcode/sbndcode/gallery/python/galleryUtils.py.

246  def __init__(self, config):
self.config = config

Member Function Documentation

def galleryUtils.ConfigurationHelper.get (   self,
  key,
  default = None,
  klass = None 
)
Returns the value associated with the specified key.

Parameters
-----------

key _(string)_
  the key of the configuration parameter to be read
default
  the value to provide if no key is present; if default is `None`,
  no default is present and if key is missing a `KeyError` exception will
  be raised
klass _(class type)_
  type of object returned (if `None`, it's taken from `default` if
  specified)

Returns
--------

An object of type `klass`, initialised with the value associated to `key`
or with `default`.

Raises
-------

`KeyError` if the `key` is not present in the configuration and `default` is
specified as `None`.

Definition at line 247 of file sbndcode/sbndcode/gallery/python/galleryUtils.py.

248  def get(self, key, default=None, klass=None):
249  """
250  Returns the value associated with the specified key.
251 
252  Parameters
253  -----------
254 
255  key _(string)_
256  the key of the configuration parameter to be read
257  default
258  the value to provide if no key is present; if default is `None`,
259  no default is present and if key is missing a `KeyError` exception will
260  be raised
261  klass _(class type)_
262  type of object returned (if `None`, it's taken from `default` if
263  specified)
264 
265  Returns
266  --------
267 
268  An object of type `klass`, initialised with the value associated to `key`
269  or with `default`.
270 
271  Raises
272  -------
273 
274  `KeyError` if the `key` is not present in the configuration and `default` is
275  specified as `None`.
276 
277  """
278  if klass is None:
279  assert default is not None
280  klass = default.__class__
281  # first try to directly return the key
282  try: return self.config.get[klass](key)
283  except Exception: pass
284  # if that failed, act depending on the default value
285  if default is None: raise KeyError(key)
return klass(default)
def galleryUtils.ConfigurationHelper.get (   self,
  key,
  default = None,
  klass = None 
)
Returns the value associated with the specified key.

Parameters
-----------

key _(string)_
  the key of the configuration parameter to be read
default
  the value to provide if no key is present; if default is `None`,
  no default is present and if key is missing a `KeyError` exception will
  be raised
klass _(class type)_
  type of object returned (if `None`, it's taken from `default` if
  specified)

Returns
--------

An object of type `klass`, initialised with the value associated to `key`
or with `default`.

Raises
-------

`KeyError` if the `key` is not present in the configuration and `default` is
specified as `None`.

Definition at line 349 of file icarusalg/icarusalg/gallery/helpers/python/galleryUtils.py.

350  def get(self, key, default=None, klass=None):
351  """
352  Returns the value associated with the specified key.
353 
354  Parameters
355  -----------
356 
357  key _(string)_
358  the key of the configuration parameter to be read
359  default
360  the value to provide if no key is present; if default is `None`,
361  no default is present and if key is missing a `KeyError` exception will
362  be raised
363  klass _(class type)_
364  type of object returned (if `None`, it's taken from `default` if
365  specified)
366 
367  Returns
368  --------
369 
370  An object of type `klass`, initialised with the value associated to `key`
371  or with `default`.
372 
373  Raises
374  -------
375 
376  `KeyError` if the `key` is not present in the configuration and `default` is
377  specified as `None`.
378 
379  """
380  if klass is None:
381  assert default is not None
382  klass = default.__class__
383  # first try to directly return the key
384  try: return self.config.get[klass](key)
385  except Exception: pass
386  # if that failed, act depending on the default value
387  if default is None: raise KeyError(key)
return klass(default)
def galleryUtils.ConfigurationHelper.has (   self,
  key 
)
Returns whether there is a value associated with the specified key.

Parameters
-----------

key _(string)_
  the key of the configuration parameter to be read

Definition at line 288 of file sbndcode/sbndcode/gallery/python/galleryUtils.py.

289  def has(self, key):
290  """
291  Returns whether there is a value associated with the specified key.
292 
293  Parameters
294  -----------
295 
296  key _(string)_
297  the key of the configuration parameter to be read
298 
299  """
return self.config.has(klass)
def galleryUtils.ConfigurationHelper.has (   self,
  key 
)
Returns whether there is a value associated with the specified key.

Parameters
-----------

key _(string)_
  the key of the configuration parameter to be read

Definition at line 390 of file icarusalg/icarusalg/gallery/helpers/python/galleryUtils.py.

391  def has(self, key):
392  """
393  Returns whether there is a value associated with the specified key.
394 
395  Parameters
396  -----------
397 
398  key _(string)_
399  the key of the configuration parameter to be read
400 
401  """
return self.config.has(klass)
def galleryUtils.ConfigurationHelper.pset (   self)

Definition at line 304 of file sbndcode/sbndcode/gallery/python/galleryUtils.py.

305  def pset(self): return self.config
306 
307 # class ConfigurationHelper
def galleryUtils.ConfigurationHelper.pset (   self)

Definition at line 406 of file icarusalg/icarusalg/gallery/helpers/python/galleryUtils.py.

407  def pset(self): return self.config
408 
409 # class ConfigurationHelper
410 

Member Data Documentation

galleryUtils.ConfigurationHelper.__call__ = get
staticprivate

Definition at line 404 of file icarusalg/icarusalg/gallery/helpers/python/galleryUtils.py.

galleryUtils.ConfigurationHelper.config

Definition at line 348 of file icarusalg/icarusalg/gallery/helpers/python/galleryUtils.py.


The documentation for this class was generated from the following files: