24 from builtins
import object, super
29 """This module defines the Mapper base class.""" 33 """Mapper is a base class for all mappers. 35 Subclasses may define the following methods: 37 map_{datasetType}(self, dataId, write) 38 Map a dataset id for the given dataset type into a ButlerLocation. 39 If write=True, this mapping is for an output dataset. 41 query_{datasetType}(self, key, format, dataId) 42 Return the possible values for the format fields that would produce 43 datasets at the granularity of key in combination with the provided 46 std_{datasetType}(self, item) 47 Standardize an object of the given data set type. 49 Methods that must be overridden: 52 Return a list of the keys that can be used in data ids. 60 map(self, datasetType, dataId, write=False) 62 queryMetadata(self, datasetType, key, format, dataId) 64 canStandardize(self, datasetType) 66 standardize(self, datasetType, item, dataId) 68 validate(self, dataId) 73 '''Instantiate a Mapper from a configuration. 74 In come cases the cfg may have already been instantiated into a Mapper, this is allowed and 75 the input var is simply returned. 77 :param cfg: the cfg for this mapper. It is recommended this be created by calling 79 :return: a Mapper instance 81 if isinstance(cfg, Policy):
82 return cfg[
'cls'](cfg)
86 """Create a new Mapper, saving arguments for pickling. 88 This is in __new__ instead of __init__ to save the user 89 from having to save the arguments themselves (either explicitly, 90 or by calling the super's __init__ with all their 91 *args,**kwargs. The resulting pickling system (of __new__, 92 __getstate__ and __setstate__ is similar to how __reduce__ 93 is usually used, except that we save the user from any 94 responsibility (except when overriding __new__, but that 105 return self._arguments
113 raise NotImplementedError(
"keys() unimplemented")
116 """Get possible values for keys given a partial data id. 118 :param datasetType: see documentation about the use of datasetType 119 :param key: this is used as the 'level' parameter 121 :param dataId: see documentation about the use of dataId 124 func = getattr(self,
'query_' + datasetType)
126 val = func(format, self.
validate(dataId))
130 """Return a list of the mappable dataset types.""" 133 for attr
in dir(self):
134 if attr.startswith(
"map_"):
135 list.append(attr[4:])
138 def map(self, datasetType, dataId, write=False):
139 """Map a data id using the mapping method for its dataset type. 144 The datasetType to map 145 dataId : DataId instance 146 The dataId to use when mapping 147 write : bool, optional 148 Indicates if the map is being performed for a read operation 149 (False) or a write operation (True) 153 ButlerLocation or a list of ButlerLocation 154 The location(s) found for the map operation. If write is True, a 155 list is returned. If write is False a single ButlerLocation is 161 If no locaiton was found for this map operation, the derived mapper 162 class may raise a lsst.daf.persistence.NoResults exception. Butler 163 catches this and will look in the next Repository if there is one. 165 func = getattr(self,
'map_' + datasetType)
166 return func(self.
validate(dataId), write)
169 """Return true if this mapper can standardize an object of the given 172 return hasattr(self,
'std_' + datasetType)
175 """Standardize an object using the standardization method for its data 176 set type, if it exists.""" 178 if hasattr(self,
'std_' + datasetType):
179 func = getattr(self,
'std_' + datasetType)
180 return func(item, self.
validate(dataId))
184 """Validate a dataId's contents. 186 If the dataId is valid, return it. If an invalid component can be 187 transformed into a valid one, copy the dataId, fix the component, and 188 return the copy. Otherwise, raise an exception.""" 193 """Rename any existing object with the given type and dataId. 195 Not implemented in the base mapper. 197 raise NotImplementedError(
"Base-class Mapper does not implement backups")
200 """Get the registry""" def __setstate__(self, state)
def backup(self, datasetType, dataId)
def canStandardize(self, datasetType)
def validate(self, dataId)
def map(self, datasetType, dataId, write=False)
def queryMetadata(self, datasetType, format, dataId)
def getDatasetTypes(self)
def __init__(self, kwargs)
def standardize(self, datasetType, item, dataId)
def __new__(cls, args, kwargs)