Skip to content
Snippets Groups Projects
Commit 1406d7bb authored by Patrick Koppenburg's avatar Patrick Koppenburg :leaves:
Browse files

Merge branch 'erodrigu-rm-make_dvalgorithm' into 'master'

Remove calls to non-thread safe code from Python

See merge request !825
parents 624025f2 9a3e4e14
No related branches found
No related tags found
2 merge requests!1103Draft: Add AnalysisHelpers to DaVinci Stack,!825Remove calls to non-thread safe code from Python
Pipeline #5072882 passed
###############################################################################
# (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration #
# (c) Copyright 2022-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". #
......@@ -18,7 +18,7 @@ Example of a typical DaVinci job:
import Functors as F
from Gaudi.Configuration import INFO
from DaVinci import Options, make_config
from DaVinci.algorithms import add_filter #, filter_on
from DaVinci.algorithms import add_filter
from DecayTreeFitter import DecayTreeFitter
from FunTuple import FunctorCollection as FC
from FunTuple import FunTuple_Particles as Funtuple
......@@ -32,13 +32,7 @@ def main(options: Options):
fields['Ds'] = "[B0 -> ^D_s- K+]CC"
fields['K'] = "[B0 -> D_s- ^K+]CC"
#Get filtered particles (Note decay_descriptor is optional, if specified only B0 decays will be selected for processing)
spruce_line = "SpruceB2OC_BdToDsmK_DsmToHHH_FEST_Line"
# REPLACING TEMPORARY THE INPUT DATA
#data_filtered = filter_on(
# f"/Event/Spruce/{spruce_line}/Particles",
# options.process,
# decay_descriptor=fields['B0'])
data_filtered = get_particles(f"/Event/Spruce/{spruce_line}/Particles")
# DecayTreeFitter Algorithm.
......
###############################################################################
# (c) Copyright 2020-2022 CERN for the benefit of the LHCb Collaboration #
# (c) Copyright 2020-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". #
......@@ -12,11 +12,9 @@ import re
import logging
from PyConf.Algorithms import (
FilterDecays,
LoKi__HDRFilter as HDRFilter,
LoKi__VoidFilter as VoidFilter,
)
from Hlt2Conf.algorithms import make_dvalgorithm
from PyConf.reading import get_particles, get_hlt_reports
log = logging.getLogger(__name__)
......@@ -191,38 +189,3 @@ def configured_FunTuple(config):
dictAlgs[key].append(funTuple)
return dictAlgs
def apply_algorithm(list_particles, algorithm, **kwargs):
"""
Function that applies an algorithm, accepting a Particle::Range as input (e.g FilterDecays),
to particles from Hlt2 or Spruce sample defined in the list of TES locations gived as argument.
The extra arguments to algorithm can be passed via kwargs.
Args:
list_particles (list(str)): List of Transient event store (TES) location of Particles in Hlt2 or Spruce sample.
algorithm (PyConf.Algorithms): Algorithm to be applied.
kwargs : Extra arguments to the passed algorithm.
Returns:
Ouput TES location of the particles from the algorithm
"""
dv_algorithm = make_dvalgorithm(algorithm)
return dv_algorithm(ParticlesA=list_particles, **kwargs).Particles
def filter_on(location, decay_descriptor=None):
"""
Function to get particles from Hlt2 or Spruce sample.
A FilterDecays is applied before returning the requested particles if a decay descriptor
is specified as extra argument.
Args:
location (str): Transient event store (TES) location of Particles in Hlt2 or Spruce sample
decay_descriptor (str, optional): Decay descriptor that will be used to select decays in the event
Returns:
data: TES location of the particles that are loaded from the input samples
"""
data = get_particles(location)
if decay_descriptor:
data = apply_algorithm([data], FilterDecays, Code=decay_descriptor)
return data
......@@ -11,11 +11,9 @@
from PyConf.Algorithms import Gaudi__Examples__VoidConsumer as VoidConsumer
from DaVinci import Options
from DaVinci.algorithms import (
define_fsr_writer,
add_filter, #filter_on
apply_filters_and_unpacking,
configured_FunTuple)
from DaVinci.algorithms import (define_fsr_writer, add_filter,
apply_filters_and_unpacking,
configured_FunTuple)
from PyConf.reading import get_odin, get_decreports, get_hlt_reports, upfront_decoder
from PyConf.application import default_raw_event
......@@ -184,16 +182,3 @@ def test_get_decreports():
get_hlt_reports.bind(input_process=options.input_process, stream=options.stream):
decreports = get_decreports("Hlt2")
assert decreports.location == "/Event/Hlt2/DecReports"
"""
def test_filter_on_and_apply_algorithms():
""
Check if filter_on and apply_algorithms functions return a correct filtered particle location."
""
spruce_line = "SpruceB2OC_BdToDsmK_DsmToHHH_FEST_Line"
decay_descriptor = "[B0 -> D_s- K+]CC"
data_filtered = filter_on(f"/Event/Spruce/{spruce_line}/Particles",
decay_descriptor)
assert data_filtered.location == "/Event/FilterDecays/particles"
"""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment