From 1678e922de3578ce6c2bd51c89a44bb941fed5d4 Mon Sep 17 00:00:00 2001
From: Maarten Van Veghel <maarten.vanveghel@cern.ch>
Date: Mon, 17 Jul 2023 00:34:58 +0200
Subject: [PATCH] fix indexing issues in mapping for tracks

---
 Hlt/Hlt2Conf/options/hlt2_standard_particles.py |  1 +
 .../lbexec_yamls/spruce_all_lines_realtime.yaml |  3 ++-
 ...spruce_all_lines_realtime_test_old_json.yaml |  1 +
 .../lbexec_yamls/spruce_example_fromfile.yaml   |  1 +
 .../options/bandwidth/spruce_bandwidth_input.py |  1 +
 Hlt/Hlt2Conf/tests/options/hlt2_monitor.py      |  1 +
 .../hlt2_passthrough_persistreco_check.py       |  5 +++--
 .../tests/options/hlt2_persistreco_check.py     | 13 +++++++++++--
 Hlt/RecoConf/options/hlt2_particles_baseline.py |  6 ++++--
 .../RecoConf/calorimeter_reconstruction.py      | 14 ++++----------
 .../python/RecoConf/muon_reconstruction.py      | 17 +++++++++--------
 .../python/RecoConf/rich_reconstruction.py      | 14 ++++++++------
 Hlt/RecoConf/python/RecoConf/standalone.py      | 12 ++++++++----
 13 files changed, 54 insertions(+), 35 deletions(-)

diff --git a/Hlt/Hlt2Conf/options/hlt2_standard_particles.py b/Hlt/Hlt2Conf/options/hlt2_standard_particles.py
index 8939396cb4f..e0b0f138cde 100644
--- a/Hlt/Hlt2Conf/options/hlt2_standard_particles.py
+++ b/Hlt/Hlt2Conf/options/hlt2_standard_particles.py
@@ -24,6 +24,7 @@ from RecoConf.calorimeter_reconstruction import make_digits
 make_digits.global_bind(calo_raw_bank=False)
 
 options.set_input_and_conds_from_testfiledb('upgrade_2018_BdKstee_LDST')
+options.persistency_locations_version = '1.0'
 options.input_raw_format = 4.3
 options.evt_max = 10
 
diff --git a/Hlt/Hlt2Conf/options/sprucing/lbexec_yamls/spruce_all_lines_realtime.yaml b/Hlt/Hlt2Conf/options/sprucing/lbexec_yamls/spruce_all_lines_realtime.yaml
index 62ac30962b1..0b14423339e 100644
--- a/Hlt/Hlt2Conf/options/sprucing/lbexec_yamls/spruce_all_lines_realtime.yaml
+++ b/Hlt/Hlt2Conf/options/sprucing/lbexec_yamls/spruce_all_lines_realtime.yaml
@@ -12,9 +12,10 @@ simulation : True
 data_type : 'Upgrade'
 dddb_tag : 'dddb-20171126'
 conddb_tag : 'sim-20171127-vc-md100'
+persistency_locations_version : '1.0'
 
 histo_file : 'spruce_all_lines_realtime_histos.root'
 output_file : 'spruce_all_lines_realtimereco_newPacking_newDst.dst'
 output_type : 'ROOT'
 output_manifest_file : "spruce_all_lines_realtime_newPacking_newDst.tck.json"
-input_process: Hlt2
\ No newline at end of file
+input_process: Hlt2
diff --git a/Hlt/Hlt2Conf/options/sprucing/lbexec_yamls/spruce_all_lines_realtime_test_old_json.yaml b/Hlt/Hlt2Conf/options/sprucing/lbexec_yamls/spruce_all_lines_realtime_test_old_json.yaml
index 8b325ff464c..dbd6e8044b6 100644
--- a/Hlt/Hlt2Conf/options/sprucing/lbexec_yamls/spruce_all_lines_realtime_test_old_json.yaml
+++ b/Hlt/Hlt2Conf/options/sprucing/lbexec_yamls/spruce_all_lines_realtime_test_old_json.yaml
@@ -14,6 +14,7 @@ dddb_tag : 'dddb-20171126'
 conddb_tag : 'sim-20171127-vc-md100'
 geometry_version : 'trunk'
 conditions_version : 'master'
