Coverage for python/lsst/daf/butler/registry/interfaces/_obscore.py: 62%
27 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-10-26 02:01 -0700
« prev ^ index » next coverage.py v6.5.0, created at 2022-10-26 02:01 -0700
1# This file is part of daf_butler.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
21from __future__ import annotations
23"""Interfaces for classes that manage obscore table(s) in a `Registry`.
24"""
26__all__ = ["ObsCoreTableManager"]
28from abc import abstractmethod
29from collections.abc import Mapping
30from typing import TYPE_CHECKING, Iterable, Type
32from ._versioning import VersionedExtension
34if TYPE_CHECKING: 34 ↛ 35line 34 didn't jump to line 35, because the condition on line 34 was never true
35 from ...core import DatasetRef, DimensionUniverse
36 from ._collections import CollectionRecord
37 from ._database import Database, StaticTablesContext
38 from ._datasets import DatasetRecordStorageManager
39 from ._dimensions import DimensionRecordStorageManager
42class ObsCoreTableManager(VersionedExtension):
43 """An interface for populating ObsCore tables(s)."""
45 @classmethod
46 @abstractmethod
47 def initialize(
48 cls,
49 db: Database,
50 context: StaticTablesContext,
51 *,
52 universe: DimensionUniverse,
53 config: Mapping,
54 datasets: Type[DatasetRecordStorageManager],
55 dimensions: DimensionRecordStorageManager,
56 ) -> ObsCoreTableManager:
57 """Construct an instance of the manager.
59 Parameters
60 ----------
61 db : `Database`
62 Interface to the underlying database engine and namespace.
63 context : `StaticTablesContext`
64 Context object obtained from `Database.declareStaticTables`; used
65 to declare any tables that should always be present in a layer
66 implemented with this manager.
67 universe : `DimensionUniverse`
68 All dimensions known to the registry.
69 config : `dict` [ `str`, `Any` ]
70 Configuration of the obscore manager.
71 datasets : `type`
72 Type of dataset manager.
73 dimensions: `DimensionRecordStorageManager`
74 Manager for Registry dimensions.
76 Returns
77 -------
78 manager : `ObsCoreTableManager`
79 An instance of a concrete `ObsCoreTableManager` subclass.
80 """
81 raise NotImplementedError()
83 @abstractmethod
84 def config_json(self) -> str:
85 """Dump configuration in JSON format.
87 Returns
88 -------
89 json : `str`
90 Configuration serialized in JSON format.
91 """
92 raise NotImplementedError()
94 def add_datasets(self, refs: Iterable[DatasetRef]) -> None:
95 """Possibly add datasets to the obscore table.
97 This method should be called when new datasets are added to a RUN
98 collection.
100 Parameters
101 ----------
102 refs : `iterable` [ `DatasetRef` ]
103 Dataset refs to add. Dataset refs have to be completely expanded.
104 If a record with the same dataset ID is already in obscore table,
105 the dataset is ignored.
107 Notes
108 -----
109 Dataset data types and collection names are checked against configured
110 list of collections and dataset types, non-matching datasets are
111 ignored and not added to the obscore table.
113 When configuration parameter ``collection_type`` is not "RUN", this
114 method should return immediately.
116 Note that there is no matching method to remove datasets from obscore
117 table, we assume that removal happens via foreign key constraint to
118 dataset table with "ON DELETE CASCADE" option.
119 """
120 raise NotImplementedError()
122 def associate(self, refs: Iterable[DatasetRef], collection: CollectionRecord) -> None:
123 """Possibly add datasets to the obscore table.
125 This method should be called when existing datasets are associated with
126 a TAGGED collection.
128 Parameters
129 ----------
130 refs : `iterable` [ `DatasetRef` ]
131 Dataset refs to add. Dataset refs have to be completely expanded.
132 If a record with the same dataset ID is already in obscore table,
133 the dataset is ignored.
134 collection : `CollectionRecord`
135 Collection record for a TAGGED collection.
137 Notes
138 -----
139 Dataset data types and collection names are checked against configured
140 list of collections and dataset types, non-matching datasets are
141 ignored and not added to the obscore table.
143 When configuration parameter ``collection_type`` is not "TAGGED", this
144 method should return immediately.
145 """
146 raise NotImplementedError()
148 def disassociate(self, refs: Iterable[DatasetRef], collection: CollectionRecord) -> None:
149 """Possibly remove datasets from the obscore table.
151 This method should be called when datasets are disassociated from a
152 TAGGED collection.
154 Parameters
155 ----------
156 refs : `iterable` [ `DatasetRef` ]
157 Dataset refs to remove. Dataset refs have to be resolved.
158 collection : `CollectionRecord`
159 Collection record for a TAGGED collection.
161 Notes
162 -----
163 Dataset data types and collection names are checked against configured
164 list of collections and dataset types, non-matching datasets are
165 ignored and not added to the obscore table.
167 When configuration parameter ``collection_type`` is not "TAGGED", this
168 method should return immediately.
169 """
170 raise NotImplementedError()