From 38ba024e8b751b814f5020958cba83a57b381ebd Mon Sep 17 00:00:00 2001
From: Sevda Esen <sevda.esen@cern.ch>
Date: Fri, 3 Mar 2023 01:25:44 +0100
Subject: [PATCH] Use raw bank size filter

---
 .../example_data/Gauss_12143001_xgen.yaml     |  2 +-
 .../Upgrade_Bd2KstarMuMu_ldst.yaml            |  2 +-
 .../example_data/Upgrade_genFSR_ldst.yaml     |  2 +-
 .../example_data/test_read_xgen.yaml          |  2 +-
 .../test_example-tupling-basic-run-mc.qmt     |  2 +-
 .../test_example-tupling-basic.qmt            |  2 +-
 .../davinci.qms/configure_dst_py-opts.qmt     |  2 +-
 .../davinci.qms/configure_dst_yaml-opts.qmt   |  2 +-
 .../tests/qmtest/davinci.qms/test_DTF.qmt     |  2 +-
 .../tests/qmtest/io.qms/test_read_mc_digi.qmt |  2 +-
 .../tests/qmtest/io.qms/test_read_mc_ldst.qmt |  2 +-
 .../tests/qmtest/io.qms/test_read_mc_mdf.qmt  |  2 +-
 .../qmtest/io.qms/test_read_mc_xdigi.qmt      |  2 +-
 .../qmtest/io.qms/test_read_moore_dst.qmt     |  2 +-
 Phys/DaVinci/python/DaVinci/LbExec.py         |  4 +++-
 Phys/DaVinci/python/DaVinci/algorithms.py     | 22 ++++++++++---------
 Phys/DaVinci/python/DaVinci/config.py         | 13 +++++------
 Phys/DaVinci/tests/config/test_algorithms.py  | 17 +++++++-------
 18 files changed, 42 insertions(+), 42 deletions(-)

diff --git a/DaVinciExamples/example_data/Gauss_12143001_xgen.yaml b/DaVinciExamples/example_data/Gauss_12143001_xgen.yaml
index 629b52d68..f96920c6a 100644
--- a/DaVinciExamples/example_data/Gauss_12143001_xgen.yaml
+++ b/DaVinciExamples/example_data/Gauss_12143001_xgen.yaml
@@ -10,4 +10,4 @@ geometry_version: trunk
 histo_file: DV_histo_xgen.root
 ntuple_file: DV_tuple_xgen.root
 input_raw_format: 0.5
-input_process: Hlt2
+input_process: Gen
diff --git a/DaVinciExamples/example_data/Upgrade_Bd2KstarMuMu_ldst.yaml b/DaVinciExamples/example_data/Upgrade_Bd2KstarMuMu_ldst.yaml
index bea19fa54..f4038399e 100644
--- a/DaVinciExamples/example_data/Upgrade_Bd2KstarMuMu_ldst.yaml
+++ b/DaVinciExamples/example_data/Upgrade_Bd2KstarMuMu_ldst.yaml
@@ -7,4 +7,4 @@ conddb_tag: sim-20171127-vc-md100
 dddb_tag: dddb-20171126
 conditions_version: master
 geometry_version: trunk
-input_process: Hlt2
+input_process: Brunel
diff --git a/DaVinciExamples/example_data/Upgrade_genFSR_ldst.yaml b/DaVinciExamples/example_data/Upgrade_genFSR_ldst.yaml
index d97993e91..c42b4cb1c 100644
--- a/DaVinciExamples/example_data/Upgrade_genFSR_ldst.yaml
+++ b/DaVinciExamples/example_data/Upgrade_genFSR_ldst.yaml
@@ -4,4 +4,4 @@ input_type: ROOT
 simulation: true
 conddb_tag: sim-20171127-vc-md100
 dddb_tag: dddb-20171126
-input_process: Turbo
+input_process: Brunel
diff --git a/DaVinciExamples/example_data/test_read_xgen.yaml b/DaVinciExamples/example_data/test_read_xgen.yaml
index e11bf7061..5394492d1 100644
--- a/DaVinciExamples/example_data/test_read_xgen.yaml
+++ b/DaVinciExamples/example_data/test_read_xgen.yaml
@@ -5,4 +5,4 @@ input_type: ROOT
 simulation: true
 conddb_tag: sim-20171127-vc-md100
 dddb_tag: dddb-20171126