+persistency_locations_version : '1.0'
 
 output_file : 'spruce_all_lines_realtimereco_newPacking.dst'
 output_type : 'ROOT'
diff --git a/Hlt/Hlt2Conf/options/sprucing/lbexec_yamls/spruce_example_fromfile.yaml b/Hlt/Hlt2Conf/options/sprucing/lbexec_yamls/spruce_example_fromfile.yaml
index eb34bb5be79..ff1c49c8778 100644
--- a/Hlt/Hlt2Conf/options/sprucing/lbexec_yamls/spruce_example_fromfile.yaml
+++ b/Hlt/Hlt2Conf/options/sprucing/lbexec_yamls/spruce_example_fromfile.yaml
@@ -11,6 +11,7 @@ dddb_tag : 'dddb-20171126'
 conddb_tag : 'sim-20171127-vc-md100'
 geometry_version : 'trunk'
 conditions_version : 'master'
+persistency_locations_version : '1.0'
 
 output_file : 'spruce_fromfilereco.dst'
 output_type : 'ROOT'
diff --git a/Hlt/Hlt2Conf/tests/options/bandwidth/spruce_bandwidth_input.py b/Hlt/Hlt2Conf/tests/options/bandwidth/spruce_bandwidth_input.py
index 2ef0b0d5e4a..245f3dc2f65 100644
--- a/Hlt/Hlt2Conf/tests/options/bandwidth/spruce_bandwidth_input.py
+++ b/Hlt/Hlt2Conf/tests/options/bandwidth/spruce_bandwidth_input.py
@@ -22,6 +22,7 @@ from RecoConf.calorimeter_reconstruction import make_digits
 options.set_input_and_conds_from_testfiledb(
     'upgrade-minbias-hlt2-full-output-July2023')
 options.input_type = "MDF"
+options.persistency_locations_version = '1.0'
 options.evt_max = 100
 options.n_threads = 1
 make_digits.global_bind(calo_raw_bank=False)
diff --git a/Hlt/Hlt2Conf/tests/options/hlt2_monitor.py b/Hlt/Hlt2Conf/tests/options/hlt2_monitor.py
index 44998708bb2..b1b4d08573a 100644
--- a/Hlt/Hlt2Conf/tests/options/hlt2_monitor.py
+++ b/Hlt/Hlt2Conf/tests/options/hlt2_monitor.py
@@ -142,6 +142,7 @@ from RecoConf.global_tools import stateProvider_with_simplified_geom
 
 options.set_input_and_conds_from_testfiledb('Upgrade_MinBias_LDST')
 options.input_raw_format = 4.3
+options.persistency_locations_version = '1.0'
 options.evt_max = 1000
 options.histo_file = 'hlt2_histos.root'
 
diff --git a/Hlt/Hlt2Conf/tests/options/hlt2_passthrough_persistreco_check.py b/Hlt/Hlt2Conf/tests/options/hlt2_passthrough_persistreco_check.py
index 4bb4c36f861..35f0a00d2b0 100644
--- a/Hlt/Hlt2Conf/tests/options/hlt2_passthrough_persistreco_check.py
+++ b/Hlt/Hlt2Conf/tests/options/hlt2_passthrough_persistreco_check.py
@@ -69,11 +69,12 @@ def error(msg):
 
 unexpected_locs = [
     'SplitPhotons', 'Neutrals', 'MergedPi0s', 'Electrons', 'Photons',
-    'Rec/Summary'
+    'ProtoP/Downstream', 'ProtoP/Upstream', 'Track/BestDownstream',
+    'Track/BestUpstream', 'Rec/Summary'
 ]
 
 #As this is a pass through line with persistreco
