StorageClassFactory¶
- class lsst.daf.butler.StorageClassFactory¶
Bases:
objectFactory for
StorageClassinstances.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:
- config
StorageClassConfigorstr, optional Load configuration. In a ButlerConfig` the relevant configuration is located in the
storageClassessection.
- config
Methods Summary
addFromConfig(config)Add more
StorageClassdefinitions from a config file.findStorageClass(pytype[, compare_types])Find the storage class associated with this python type.
getStorageClass(storageClassName)makeNewStorageClass(name[, baseClass])Create a new Python class as a subclass of
StorageClass.registerStorageClass(storageClass[, msg])Store the
StorageClassin the factory.reset()Remove all storage class entries from factory and reset to initial state.
Methods Documentation
- addFromConfig(config: StorageClassConfig | Config | str) None¶
Add more
StorageClassdefinitions from a config file.- Parameters:
- config
StorageClassConfig,Configorstr Storage class configuration. Can contain a
storageClasseskey if part of a global configuration.
- config
- findStorageClass(pytype: type, compare_types: bool = False) StorageClass¶
Find the storage class associated with this python type.
- Parameters:
- pytype
type The Python type to be matched.
- compare_types
bool, optional If
False, the type will be checked against name of the python type. This comparison is always done first. IfTrueand the string comparison failed, each candidate storage class will be forced to have its type imported. This can be significantly slower.
- pytype
- Returns:
- storageClass
StorageClass The matching storage class.
- storageClass
- Raises:
- KeyError
Raised if no match could be found.
Notes
It is possible for a python type to be associated with multiple storage classes. This method will currently return the first that matches.
- getStorageClass(storageClassName: str) StorageClass¶
- static makeNewStorageClass(name: str, baseClass: type[lsst.daf.butler._storage_class.StorageClass] | None = <class 'lsst.daf.butler._storage_class.StorageClass'>, **kwargs: ~typing.Any) type[lsst.daf.butler._storage_class.StorageClass]¶
Create a new Python class as a subclass of
StorageClass.- Parameters:
- name
str Name to use for this class.
- baseClass
type, optional Base class for this
StorageClass. Must be eitherStorageClassor a subclass ofStorageClass. IfNone,StorageClasswill be used.- **kwargs
Additional parameter values to use as defaults for this class. This can include
components,parameters,derivedComponents, andconverters.
- name
- Returns:
- newtype
typesubclass ofStorageClass Newly created Python type.
- newtype
- registerStorageClass(storageClass: StorageClass, msg: str | None = None) None¶
Store the
StorageClassin the factory.Will be indexed by
StorageClass.nameand will return instances of the suppliedStorageClass.- Parameters:
- storageClass
StorageClass Type of the Python
StorageClassto register.- msg
str, optional Additional message string to be included in any error message.
- storageClass
- Raises:
- ValueError
If a storage class has already been registered with that storage class name and the previous definition differs.