-input_process: Turbo
+input_process: Gen
diff --git a/DaVinciExamples/tests/qmtest/tupling.qms/test_example-tupling-basic-run-mc.qmt b/DaVinciExamples/tests/qmtest/tupling.qms/test_example-tupling-basic-run-mc.qmt
index 22b15a94f..cfc4f6507 100755
--- a/DaVinciExamples/tests/qmtest/tupling.qms/test_example-tupling-basic-run-mc.qmt
+++ b/DaVinciExamples/tests/qmtest/tupling.qms/test_example-tupling-basic-run-mc.qmt
@@ -23,7 +23,7 @@
     histo_file: DV-example-tupling-basic-his-run-mc.root
     input_raw_format: 4.3
     ntuple_file: DV-example-tupling-basic-ntp-run-mc.root
-    input_process: Hlt2
+    input_process: Brunel
   </text></argument>
   <argument name="reference"><text>../refs/test_davinci_tupling-basic-run-mc.ref</text></argument>
   <argument name="error_reference"><text>../refs/empty.ref</text></argument>
diff --git a/DaVinciExamples/tests/qmtest/tupling.qms/test_example-tupling-basic.qmt b/DaVinciExamples/tests/qmtest/tupling.qms/test_example-tupling-basic.qmt
index 29a0a30fe..798ce1822 100644
--- a/DaVinciExamples/tests/qmtest/tupling.qms/test_example-tupling-basic.qmt
+++ b/DaVinciExamples/tests/qmtest/tupling.qms/test_example-tupling-basic.qmt
@@ -23,7 +23,7 @@
     histo_file: DV-example-tupling-basic-his.root
     evt_max: 10
     input_raw_format: 4.3
-    input_process: Hlt2
+    input_process: Brunel
 </text></argument>
 <argument name="timeout"><integer>3600</integer></argument>
 <argument name="validator"><text>
diff --git a/DaVinciTests/tests/qmtest/davinci.qms/configure_dst_py-opts.qmt b/DaVinciTests/tests/qmtest/davinci.qms/configure_dst_py-opts.qmt
index a3eb39287..c1d471bf5 100644
--- a/DaVinciTests/tests/qmtest/davinci.qms/configure_dst_py-opts.qmt
+++ b/DaVinciTests/tests/qmtest/davinci.qms/configure_dst_py-opts.qmt
@@ -21,7 +21,7 @@
     ntuple_file: DV-Ntuple.root
     histo_file: DV-Histos.root
     lumi: False
-    input_process: Turbo
+    input_process: Brunel
   </text></argument>
   <argument name="use_temp_dir"><enumeral>true</enumeral></argument>
   <argument name="validator"><text>
diff --git a/DaVinciTests/tests/qmtest/davinci.qms/configure_dst_yaml-opts.qmt b/DaVinciTests/tests/qmtest/davinci.qms/configure_dst_yaml-opts.qmt
index 343f5061a..5d82a8adc 100644
--- a/DaVinciTests/tests/qmtest/davinci.qms/configure_dst_yaml-opts.qmt
+++ b/DaVinciTests/tests/qmtest/davinci.qms/configure_dst_yaml-opts.qmt
@@ -21,7 +21,7 @@
     ntuple_file: DV-Ntuple.root
     histo_file: DV-Histos.root
     lumi: False
-    input_process: Turbo
+    input_process: Brunel
     evt_max: 10
   </text></argument>
   <argument name="use_temp_dir"><enumeral>true</enumeral></argument>
diff --git a/DaVinciTests/tests/qmtest/davinci.qms/test_DTF.qmt b/DaVinciTests/tests/qmtest/davinci.qms/test_DTF.qmt
index af1c59196..a40158379 100755
--- a/DaVinciTests/tests/qmtest/davinci.qms/test_DTF.qmt
+++ b/DaVinciTests/tests/qmtest/davinci.qms/test_DTF.qmt
@@ -29,7 +29,7 @@ See https://gitlab.cern.ch/lhcb/Rec/-/issues/408
     histo_file: DV-example-tupling-DTF-his.root
     input_raw_format: 4.3
     ntuple_file: DV-example-tupling-DTF-ntp.root
