StorageClassFactory

class lsst.daf.butler.StorageClassFactory

Bases: object

Factory for StorageClass instances.

This class is a singleton, with each instance sharing the pool of StorageClasses. Since code can not know whether it is the first time the instance has been created, the constructor takes no arguments. To populate the factory with storage classes, a call to addFromConfig() should be made.

Parameters:
configStorageClassConfig or str, optional

Load configuration. In a ButlerConfig` the relevant configuration is located in the storageClasses section.

Methods Summary

addFromConfig(config)

Add more StorageClass definitions from a config file.

getStorageClass(storageClassName)

Get a StorageClass instance associated with the supplied name.

makeNewStorageClass(name[, baseClass])

Create a new Python class as a subclass of StorageClass.

registerStorageClass(storageClass[, msg])

Store the StorageClass in the factory.

Methods Documentation

addFromConfig(config: StorageClassConfig | Config | str) None

Add more StorageClass definitions from a config file.

Parameters:
configStorageClassConfig, Config or str

Storage class configuration. Can contain a storageClasses key if part of a global configuration.

getStorageClass(storageClassName: str) StorageClass

Get a StorageClass instance associated with the supplied name.

Parameters:
storageClassNamestr

Name of the storage class to retrieve.

Returns:
instanceStorageClass

Instance of the correct StorageClass.

Raises:
KeyError

The requested storage class name is not registered.

static makeNewStorageClass(name: str, baseClass: ~typing.Type[~lsst.daf.butler.core.storageClass.StorageClass] | None = <class 'lsst.daf.butler.core.storageClass.StorageClass'>, **kwargs: ~typing.Any) Type[StorageClass]

Create a new Python class as a subclass of StorageClass.

Parameters:
namestr

Name to use for this class.

baseClasstype, optional

Base class for this StorageClass. Must be either StorageClass or a subclass of StorageClass. If None, StorageClass will be used.

Returns:
newtypetype subclass of StorageClass

Newly created Python type.

registerStorageClass(storageClass: StorageClass, msg: str | None = None) None

Store the StorageClass in the factory.

Will be indexed by StorageClass.name and will return instances of the supplied StorageClass.

Parameters:
storageClassStorageClass

Type of the Python StorageClass to register.

msgstr, optional

Additional message string to be included in any error message.

Raises:
ValueError

If a storage class has already been registered with that storage class name and the previous definition differs.