LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Private Attributes | List of all members
lsst.pex.config.registry.Registry Class Reference
Inheritance diagram for lsst.pex.config.registry.Registry:

Public Member Functions

def __init__
 
def register
 
def __getitem__
 
def __len__
 
def __iter__
 
def __contains__
 
def makeField
 

Private Attributes

 _configBaseType
 
 _dict
 

Detailed Description

A base class for global registries, mapping names to configurables.

There are no hard requirements on configurable, but they typically create an algorithm
or are themselves the algorithm, and typical usage is as follows:
- configurable is a callable whose call signature is (config, ...extra arguments...)
- All configurables added to a particular registry will have the same call signature
- All configurables in a registry will typically share something important in common.
  For example all configurables in psfMatchingRegistry return a psf matching
  class that has a psfMatch method with a particular call signature.

A registry acts like a read-only dictionary with an additional register method to add items.
The dict contains configurables and each configurable has an instance ConfigClass.

Example:
registry = Registry()
class FooConfig(Config):
    val = Field(dtype=int, default=3, doc="parameter for Foo")
class Foo(object):
    ConfigClass = FooConfig
    def __init__(self, config):
        self.config = config
    def addVal(self, num):
        return self.config.val + num
registry.register("foo", Foo)
names = registry.keys() # returns ("foo",)
fooConfigurable = registry["foo"]
fooConfig = fooItem.ConfigClass()
foo = fooConfigurable(fooConfig)
foo.addVal(5) # returns config.val + 5

Definition at line 44 of file registry.py.

Constructor & Destructor Documentation

def lsst.pex.config.registry.Registry.__init__ (   self,
  configBaseType = Config 
)
Construct a registry of name: configurables

@param configBaseType: base class for config classes in registry

Definition at line 76 of file registry.py.

76 
77  def __init__(self, configBaseType=Config):
78  """Construct a registry of name: configurables
79 
80  @param configBaseType: base class for config classes in registry
81  """
82  if not issubclass(configBaseType, Config):
83  raise TypeError("configBaseType=%s must be a subclass of Config" % _typeStr(configBaseType,))
84  self._configBaseType = configBaseType
85  self._dict = {}

Member Function Documentation

def lsst.pex.config.registry.Registry.__contains__ (   self,
  key 
)

Definition at line 113 of file registry.py.

114  def __contains__(self, key): return key in self._dict
def lsst.pex.config.registry.Registry.__getitem__ (   self,
  key 
)

Definition at line 110 of file registry.py.

def __getitem__(self, key): return self._dict[key]
def lsst.pex.config.registry.Registry.__iter__ (   self)

Definition at line 112 of file registry.py.

def __iter__(self): return iter(self._dict)
def lsst.pex.config.registry.Registry.__len__ (   self)

Definition at line 111 of file registry.py.

def __len__(self): return len(self._dict)
def lsst.pex.config.registry.Registry.makeField (   self,
  doc,
  default = None,
  optional = False,
  multi = False 
)

Definition at line 115 of file registry.py.

116  def makeField(self, doc, default=None, optional=False, multi=False):
117  return RegistryField(doc, self, default, optional, multi)
def lsst.pex.config.registry.Registry.register (   self,
  name,
  target,
  ConfigClass = None 
)
Add a new item to the registry.

@param target       A callable 'object that takes a Config instance as its first argument.
            This may be a Python type, but is not required to be.
@param ConfigClass  A subclass of pex_config Config used to configure the configurable;
            if None then configurable.ConfigClass is used.
          
@note: If ConfigClass is provided then then 'target' is wrapped in a new object that forwards
       function calls to it.  Otherwise the original 'target' is stored.

@raise AttributeError if ConfigClass is None and target does not have attribute ConfigClass

Definition at line 86 of file registry.py.

86 
87  def register(self, name, target, ConfigClass=None):
88  """Add a new item to the registry.
89 
90  @param target A callable 'object that takes a Config instance as its first argument.
91  This may be a Python type, but is not required to be.
92  @param ConfigClass A subclass of pex_config Config used to configure the configurable;
93  if None then configurable.ConfigClass is used.
94 
95  @note: If ConfigClass is provided then then 'target' is wrapped in a new object that forwards
96  function calls to it. Otherwise the original 'target' is stored.
97 
98  @raise AttributeError if ConfigClass is None and target does not have attribute ConfigClass
99  """
100  if name in self._dict:
101  raise RuntimeError("An item with name %r already exists" % name)
102  if ConfigClass is None:
103  wrapper = target
104  else:
105  wrapper = ConfigurableWrapper(target, ConfigClass)
106  if not issubclass(wrapper.ConfigClass, self._configBaseType):
107  raise TypeError("ConfigClass=%s is not a subclass of %r" % \
108  (_typeStr(wrapper.ConfigClass), _typeStr(self._configBaseType)))
109  self._dict[name] = wrapper

Member Data Documentation

lsst.pex.config.registry.Registry._configBaseType
private

Definition at line 83 of file registry.py.

lsst.pex.config.registry.Registry._dict
private

Definition at line 84 of file registry.py.


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