-N_TURBO = 90
+N_TURBO = 60
 
 for ii in range(2):
 
diff --git a/Hlt/Hlt2Conf/tests/options/hlt2_persistreco_check.py b/Hlt/Hlt2Conf/tests/options/hlt2_persistreco_check.py
index 1e2719b724e..93f6aea71ac 100644
--- a/Hlt/Hlt2Conf/tests/options/hlt2_persistreco_check.py
+++ b/Hlt/Hlt2Conf/tests/options/hlt2_persistreco_check.py
@@ -103,8 +103,17 @@ TES = appMgr.evtsvc()
 appMgr.run(1)
 ## Locations we expect to be 0
 unexpected_locs = [
-    'SplitPhotons', 'Neutrals', 'MergedPi0s', 'Electrons', 'Photons',
-    'Rec/Summary', 'MuonPID'
+    'SplitPhotons',
+    'Neutrals',
+    'MergedPi0s',
+    'Electrons',
+    'Photons',
+    'Rec/Summary',
+    'MuonPID',
+    'ProtoP/Downstream',
+    'ProtoP/Upstream',
+    'Track/BestDownstream',
+    'Track/BestUpstream',
 ]
 ##Here we expect the reconstruction of whole event to be persisted
 print('Checking persistreco==True event...')
diff --git a/Hlt/RecoConf/options/hlt2_particles_baseline.py b/Hlt/RecoConf/options/hlt2_particles_baseline.py
index 79f02aa9a75..be3cff4a0c7 100644
--- a/Hlt/RecoConf/options/hlt2_particles_baseline.py
+++ b/Hlt/RecoConf/options/hlt2_particles_baseline.py
@@ -86,12 +86,14 @@ def standalone_hlt2_particles(print_protos=False):
     ksll = make_KsLL(long_detached_pions, pvs)
     jpsi = make_JPsi(long_muons)
 
