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