From b38dbd7d443567fdb5e53655f761da3290d0a164 Mon Sep 17 00:00:00 2001 From: Chris Burr Date: Tue, 1 Jul 2025 10:23:37 +0200 Subject: [PATCH] Drop the use of OrderedDict --- Hlt/Moore/python/Moore/config_tools.py | 4 +-- .../optimization/controlFlowOptimization.py | 10 ++---- Hlt/Moore/python/Moore/optimization/tools.py | 3 +- .../python/RecoConf/data_from_file.py | 36 +++++++++---------- 4 files changed, 22 insertions(+), 31 deletions(-) diff --git a/Hlt/Moore/python/Moore/config_tools.py b/Hlt/Moore/python/Moore/config_tools.py index b46116ebd25..933fc1bb549 100644 --- a/Hlt/Moore/python/Moore/config_tools.py +++ b/Hlt/Moore/python/Moore/config_tools.py @@ -166,8 +166,8 @@ def _walk_and_rename(map_the_name: dict, configuration, nodes: list) -> None: """Propagate new names from map_the_name into dataflow configuration items.""" for key, value in list(configuration.items()): - # Unpack OrderedDict and propagate into the items - for lowerkey, lowervalue in list(value.items()): + # Unpack dict and propagate into the items + for lowerkey, lowervalue in value.items(): # Unview the instance if not iterable, otherwise share the reference if isinstance(lowervalue, ItemsView): lowervalue_unview = copy(lowervalue) diff --git a/Hlt/Moore/python/Moore/optimization/controlFlowOptimization.py b/Hlt/Moore/python/Moore/optimization/controlFlowOptimization.py index 289f995bfb9..b036e789df5 100644 --- a/Hlt/Moore/python/Moore/optimization/controlFlowOptimization.py +++ b/Hlt/Moore/python/Moore/optimization/controlFlowOptimization.py @@ -14,7 +14,6 @@ import logging log = logging.getLogger(__name__) import copy -from collections import OrderedDict from itertools import chain from PyConf.control_flow import CompositeNode @@ -56,7 +55,7 @@ def loopLineAlgIterations(oldAlgs): loopLine = False if not nextList: loopLine = False - currentList = list(OrderedDict.fromkeys(nextList)) + currentList = list(dict.fromkeys(nextList)) iteration += 1 return lineAlgorithmIterations @@ -219,10 +218,7 @@ def loopPastMerger(inputAlgs, loopVar): # Flattened and filtered list of input algorithms # chain.from_iterable flattens the list - flatFilteredInputAlgs = list( - OrderedDict.fromkeys((chain.from_iterable(loopThroughList))) - ) - for alg in flatFilteredInputAlgs: + for alg in dict.fromkeys(chain.from_iterable(loopThroughList)): # If algorithm is shared between all inputs we can add it to the control flow if all([alg in algList for algList in loopThroughList]): if isinstance(alg, DataHandle): @@ -239,7 +235,7 @@ def loopPastMerger(inputAlgs, loopVar): for n in range(len(loopThroughList)): if not newLoopAlgs[n]: continue - for alg in list(OrderedDict.fromkeys(newLoopAlgs[n])): + for alg in dict.fromkeys(newLoopAlgs[n]): if isSelectionAlg(alg): if isinstance(alg, DataHandle): alg = alg.producer diff --git a/Hlt/Moore/python/Moore/optimization/tools.py b/Hlt/Moore/python/Moore/optimization/tools.py index 21d981c9366..3e9a6dc0c7f 100644 --- a/Hlt/Moore/python/Moore/optimization/tools.py +++ b/Hlt/Moore/python/Moore/optimization/tools.py @@ -12,7 +12,6 @@ import logging log = logging.getLogger(__name__) -from collections import OrderedDict from PyConf.control_flow import CompositeNode from PyConf.dataflow import DataHandle @@ -49,7 +48,7 @@ def getInputs(alg): else: l.append(values) - return list(OrderedDict.fromkeys(l)) + return list(dict.fromkeys(l)) def isSelectionAlg(line_alg): diff --git a/Hlt/RecoConf/python/RecoConf/data_from_file.py b/Hlt/RecoConf/python/RecoConf/data_from_file.py index 638e7b436b1..1ec8838b441 100644 --- a/Hlt/RecoConf/python/RecoConf/data_from_file.py +++ b/Hlt/RecoConf/python/RecoConf/data_from_file.py @@ -170,20 +170,18 @@ def _get_reco_unpackers(): ], ) - return collections.OrderedDict( - [ - ("PVs", _reco_unpacker("PVs")), - ("CaloElectrons", electrons), - ("CaloPhotons", photons), - ("CaloMergedPi0s", _reco_unpacker("CaloMergedPi0s")), - ("CaloSplitPhotons", _reco_unpacker("CaloSplitPhotons")), - ("MuonPIDs", muonPIDs), - ("RichPIDs", richPIDs), - ("Tracks", _reco_unpacker("Tracks")), - ("NeutralProtos", _reco_unpacker("NeutralProtos")), - ("ChargedProtos", charged_protos), - ] - ) + return { + "PVs": _reco_unpacker("PVs"), + "CaloElectrons": electrons, + "CaloPhotons": photons, + "CaloMergedPi0s": _reco_unpacker("CaloMergedPi0s"), + "CaloSplitPhotons": _reco_unpacker("CaloSplitPhotons"), + "MuonPIDs": muonPIDs, + "RichPIDs": richPIDs, + "Tracks": _reco_unpacker("Tracks"), + "NeutralProtos": _reco_unpacker("NeutralProtos"), + "ChargedProtos": charged_protos, + } # precomputed dict of reco unpackers, will be filled on first use @@ -226,12 +224,10 @@ def _get_mc_unpackers(): # Ordered so that dependents are unpacked first # Make sure that MC particles and MC vertices are unpacked together, # see https://gitlab.cern.ch/lhcb/LHCb/issues/57 for details. - unps = collections.OrderedDict( - [ - ("MCParticles", get_mc_particles("/Event/MC/Particles")), - ("MCVertices", get_mc_vertices("/Event/MC/Vertices")), - ] - ) + unps = { + "MCParticles": get_mc_particles("/Event/MC/Particles"), + "MCVertices": get_mc_vertices("/Event/MC/Vertices"), + } for spill in ["", "PrevPrev/", "Prev/", "NextNext/", "Next/", "LHCBackground/"]: unps.update( [ -- GitLab