-    input_process: Hlt2
+    input_process: Brunel
   </text></argument>
 <argument name="exit_code"><integer>3</integer></argument>
 <argument name="exit_value"><text>Failed</text></argument>
diff --git a/DaVinciTests/tests/qmtest/io.qms/test_read_mc_digi.qmt b/DaVinciTests/tests/qmtest/io.qms/test_read_mc_digi.qmt
index 0d366cc93..4388ed66f 100644
--- a/DaVinciTests/tests/qmtest/io.qms/test_read_mc_digi.qmt
+++ b/DaVinciTests/tests/qmtest/io.qms/test_read_mc_digi.qmt
@@ -19,7 +19,7 @@
   <argument name="test_file_db_options_yaml"><text>upgrade-magdown-sim09c-up02-34112100-digi</text></argument>
   <argument name="extra_options_yaml"><text>
     evt_max: 200
-    input_process: Turbo
+    input_process: Boole
   </text></argument>
   <argument name="reference"><text>../refs/test_davinci_read_mc_digi.ref</text></argument>
   <argument name="error_reference"><text>../refs/empty.ref</text></argument>
diff --git a/DaVinciTests/tests/qmtest/io.qms/test_read_mc_ldst.qmt b/DaVinciTests/tests/qmtest/io.qms/test_read_mc_ldst.qmt
index 1156c08f7..d8a2e494c 100644
--- a/DaVinciTests/tests/qmtest/io.qms/test_read_mc_ldst.qmt
+++ b/DaVinciTests/tests/qmtest/io.qms/test_read_mc_ldst.qmt
@@ -19,7 +19,7 @@
   <argument name="test_file_db_options_yaml"><text>upgrade-magdown-sim09c-up02-reco-up01-minbias-ldst</text></argument>
   <argument name="extra_options_yaml"><text>
     evt_max: 200
-    input_process: Turbo
+    input_process: Brunel
   </text></argument>
   <argument name="reference"><text>../refs/test_davinci_read_mc_ldst.ref</text></argument>
   <argument name="error_reference"><text>../refs/empty.ref</text></argument>
diff --git a/DaVinciTests/tests/qmtest/io.qms/test_read_mc_mdf.qmt b/DaVinciTests/tests/qmtest/io.qms/test_read_mc_mdf.qmt
index e3cb78586..9ff4e55a0 100644
--- a/DaVinciTests/tests/qmtest/io.qms/test_read_mc_mdf.qmt
+++ b/DaVinciTests/tests/qmtest/io.qms/test_read_mc_mdf.qmt
@@ -20,7 +20,7 @@
   <argument name="extra_options_yaml"><text>
     input_type: RAW
     evt_max: 200
-    input_process: Turbo
+    input_process: Hlt1
   </text></argument>
   <argument name="reference"><text>../refs/test_davinci_read_mc_mdf.ref</text></argument>
   <argument name="error_reference"><text>../refs/empty.ref</text></argument>
diff --git a/DaVinciTests/tests/qmtest/io.qms/test_read_mc_xdigi.qmt b/DaVinciTests/tests/qmtest/io.qms/test_read_mc_xdigi.qmt
index 57e0c400a..e9e51114f 100644
--- a/DaVinciTests/tests/qmtest/io.qms/test_read_mc_xdigi.qmt
+++ b/DaVinciTests/tests/qmtest/io.qms/test_read_mc_xdigi.qmt
@@ -19,7 +19,7 @@
   <argument name="test_file_db_options_yaml"><text>upgrade_DC19_01_Bs2JPsiPhi_MD</text></argument>
   <argument name="extra_options_yaml"><text>
     evt_max: 200
-    input_process: Turbo
+    input_process: Boole
   </text></argument>
   <argument name="reference"><text>../refs/test_davinci_read_mc_xdigi.ref</text></argument>
   <argument name="error_reference"><text>../refs/empty.ref</text></argument>
