Coverage for python/lsst/daf/butler/registry/dimensions/static.py : 87%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
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
23from typing import Optional
25from ...core.dimensions import DimensionElement, DimensionUniverse
26from ...core.utils import NamedKeyDict
27from ..interfaces import Database, StaticTablesContext, DimensionRecordStorageManager, DimensionRecordStorage
30class StaticDimensionRecordStorageManager(DimensionRecordStorageManager):
31 """An implementation of `DimensionRecordStorageManager` for single-layer
32 `Registry` and the base layers of multi-layer `Registry`.
34 This manager creates `DimensionRecordStorage` instances for all elements
35 in the `DimensionUniverse` in its own `initialize` method, as part of
36 static table creation, so it never needs to manage any dynamic registry
37 tables.
39 Parameters
40 ----------
41 db : `Database`
42 Interface to the underlying database engine and namespace.
43 records : `NamedKeyDict`
44 Mapping from `DimensionElement` to `DimensionRecordStorage` for that
45 element.
46 universe : `DimensionUniverse`
47 All known dimensions.
48 """
49 def __init__(self, db: Database, records: NamedKeyDict[DimensionElement, DimensionRecordStorage], *,
50 universe: DimensionUniverse):
51 super().__init__(universe=universe)
52 self._db = db
53 self._records = records
55 @classmethod
56 def initialize(cls, db: Database, context: StaticTablesContext, *,
57 universe: DimensionUniverse) -> DimensionRecordStorageManager:
58 # Docstring inherited from DimensionRecordStorageManager.
59 records = NamedKeyDict({})
60 for element in universe.elements:
61 ImplementationClass = DimensionRecordStorage.getDefaultImplementation(element)
62 records[element] = ImplementationClass.initialize(db, element, context=context)
63 return cls(db=db, records=records, universe=universe)
65 def refresh(self):
66 # Docstring inherited from DimensionRecordStorageManager.
67 pass
69 def get(self, element: DimensionElement) -> Optional[DimensionRecordStorage]:
70 # Docstring inherited from DimensionRecordStorageManager.
71 return self._records.get(element)
73 def register(self, element: DimensionElement) -> DimensionRecordStorage:
74 # Docstring inherited from DimensionRecordStorageManager.
75 result = self._records.get(element)
76 assert result, "All records instances should be created in initialize()."
77 return result
79 def clearCaches(self):
80 # Docstring inherited from DimensionRecordStorageManager.
81 for storage in self._records.values():
82 storage.clearCaches()