23 """Retrieve collections of metadata or data based on a set of data references
25 Use this as a base task for creating graphs and reports for a set of data.
36 __all__ = [
"DataRefListRunner",
"GetRepositoryDataTask"]
39 """A task runner that calls run with a list of data references
41 Differs from the default TaskRunner by providing all data references at once,
42 instead of iterating over them one at a time.
46 """Return a list of targets (arguments for __call__); one entry per invocation
48 return [parsedCmd.id.refList]
51 """Run GetRepositoryDataTask.run on a single target
53 @param dataRefList: argument dict for run; contains one key: dataRefList
56 - None if doReturnResults false
57 - A pipe_base Struct containing these fields if doReturnResults true:
58 - dataRefList: the argument dict sent to runDataRef
59 - metadata: task metadata after execution of runDataRef
60 - result: result returned by task runDataRef
62 task = self.TaskClass(config=self.config, log=self.log)
63 result = task.run(dataRefList)
65 if self.doReturnResults:
66 return pipeBase.Struct(
67 dataRefList = dataRefList,
68 metadata = task.metadata,
74 """Retrieve data from a repository, e.g. for plotting or analysis purposes
76 ConfigClass = pexConfig.Config
77 RunnerClass = DataRefListRunner
78 _DefaultName =
"getTaskData"
81 pipeBase.CmdLineTask.__init__(self, *args, **kwargs)
84 def run(self, dataRefList):
85 """Get data from a repository for a collection of data references
87 @param dataRefList: a list of data references
89 raise NotImplementedError(
"subclass must specify a run method")
92 """Get a list of data IDs in a form that can be used as dictionary keys
94 @param dataRefList: a list of data references
95 @return a pipe_base Struct with fields:
96 - idKeyTuple: a tuple of dataRef data ID keys
97 - idValList: a list of data ID value tuples, each tuple contains values in the order in idKeyTuple
100 raise RuntimeError(
"No data refs")
101 idKeyTuple = tuple(sorted(dataRefList[0].dataId.keys()))
104 for dataRef
in dataRefList:
105 idValTuple = tuple(dataRef.dataId[key]
for key
in idKeyTuple)
106 idValList.append(idValTuple)
108 return pipeBase.Struct(
109 idKeyTuple = idKeyTuple,
110 idValList = idValList,
114 """Retrieve a list of data
116 @param dataRefList: a list of data references
117 @param datasetType: datasetType of data to be retrieved
118 @return a list of data, one entry per dataRef in dataRefList (in order)
120 return [dataRef.get(datasetType=datasetType)
for dataRef
in dataRefList]
123 """Retrieve a list of dictionaries of metadata
125 @param dataRefList: a list of data references
126 @param datasetType: datasetType of metadata (or any object that supports get(name))
127 @return a list of dicts of metadata:
128 - each entry in the list corresponds to a dataRef in dataRefList
129 - each dict contains name: item of metadata, for each name in nameList
132 for dataRef
in dataRefList:
133 metadata = dataRef.get(datasetType=datasetType)
134 valList.append(dict((name, metadata.get(name))
for name
in nameList))