27 """This module defines the ButlerSubset class and the ButlerDataRefs contained 28 within it as well as an iterator over the subset.""" 29 from builtins
import next
30 from builtins
import range
31 from builtins
import object
38 """ButlerSubset is a container for ButlerDataRefs. It represents a 39 collection of data ids that can be used to obtain datasets of the type 40 used when creating the collection or a compatible dataset type. It can be 41 thought of as the result of a query for datasets matching a partial data 44 The ButlerDataRefs are generated at a specified level of the data id 45 hierarchy. If that is not the level at which datasets are specified, the 46 ButlerDataRef.subItems() method may be used to dive further into the 49 ButlerSubsets should generally be created using Butler.subset(). 51 This mechanism replaces the creation of butlers using partial dataIds. 55 __init__(self, butler, datasetType, level, dataId) 64 """This is a Generation 2 ButlerSubset. 67 def __init__(self, butler, datasetType, level, dataId):
69 Create a ButlerSubset by querying a butler for data ids matching a 70 given partial data id for a given dataset type at a given hierarchy 73 @param butler (Butler) butler that is being queried. 74 @param datasetType (str) the type of dataset to query. 75 @param level (str) the hierarchy level to descend to. if empty string will look up the default 77 @param dataId (dict) the (partial or complete) data id. 85 keys = self.
butler.getKeys(datasetType, level, tag=dataId.tag)
88 fmt =
list(keys.keys())
101 for idTuple
in idTuples:
102 tempId = dict(self.
dataId)
104 tempId[fmt[0]] = idTuple
106 for i
in range(len(fmt)):
107 tempId[fmt[i]] = idTuple[i]
111 return "ButlerSubset(butler=%s, datasetType=%s, dataId=%s, cache=%s, level=%s)" % (
116 Number of ButlerDataRefs in the ButlerSubset. 121 return len(self.
cache)
125 Iterator over the ButlerDataRefs in the ButlerSubset. 127 @returns (ButlerIterator) 135 An iterator over the ButlerDataRefs in a ButlerSubset. 151 A ButlerDataRef is a reference to a potential dataset or group of datasets 152 that is portable between compatible dataset types. As such, it can be 153 used to create or retrieve datasets. 155 ButlerDataRefs are (conceptually) created as elements of a ButlerSubset by 156 Butler.subset(). They are initially specific to the dataset type passed 157 to that call, but they may be used with any other compatible dataset type. 158 Dataset type compatibility must be determined externally (or by trial and 161 ButlerDataRefs may be created at any level of a data identifier hierarchy. 162 If the level is not one at which datasets exist, a ButlerSubset 163 with lower-level ButlerDataRefs can be created using 164 ButlerDataRef.subItems(). 168 get(self, datasetType=None, **rest) 170 put(self, obj, datasetType=None, **rest) 172 subItems(self, level=None) 174 datasetExists(self, datasetType=None, **rest) 180 """This is a Generation 2 DataRef. 185 For internal use only. ButlerDataRefs should only be created by 186 ButlerSubset and ButlerSubsetIterator. 195 def get(self, datasetType=None, **rest):
197 Retrieve a dataset of the given type (or the type used when creating 198 the ButlerSubset, if None) as specified by the ButlerDataRef. 200 @param datasetType (str) dataset type to retrieve. 201 @param **rest keyword arguments with data identifiers 202 @returns object corresponding to the given dataset type. 204 if datasetType
is None:
208 def put(self, obj, datasetType=None, doBackup=False, **rest):
210 Persist a dataset of the given type (or the type used when creating 211 the ButlerSubset, if None) as specified by the ButlerDataRef. 213 @param obj object to persist. 214 @param datasetType (str) dataset type to persist. 215 @param doBackup if True, rename existing instead of overwriting 216 @param **rest keyword arguments with data identifiers 218 WARNING: Setting doBackup=True is not safe for parallel processing, as it 219 may be subject to race conditions. 222 if datasetType
is None:
224 self.
butlerSubset.butler.put(obj, datasetType, self.
dataId, doBackup=doBackup, **rest)
226 def getUri(self, datasetType=None, write=False, **rest):
227 """Return the URL for a dataset 229 .. warning:: This is intended only for debugging. The URI should 230 never be used for anything other than printing. 232 .. note:: In the event there are multiple URIs, we return only 235 .. note:: getUri() does not currently support composite datasets. 239 datasetType : `str`, optional 240 The dataset type of interest. 241 write : `bool`, optional 242 Return the URI for writing? 243 rest : `dict`, optional 244 Keyword arguments for the data id. 252 if datasetType
is None:
258 Return a list of the lower levels of the hierarchy than this 261 @returns (iterable) list of strings with level keys.""" 276 Generate a ButlerSubset at a lower level of the hierarchy than this 277 ButlerDataRef, using it as a partial data id. If level is None, a 278 default lower level for the original ButlerSubset level and dataset 281 As currently implemented, the default sublevels for all the 282 repositories used by this Butler instance must match for the Butler to 283 be able to select a default sublevel to get the subset. 285 @param level (str) the hierarchy level to descend to. 286 @returns (ButlerSubset) resulting from the lower-level query or () if 287 there is no lower level. 293 levelSet.add(repoData.repo._mapper.getDefaultSubLevel(
295 if len(levelSet) > 1:
297 "Support for multiple levels not implemented.")
298 level = levelSet.pop()
306 Determine if a dataset exists of the given type (or the type used when 307 creating the ButlerSubset, if None) as specified by the ButlerDataRef. 309 @param datasetType (str) dataset type to check. 310 @param write (bool) if True, search only in output repositories 311 @param **rest keywords arguments with data identifiers 314 if datasetType
is None:
317 datasetType, self.
dataId, write=write, **rest)
321 Return the butler associated with this data reference.
def __init__(self, butlerSubset, dataId)
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
daf::base::PropertySet * set
def __init__(self, butlerSubset)
def __init__(self, butler, datasetType, level, dataId)
def put(self, obj, datasetType=None, doBackup=False, rest)
def datasetExists(self, datasetType=None, write=False, rest)
def subItems(self, level=None)
def getUri(self, datasetType=None, write=False, rest)
def get(self, datasetType=None, rest)
daf::base::PropertyList * list