lsst.pex.config  16.0-5-gd0f1235+6
Public Member Functions | List of all members
lsst.pex.config.registry.Registry Class Reference
Inheritance diagram for lsst.pex.config.registry.Registry:

Public Member Functions

def __init__ (self, configBaseType=Config)
 
def register (self, name, target, ConfigClass=None)
 
def __getitem__ (self, key)
 
def __len__ (self)
 
def __iter__ (self)
 
def __contains__ (self, key)
 
def makeField (self, doc, default=None, optional=False, multi=False)
 

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:
    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 46 of file registry.py.

Constructor & Destructor Documentation

◆ __init__()

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 78 of file registry.py.

Member Function Documentation

◆ __contains__()

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

Definition at line 121 of file registry.py.

◆ __getitem__()

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

Definition at line 112 of file registry.py.

◆ __iter__()

def lsst.pex.config.registry.Registry.__iter__ (   self)

Definition at line 118 of file registry.py.

◆ __len__()

def lsst.pex.config.registry.Registry.__len__ (   self)

Definition at line 115 of file registry.py.

◆ makeField()

def lsst.pex.config.registry.Registry.makeField (   self,
  doc,
  default = None,
  optional = False,
  multi = False 
)

Definition at line 124 of file registry.py.

◆ register()

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 88 of file registry.py.


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