570def reorderRefs(inputRefs, outputSortKeyOrder, dataIdKey):
571 """Reorder inputRefs per outputSortKeyOrder.
572
573 Any inputRefs which are lists will be resorted per specified key e.g.,
574 'detector.' Only iterables will be reordered, and values can be of type
575 `lsst.pipe.base.connections.DeferredDatasetRef` or
576 `lsst.daf.butler.core.datasets.ref.DatasetRef`.
577
578 Returned lists of refs have the same length as the outputSortKeyOrder.
579 If an outputSortKey not in the inputRef, then it will be padded with None.
580 If an inputRef contains an inputSortKey that is not in the
581 outputSortKeyOrder it will be removed.
582
583 Parameters
584 ----------
585 inputRefs : `lsst.pipe.base.connections.QuantizedConnection`
586 Input references to be reordered and padded.
587 outputSortKeyOrder : `iterable`
588 Iterable of values to be compared with inputRef's dataId[dataIdKey].
589 dataIdKey : `str`
590 The data ID key in the dataRefs to compare with the outputSortKeyOrder.
591
592 Returns
593 -------
594 inputRefs : `lsst.pipe.base.connections.QuantizedConnection`
595 Quantized Connection with sorted DatasetRef values sorted if iterable.
596 """
597 for connectionName, refs in inputRefs:
598 if isinstance(refs, Iterable):
599 if hasattr(refs[0], "dataId"):
600 inputSortKeyOrder = [ref.dataId[dataIdKey] for ref in refs]
601 else:
602 inputSortKeyOrder = [handle.datasetRef.dataId[dataIdKey] for handle in refs]
603 if inputSortKeyOrder != outputSortKeyOrder:
604 setattr(inputRefs, connectionName,
605 reorderAndPadList(refs, inputSortKeyOrder, outputSortKeyOrder))
606 return inputRefs