CollectionManager¶
- class lsst.daf.butler.registry.interfaces.CollectionManager(*, registry_schema_version: VersionTuple | None = None)¶
Bases:
Generic
[_Key
],VersionedExtension
An interface for managing the collections (including runs) in a
Registry
.- Parameters:
- registry_schema_version
VersionTuple
orNone
, optional Version of registry schema.
- registry_schema_version
Notes
Each layer in a multi-layer
Registry
has its own record for any collection for which it has datasets (or quanta). Different layers may use different IDs for the same collection, so any usage of the IDs obtained through theCollectionManager
APIs are strictly for internal (toRegistry
) use.Methods Summary
addCollectionForeignKey
(tableSpec, *[, ...])Add a foreign key (field and constraint) referencing the collection table.
addRunForeignKey
(tableSpec, *[, prefix, ...])Add a foreign key (field and constraint) referencing the run table.
checkCompatibility
(registry_schema_version, ...)Check that schema version defined in registry is compatible with current implementation.
checkNewSchemaVersion
(schema_version)Verify that requested schema version can be created by an extension.
clsNewSchemaVersion
(schema_version)Class method which returns schema version to use for newly created registry database.
Return schema version(s) supported by this extension class.
Return full name of the extension.
find
(name)Return the collection record associated with the given name.
getCollectionForeignKeyName
([prefix])Return the name of the field added by
addCollectionForeignKey
if called with the same prefix.getDocumentation
(key)Retrieve the documentation string for a collection.
getParentChains
(key)Find all CHAINED collection names that directly contain the given collection.
getRunForeignKeyName
([prefix])Return the name of the field added by
addRunForeignKey
if called with the same prefix.initialize
(db, context, *, dimensions, ...)Construct an instance of the manager.
Return schema version for newly created registry.
refresh
()Ensure all other operations on this manager are aware of any collections that may have been registered by other clients since it was initialized or last refreshed.
register
(name, type[, doc])Ensure that a collection of the given name and type are present in the layer this manager is associated with.
remove
(name)Completely remove a collection.
resolve_wildcard
(wildcard, *[, ...])Iterate over collection records that match a wildcard.
setDocumentation
(key, doc)Set the documentation string for a collection.
update_chain
(record, children[, flatten])Update chained collection composition.
Methods Documentation
- abstract classmethod addCollectionForeignKey(tableSpec: TableSpec, *, prefix: str = 'collection', onDelete: str | None = None, constraint: bool = True, **kwargs: Any) FieldSpec ¶
Add a foreign key (field and constraint) referencing the collection table.
- Parameters:
- tableSpec
ddl.TableSpec
Specification for the table that should reference the collection table. Will be modified in place.
- prefix
str
, optional A name to use for the prefix of the new field; the full name may have a suffix (and is given in the returned
ddl.FieldSpec
).- onDelete
str
, optional One of “CASCADE” or “SET NULL”, indicating what should happen to the referencing row if the collection row is deleted.
None
indicates that this should be an integrity error.- constraint
bool
, optional If
False
(True
is default), add a field that can be joined to the collection primary key, but do not add a foreign key constraint.- **kwargs
Additional keyword arguments are forwarded to the
ddl.FieldSpec
constructor (only thename
anddtype
arguments are otherwise provided).
- tableSpec
- Returns:
- fieldSpec
ddl.FieldSpec
Specification for the field being added.
- fieldSpec
- abstract classmethod addRunForeignKey(tableSpec: TableSpec, *, prefix: str = 'run', onDelete: str | None = None, constraint: bool = True, **kwargs: Any) FieldSpec ¶
Add a foreign key (field and constraint) referencing the run table.
- Parameters:
- tableSpec
ddl.TableSpec
Specification for the table that should reference the run table. Will be modified in place.
- prefix
str
, optional A name to use for the prefix of the new field; the full name may have a suffix (and is given in the returned
ddl.FieldSpec
).- onDelete
str
, optional One of “CASCADE” or “SET NULL”, indicating what should happen to the referencing row if the collection row is deleted.
None
indicates that this should be an integrity error.- constraint
bool
, optional If
False
(True
is default), add a field that can be joined to the run primary key, but do not add a foreign key constraint.- **kwargs
Additional keyword arguments are forwarded to the
ddl.FieldSpec
constructor (only thename
anddtype
arguments are otherwise provided).
- tableSpec
- Returns:
- fieldSpec
ddl.FieldSpec
Specification for the field being added.
- fieldSpec
- classmethod checkCompatibility(registry_schema_version: VersionTuple, update: bool) None ¶
Check that schema version defined in registry is compatible with current implementation.
- Parameters:
- registry_schema_version
VersionTuple
Schema version that exists in registry or defined in a configuration for a registry to be created.
- update
bool
If True then read-write access is expected.
- registry_schema_version
- Raises:
- IncompatibleVersionError
Raised if schema version is not supported by implementation.
Notes
Default implementation uses
VersionTuple.checkCompatibility
on the versions returned fromcurrentVersions
method. Subclasses that support different compatibility model will overwrite this method.
- classmethod checkNewSchemaVersion(schema_version: VersionTuple) None ¶
Verify that requested schema version can be created by an extension.
- Parameters:
- schema_version
VersionTuple
Schema version that this extension is asked to create.
- schema_version
Notes
This method may be used only occasionally when a specific schema version is given in a regisitry config file. This can be used with an extension that supports multiple schem versions to make it create new schema with a non-default version number. Default implementation compares requested version with one of the version returned from
currentVersions
.
- classmethod clsNewSchemaVersion(schema_version: VersionTuple | None) VersionTuple | None ¶
Class method which returns schema version to use for newly created registry database.
- Parameters:
- schema_version
VersionTuple
orNone
Configured schema version or
None
if default schema version should be created. If notNone
then it is guaranteed to be compatible withcurrentVersions
.
- schema_version
- Returns:
- version
VersionTuple
orNone
Schema version created by this extension.
None
is returned if an extension does not require its version to be saved or checked.
- version
Notes
Default implementation of this method can work in simple cases. If the extension only supports single schema version than that version is returned. If the extension supports multiple schema versions and
schema_version
is notNone
thenschema_version
is returned. If the extension supports multiple schema versions, butschema_version
isNone
it calls_newDefaultSchemaVersion
method which needs to be reimplemented in a subsclass.
- abstract classmethod currentVersions() list[lsst.daf.butler.registry.interfaces._versioning.VersionTuple] ¶
Return schema version(s) supported by this extension class.
- Returns:
- version
list
[VersionTuple
] Schema versions for this extension. Empty list is returned if an extension does not require its version to be saved or checked.
- version
- classmethod extensionName() str ¶
Return full name of the extension.
This name should match the name defined in registry configuration. It is also stored in registry attributes. Default implementation returns full class name.
- Returns:
- name
str
Full extension name.
- name
- abstract find(name: str) CollectionRecord[_Key] ¶
Return the collection record associated with the given name.
- Parameters:
- name
str
Name of the collection.
- name
- Returns:
- record
CollectionRecord
Object representing the collection, including its type and ID. If
record.type is CollectionType.RUN
, this will be aRunRecord
instance. Ifrecord.type is CollectionType.CHAIN
, this will be aChainedCollectionRecord
instance.
- record
- Raises:
- MissingCollectionError
Raised if the given collection does not exist.
Notes
Collections registered by another client of the same layer since the last call to
initialize
orrefresh
may not be found.
- abstract classmethod getCollectionForeignKeyName(prefix: str = 'collection') str ¶
Return the name of the field added by
addCollectionForeignKey
if called with the same prefix.
- abstract getDocumentation(key: _Key) str | None ¶
Retrieve the documentation string for a collection.
- abstract getParentChains(key: _Key) set[str] ¶
Find all CHAINED collection names that directly contain the given collection.
- abstract classmethod getRunForeignKeyName(prefix: str = 'run') str ¶
Return the name of the field added by
addRunForeignKey
if called with the same prefix.
- abstract classmethod initialize(db: Database, context: StaticTablesContext, *, dimensions: DimensionRecordStorageManager, caching_context: CachingContext, registry_schema_version: VersionTuple | None = None) CollectionManager ¶
Construct an instance of the manager.
- Parameters:
- db
Database
Interface to the underlying database engine and namespace.
- context
StaticTablesContext
Context object obtained from
Database.declareStaticTables
; used to declare any tables that should always be present in a layer implemented with this manager.- dimensions
DimensionRecordStorageManager
Manager object for the dimensions in this
Registry
.- caching_context
CachingContext
Object controlling caching of information returned by managers.
- registry_schema_version
VersionTuple
orNone
Schema version of this extension as defined in registry.
- db
- Returns:
- manager
CollectionManager
An instance of a concrete
CollectionManager
subclass.
- manager
- newSchemaVersion() VersionTuple | None ¶
Return schema version for newly created registry.
- Returns:
- version
VersionTuple
orNone
Schema version created by this extension.
None
is returned if an extension does not require its version to be saved or checked.
- version
Notes
Extension classes that support multiple schema versions need to override
_newDefaultSchemaVersion
method.
- abstract refresh() None ¶
Ensure all other operations on this manager are aware of any collections that may have been registered by other clients since it was initialized or last refreshed.
- abstract register(name: str, type: CollectionType, doc: str | None = None) tuple[lsst.daf.butler.registry.interfaces._collections.CollectionRecord[_Key], bool] ¶
Ensure that a collection of the given name and type are present in the layer this manager is associated with.
- Parameters:
- Returns:
- record
CollectionRecord
Object representing the collection, including its type and ID. If
type is CollectionType.RUN
, this will be aRunRecord
instance. Iftype is CollectionType.CHAIN
, this will be aChainedCollectionRecord
instance.- registered
bool
True if the collection was registered,
False
if it already existed.
- record
- Raises:
- TransactionInterruption
Raised if this operation is invoked within a
Database.transaction
context.- DatabaseConflictError
Raised if a collection with this name but a different type already exists.
Notes
Concurrent registrations of the same collection should be safe; nothing should happen if the types are consistent, and integrity errors due to inconsistent types should happen before any database changes are made.
- abstract remove(name: str) None ¶
Completely remove a collection.
Any existing
CollectionRecord
objects that correspond to the removed collection are considered invalidated.- Parameters:
- name
str
Name of the collection to remove.
- name
Notes
If this collection is referenced by foreign keys in tables managed by other objects, the ON DELETE clauses of those tables will be invoked. That will frequently delete many dependent rows automatically (via “CASCADE”, but it may also cause this operation to fail (with rollback) unless dependent rows that do not have an ON DELETE clause are removed first.
- abstract resolve_wildcard(wildcard: CollectionWildcard, *, collection_types: Set[CollectionType] = frozenset({CollectionType.RUN, CollectionType.TAGGED, CollectionType.CHAINED, CollectionType.CALIBRATION}), done: set[str] | None = None, flatten_chains: bool = True, include_chains: bool | None = None) list[lsst.daf.butler.registry.interfaces._collections.CollectionRecord[_Key]] ¶
Iterate over collection records that match a wildcard.
- Parameters:
- wildcard
CollectionWildcard
Names and/or patterns for collections.
- collection_types
collections.abc.Set
[CollectionType
], optional If provided, only yield collections of these types.
- done
set
[str
], optional A
set
of collection names that will not be returned (presumably because they have already been returned in some higher-level logic) that will also be updated with the names of the collections returned.- flatten_chains
bool
, optional If
True
(default) recursively yield the child collections ofCHAINED
collections.- include_chains
bool
, optional If
True
, return records forCHAINED
collections themselves. The default is the opposite offlatten_chains
: either return records for CHAINED collections or their children, but not both.
- wildcard
- Returns:
- records
list
[CollectionRecord
] Matching collection records.
- records
- abstract setDocumentation(key: _Key, doc: str | None) None ¶
Set the documentation string for a collection.
- Parameters:
- key_Key
Internal primary key value for the collection.
- doc
str
, optional Docstring for the collection with the given key.
- abstract update_chain(record: ChainedCollectionRecord[_Key], children: Iterable[str], flatten: bool = False) ChainedCollectionRecord[_Key] ¶
Update chained collection composition.
- Parameters:
- record
ChainedCollectionRecord
Chained collection record.
- children
Iterable
[str
] Ordered names of children collections.
- flatten
bool
, optional If
True
, recursively flatten out any nestedCHAINED
collections inchildren
first.
- record