diff --git a/DaVinciTests/tests/qmtest/io.qms/test_read_moore_dst.qmt b/DaVinciTests/tests/qmtest/io.qms/test_read_moore_dst.qmt
index 27078945d..3cb9c12cd 100755
--- a/DaVinciTests/tests/qmtest/io.qms/test_read_moore_dst.qmt
+++ b/DaVinciTests/tests/qmtest/io.qms/test_read_moore_dst.qmt
@@ -23,7 +23,7 @@
     evt_max: -1
     print_freq: 1
     msg_svc_format: "% F%60W%S%7W%R%T %0W%M"
-    input_process: Turbo
+    input_process: Brunel
   </text></argument>
 <argument name="validator"><text>
 findReferenceBlock("""StdLooseD02KK                                                  INFO Number of counters : 6
diff --git a/Phys/DaVinci/python/DaVinci/LbExec.py b/Phys/DaVinci/python/DaVinci/LbExec.py
index 473273db8..3ae34e4ab 100644
--- a/Phys/DaVinci/python/DaVinci/LbExec.py
+++ b/Phys/DaVinci/python/DaVinci/LbExec.py
@@ -61,7 +61,9 @@ class Options(DefaultOptions):
         dict: Modified attributes of the Options object.
       """
         input_process = values.get("input_process")
-        if input_process == InputProcessTypes.Hlt2:
+        if input_process not in {
+                InputProcessTypes.Spruce, InputProcessTypes.Turbo
+        }:
             values['stream'] = ''
 
         return values
diff --git a/Phys/DaVinci/python/DaVinci/algorithms.py b/Phys/DaVinci/python/DaVinci/algorithms.py
index 9c08f800d..6380b8954 100644
--- a/Phys/DaVinci/python/DaVinci/algorithms.py
+++ b/Phys/DaVinci/python/DaVinci/algorithms.py
@@ -11,11 +11,9 @@
 import re
 import logging
 
-from PyConf.Algorithms import (
-    LoKi__HDRFilter as HDRFilter,
-    LoKi__VoidFilter as VoidFilter,
-)
-from PyConf.reading import get_particles, get_hlt_reports
+from PyConf.Algorithms import (LoKi__HDRFilter as HDRFilter, LoKi__VoidFilter
+                               as VoidFilter)
+from PyConf.reading import get_particles, get_hlt_reports, dstdata_filter
 
 log = logging.getLogger(__name__)
 
@@ -86,23 +84,27 @@ def add_filter(name, code):
     return algFilter
 
 
-def apply_filters_and_unpacking(options, algs_dict):
+def apply_filters(options, algs_dict):
     """
-    Adding filter and unpacking algorithms.
+    Adding filter algorithms.
 
     Args:
         options (DaVinci.Options): lbexec provided options object
         algs_dict (dict): dict of the user algorithms.
-        (TO BE REMOVED WHEN THE UNPACKING WILL BECOME FUNCTIONAL)
-        (UNPACKING IS FUNCTIONAL, time to remove maybe?)
 
     Returns:
-        Dict where at each node filters and unpacking algorithms are prepended to the initial list of user algorithms.
+        Dict where at each node filters  are prepended to the initial list of user algorithms.
     """
 
     alg_filterd_dict = {}
     for name, algs in algs_dict.items():
         algs_list = []
+
+        # This filter will skip events with empty DstData but a positive line decision.
+        # It will only be applied to the input_process where DstData bank is produced (Hlt2, Turbo, Spruce).
+        if options.input_process in {"Turbo", "Spruce", "Hlt2"}:
+            algs_list += [dstdata_filter(options.stream)]
+
         if options.evt_pre_filters:
             evt_pre_filters = []
             for title, code in options.evt_pre_filters.items():
diff --git a/Phys/DaVinci/python/DaVinci/config.py b/Phys/DaVinci/python/DaVinci/config.py
index 97854509f..8684ebfc2 100644
--- a/Phys/DaVinci/python/DaVinci/config.py
+++ b/Phys/DaVinci/python/DaVinci/config.py
@@ -1,5 +1,5 @@
 ###############################################################################
-# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration      #
+# (c) Copyright 2021-2023 CERN for the benefit of the LHCb Collaboration      #
 #                                                                             #
 # This software is distributed under the terms of the GNU General Public      #
 # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
@@ -19,7 +19,7 @@ from PyConf.application import configure, configure_input, configured_ann_svc
 from PyConf.application import metainfo_repos
 from PyConf.control_flow import CompositeNode, NodeLogic
 from PyConf.Algorithms import EventAccounting
-from DaVinci.algorithms import (define_fsr_writer, apply_filters_and_unpacking)
+from DaVinci.algorithms import (define_fsr_writer, apply_filters)
 
 log = logging.getLogger(__name__)
 
@@ -170,14 +170,11 @@ def add_davinci_configurables(options, user_algorithms, public_tools):
         ]
 
     elif options.annsvc_config:  # this should be renamed to input_manifest_file