-    charged_protos = make_charged_protoparticles()
+    long_protos = make_charged_protoparticles(track_type='Long')
+    down_protos = make_charged_protoparticles(track_type='Downstream')
     neutral_protos = make_neutral_protoparticles()
     if (print_protos):
         data += [
+            PrintProtoParticles(name="PrintLongProtos", Input=long_protos),
             PrintProtoParticles(
-                name="PrintChargedProtos", Input=charged_protos)
+                name="PrintDownstreamProtos", Input=down_protos),
         ]
         data += [
             PrintProtoParticles(
diff --git a/Hlt/RecoConf/python/RecoConf/calorimeter_reconstruction.py b/Hlt/RecoConf/python/RecoConf/calorimeter_reconstruction.py
index 906aacdf849..047e120d924 100644
--- a/Hlt/RecoConf/python/RecoConf/calorimeter_reconstruction.py
+++ b/Hlt/RecoConf/python/RecoConf/calorimeter_reconstruction.py
@@ -379,21 +379,15 @@ def make_convert_calo_chargedpids(
     pids = {"chargedpids": {}, "breminfos": {}}
     if not trackrels: return pids
     if not len(trackrels): return pids
+    ChargedConverter = ChargedPIDsConverter_v1Shared if shared_container else ChargedPIDsConverter_v1
     for tt in calopids_v3["chargedpids"]:
-        pids["chargedpids"][tt] = ChargedPIDsConverter_v1(
-            name=base.format("ChargedCaloPIDs", tt),
-            ChargedPIDs=calopids_v3["chargedpids"][tt],
-            Relations=trackrels[tt]
-        ).Output if not shared_container else ChargedPIDsConverter_v1Shared(
+        pids["chargedpids"][tt] = ChargedConverter(
             name=base.format("ChargedCaloPIDs", tt),
             ChargedPIDs=calopids_v3["chargedpids"][tt],
             Relations=trackrels[tt]).Output
+    BremConverter = BremInfosConverter_v1Shared if shared_container else BremInfosConverter_v1
     for tt in calopids_v3["breminfos"]:
-        pids["breminfos"][tt] = BremInfosConverter_v1(
-            name=base.format("BremInfos", tt),
-            ChargedPIDs=calopids_v3["breminfos"][tt],
-            Relations=trackrels[tt]
-        ).Output if not shared_container else BremInfosConverter_v1Shared(
+        pids["breminfos"][tt] = BremConverter(
             name=base.format("BremInfos", tt),
             ChargedPIDs=calopids_v3["breminfos"][tt],
             Relations=trackrels[tt]).Output
diff --git a/Hlt/RecoConf/python/RecoConf/muon_reconstruction.py b/Hlt/RecoConf/python/RecoConf/muon_reconstruction.py
index 30b76440826..315d2efbb26 100644
--- a/Hlt/RecoConf/python/RecoConf/muon_reconstruction.py
+++ b/Hlt/RecoConf/python/RecoConf/muon_reconstruction.py
@@ -12,9 +12,9 @@ from PyConf import configurable
 
 from PyConf.Algorithms import (
     LHCb__Converters__Track__SOA__fromV1Track as TrackSOAFromV1,
-    fromV2MuonPIDV1MuonPID, MuonPIDV2ToMuonTracks,
-    MuonPIDContainersSharedMerger as MergeMuonPIDsV1Shared,
-    MuonPIDsEmptyProducer, TracksEmptyProducer)
+    fromV2MuonPIDV1MuonPID, fromV2MuonPIDV1MuonPIDShared,
+    MuonPIDV2ToMuonTracks, MuonPIDContainersSharedMerger as
+    MergeMuonPIDsV1Shared, MuonPIDsEmptyProducer, TracksEmptyProducer)
 
 from .hlt2_muonid import make_muon_ids
 from RecoConf.core_algorithms import make_unique_id_generator
@@ -47,18 +47,19 @@ def make_all_muon_pids(tracks, track_types=['Long', 'Downstream']):
 
 def make_conv_muon_pids(muonPidsConfs,
                         best_track_rels,
-                        track_types=['Long', 'Downstream']):
+                        track_types=['Long', 'Downstream'],
+                        shared_container=False):
     muon_pids_v1 = dict()
     muon_tracks = dict()
-    for track_type in ['Long', 'Downstream']:
-        if track_type in track_types:
+    MuonPIDConverter = fromV2MuonPIDV1MuonPIDShared if shared_container else fromV2MuonPIDV1MuonPID
+    for track_type in track_types:
+        if track_type in muonPidsConfs.keys():
             # Add muon hits of MuonPID to "muontracks"
             muon_tracks[track_type] = MuonPIDV2ToMuonTracks(
                 name="MuonPIDV2ToMuonTracks_" + track_type + "_{hash}",
                 InputMuonPIDs=muonPidsConfs[track_type]).OutputMuonTracks
-
             # Convert to Keyed Container for ProtoParticle
-            muon_pids_v1[track_type] = fromV2MuonPIDV1MuonPID(
+            muon_pids_v1[track_type] = MuonPIDConverter(
                 name="fromV2MuonPIDV1MuonPID" + track_type + "_{hash}",
                 InputMuonPIDs=muonPidsConfs[track_type],
                 InputMuonTracks=muon_tracks[track_type],
diff --git a/Hlt/RecoConf/python/RecoConf/rich_reconstruction.py b/Hlt/RecoConf/python/RecoConf/rich_reconstruction.py
index cb76f9a94fe..692d3ac8214 100644
--- a/Hlt/RecoConf/python/RecoConf/rich_reconstruction.py
+++ b/Hlt/RecoConf/python/RecoConf/rich_reconstruction.py
@@ -742,12 +742,12 @@ def make_all_rich_pids(best_tracks,
     # First, extract seperate selections for the Long, Downstream, Upstream and Seed tracks
     # Eventually this should not be done, as the best container should go and
     # the tracks should be provided from source in seperate containers.
-    richTkFilt = TrackFilter(InTracksLocation=best_tracks["v1"])
+    richTkFilt = TrackFilter(InputTracks=best_tracks["v1"])
     track_type_locations = {
-        'Long': richTkFilt.OutLongTracksLocation,
-        'Downstream': richTkFilt.OutDownTracksLocation,
-        'Upstream': richTkFilt.OutUpTracksLocation,
-        'Seed': richTkFilt.OutSeedTracksLocation,
+        'Long': richTkFilt.LongTracks,
+        'Downstream': richTkFilt.DownstreamTracks,
+        'Upstream': richTkFilt.UpstreamTracks,
+        'Seed': richTkFilt.Ttracks,
     }
     richRecConfs = dict()
     # Create the confs for each RICH reco for the different track types (Long, Downstream, Upstream, Seed)
@@ -763,7 +763,9 @@ def make_merged_rich_pids(rich_pids,
                           track_types=['Long', 'Downstream'],
                           location=None):
     merged_pids = MergePIDs(
-        InputLocations=[v for k, v in rich_pids.items() if k in track_types],
+        InputLocations=[
+            v['RichPIDs'] for k, v in rich_pids.items() if k in track_types
+        ],
         outputs={
             'OutputLocation': location
         }).OutputLocation
diff --git a/Hlt/RecoConf/python/RecoConf/standalone.py b/Hlt/RecoConf/python/RecoConf/standalone.py
index f8efb70994e..a9562e2a4e7 100644
--- a/Hlt/RecoConf/python/RecoConf/standalone.py
+++ b/Hlt/RecoConf/python/RecoConf/standalone.py
@@ -593,7 +593,8 @@ def standalone_hlt2_light_reco(fast_reco=False,
 
     muonRecConfs = make_all_muon_pids(
         tracks=tracks_v3, track_types=list(tracks4rich.keys()))
-    muon_conv, muon_tracks = make_conv_muon_pids(muonRecConfs, trackrels)
+    muon_conv, muon_tracks = make_conv_muon_pids(
+        muonRecConfs, trackrels, shared_container=True)
     muon_pids = make_merged_muon_pids(muon_conv)
     data += [muon_pids]
 
@@ -783,7 +784,8 @@ def standalone_hlt2_light_reco_without_UT(fast_reco=False,
         tracktypes_formuon = list(tracks4rich.keys())
         muonRecConfs = make_all_muon_pids(
             tracks=tracks_v3, track_types=tracktypes_formuon)
-        muon_conv, muon_tracks = make_conv_muon_pids(muonRecConfs, trackrels)
+        muon_conv, muon_tracks = make_conv_muon_pids(
+            muonRecConfs, trackrels, shared_container=True)
         muon_pids = make_merged_muon_pids(muon_conv)
         data += [muon_pids]
 
@@ -957,7 +959,8 @@ def standalone_hlt2_light_reco_ion(fast_reco=False,
 
     muonRecConfs = make_all_muon_pids(
         tracks=tracks_v3, track_types=list(tracks4rich.keys()))
-    muon_pids = make_conv_muon_pids(muonRecConfs, trackrels)
+    muon_pids = make_conv_muon_pids(
+        muonRecConfs, trackrels, shared_container=True)
     data += [muon_pids]
 
     # proto particles
@@ -1096,7 +1099,8 @@ def standalone_hlt2_light_reco_ion_without_UT(fast_reco=False,
     tracktypes_formuon = list(tracks4rich.keys())
     muonRecConfs = make_all_muon_pids(
         tracks=tracks_v3, track_types=tracktypes_formuon)
-    muon_conv, muon_tracks = make_conv_muon_pids(muonRecConfs, trackrels)
+    muon_conv, muon_tracks = make_conv_muon_pids(
+        muonRecConfs, trackrels, shared_container=True)
     muon_pids = make_merged_muon_pids(muon_conv)
     data += [muon_pids]
 
-- 
GitLab