-        # distinguish between configuring the ANNSvc for decoding, and getting
-        # the manifest to configure the unpacking (the latter has _NOTHING_ to
-        # do with the ANNSvc)
-        # Here we only do the decoding part. The unpacking manifest part we
-        # do in apply_filters_and_unpacking...
+        # distinguish between configuring the ANNSvc for decoding and unpacking
+        # manifest file is not needed for unpacking anymore
         config.add(configured_ann_svc(json_file=options.annsvc_config))
 
-    dvMainFlow = apply_filters_and_unpacking(options, user_algorithms)
+    dvMainFlow = apply_filters(options, user_algorithms)
 
     fsrAlgs = {}
     if options.write_fsr:
diff --git a/Phys/DaVinci/tests/config/test_algorithms.py b/Phys/DaVinci/tests/config/test_algorithms.py
index 74f27e3cc..cad62cf1c 100644
--- a/Phys/DaVinci/tests/config/test_algorithms.py
+++ b/Phys/DaVinci/tests/config/test_algorithms.py
@@ -11,8 +11,7 @@
 from PyConf.Algorithms import Gaudi__Examples__VoidConsumer as VoidConsumer
 
 from DaVinci import Options
-from DaVinci.algorithms import (define_fsr_writer, add_filter,
-                                apply_filters_and_unpacking,
+from DaVinci.algorithms import (define_fsr_writer, add_filter, apply_filters,
                                 configured_FunTuple)
 from PyConf.reading import get_odin, get_decreports, get_hlt_reports, upfront_decoder
 from PyConf.application import default_raw_event
@@ -24,7 +23,7 @@ def test_define_write_fsr():
     """
     options = Options(
         data_type="Upgrade",
-        input_process="Turbo",
+        input_process="Gen",
         evt_max=1,
         output_level=3,
         merge_genfsr=True,
@@ -83,7 +82,7 @@ def test_add_void_filter():
     """
     options = Options(
         data_type="Upgrade",
-        input_process="Turbo",
+        input_process="Gen",
         evt_max=1,
         simulation=True,
     )
@@ -93,20 +92,20 @@ def test_add_void_filter():
     assert "VoidFilter" in test_filter.fullname
 
 
-def test_apply_filters_and_unpack():
+def test_apply_filters():
     """
     Check if DaVinci applies correctly a filter in front of a given algorithm
     """
     options = Options(
         data_type="Upgrade",
         input_raw_format=0.5,
-        input_process="Turbo",
+        input_process="Gen",
         evt_max=1,
         evt_pre_filters={"test_filter": "EVT_PREFILTER"},
         simulation=True,
     )
     alg_dict = {"test_alg": [VoidConsumer()]}
-    test_alg_dict = apply_filters_and_unpacking(options, alg_dict)
+    test_alg_dict = apply_filters(options, alg_dict)
     list_of_main_expected_algs = ["LoKi__VoidFilter"]
 
     for exp_alg in list_of_main_expected_algs:
@@ -155,7 +154,7 @@ def test_get_odin():
     """
     options = Options(
         data_type="Upgrade",
-        input_process="Turbo",
+        input_process="Gen",
         evt_max=1,
         input_raw_format=0.5,
         simulation=True,
@@ -163,7 +162,7 @@ def test_get_odin():
     with default_raw_event.bind(raw_event_format=options.input_raw_format):
         odin = get_odin(
             input_process=options.input_process, stream=options.stream)
-    assert odin.location == "/Event/createODIN#1/ODIN"
+    assert odin.location == "/Event/createODIN/ODIN"
 
 
 def test_get_decreports():
-- 
GitLab