Skip to content
Snippets Groups Projects
Commit 5e3a5acf authored by Davide Fazzini's avatar Davide Fazzini Committed by Miroslav Saur
Browse files

Fixes for FSR reading from LHCb 4598

parent 50d471b7
No related branches found
No related tags found
2 merge requests!4694Fixes for FSR reading from LHCb 4598,!4679Synchronize master branch with 2024-patches
###############################################################################
# (c) Copyright 2022-2023 CERN for the benefit of the LHCb Collaboration #
# (c) Copyright 2022-2024 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". #
......@@ -48,7 +48,7 @@ from typing import Optional, Callable, get_type_hints
import click
import yaml
import ROOT
from ROOT import TFile
# Workaround for https://gitlab.cern.ch/lhcb/LHCb/-/issues/292
import warnings
......@@ -192,7 +192,8 @@ def OptionsLoader(function: FunctionLoader, options_spec: str) -> OptionsBase:
raise NotImplementedError(f"Unrecognised {options_spec!r}")
# Try to parse options from input file FSR
_config_from_fsr(options)
if options.get("input_files") is not None:
_config_from_fsr(options)
# Parse the merged YAML
try:
......@@ -221,15 +222,15 @@ def OptionsLoader(function: FunctionLoader, options_spec: str) -> OptionsBase:
def log_info(message):
click.echo(click.style("INFO: ", fg="green") + message, err=True)
click.echo(f"{click.style('INFO: ', fg='green')} {message}", err=True)
def log_warn(message):
click.echo(click.style("WARN: ", fg="yellow") + message, err=True)
click.echo(f"{click.style('WARN: ', fg='yellow')} {message}", err=True)
def log_error(message):
click.echo(click.style("ERROR: ", fg="red") + message, err=True)
click.echo(f"{click.style('ERROR: ', fg='red')} {message}", err=True)
def _make_type_hint_suggestion(function: Callable, options_arg: str) -> str:
......@@ -328,8 +329,8 @@ def _print_diff(original: str, corrected: str):
fg2 = "green"
s1 += click.style(s.a[i1:i2], fg=fg1)
s2 += click.style(s.b[j1:j2], fg=fg2)
click.echo(click.style(" Original: ", fg="red") + s1, err=True)
click.echo(click.style("Corrected: ", fg="green") + s2, err=True)
click.echo(f"{click.style('Original: ', fg='red')} {s1}", err=True)
click.echo(f"{click.style('Corrected: ', fg='green')} {s2}", err=True)
def _raise_user_exception(e, action_msg, spec):
......@@ -403,34 +404,32 @@ def _config_from_fsr(options):
"simulation", "process", "output_type", "output_manifest_file"
]
if input_files is not None:
root_file = OptionsBase.glob_input_files(input_files)[0]
# Check if the input file is a ROOT file
if not any(root_file.endswith(x)
for x in [".raw", ".mdf"]) and Path(root_file).is_file():
try:
f = ROOT.TFile.Open(root_file)
fsr = yaml.safe_load(str(f.FileSummaryRecord))
except AttributeError:
pass
else:
if fsr and "application_options" in fsr.keys():
opts_fsr = fsr["application_options"]
for name, value in opts_fsr.items():
# Not overwrite the options is defined in the user options
if name in options.keys():
click.echo(click.style("INFO: ", fg="green") + f"{name} is set to '{options[name]}' as defined by the user,"\
" ignoring the information stored in the input file FSR.")
elif name in allowed_options:
click.echo(
click.style("INFO: ", fg="green") +
f"{name} is set to '{value}' using the information stored in the input file FSR."
)
if name == "process":
opt_name = "input_process"
elif "output" in name:
opt_name = name.replace("output", "input")
else:
opt_name = name
options[opt_name] = value
root_file = OptionsBase.glob_input_files(input_files)[0]
# Check if the input file is a ROOT file
if not any(root_file.endswith(x)
for x in [".raw", ".mdf"]) and Path(root_file).is_file():
try:
f = TFile.Open(root_file)
fsr = yaml.safe_load(str(f.FileSummaryRecord))
except AttributeError:
pass
else:
if fsr and "application_options" in fsr.keys():
opts_fsr = fsr["application_options"]
for name, value in opts_fsr.items():
# Not overwrite the options is defined in the user options
if name in options.keys():
click.echo(f"{click.style('INFO: ', fg='green')} {name} is set to '{options[name]}' as defined by the user,"\
" ignoring the information stored in the input file FSR.")
elif name in allowed_options:
click.echo(
f"{click.style('INFO: ', fg='green')} {name} is set to '{value}' using the information stored in the input file FSR."
)
if name == "process":
opt_name = "input_process"
elif "output" in name:
opt_name = name.replace("output", "input")
else:
opt_name = name
options[opt_name] = value
/*****************************************************************************\
* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration *
* (c) Copyright 2000-2024 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". *
......
......@@ -346,10 +346,13 @@ namespace LHCb::FSR {
"if set to true, job options are added to the file summary record"};
Gaudi::Property<std::string> m_includeApplicationOptions{
this, "IncludeApplicationOptions", "",
"If provided with the application options, they will be persisted to the FSR"};
"If set, this string provides the application options that will be persisted to the FSR"};
Gaudi::Property<std::string> m_configurationFSRs{this, "ConfigurationFSRs", "",
"If set provide the configuration of the expected FSRs"};
Gaudi::Property<std::string> m_configurationFSRs{
this, "ConfigurationFSRs", "",
"If set, this string provide the configuration to be parsed for "
"reading and writing the FSRs.The default configuration is available in PyConf "
"utils.py "};
struct OutputFile {
std::string name;
......
###############################################################################
# (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration #
# (c) Copyright 2022-2024 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". #
......@@ -31,9 +31,11 @@ def load_file(fname):
def get_fsr_configurations():
"""
Expected FSR configuration for each version. The keys represent the names used to store the FSR
in the output file, while the values indicate the entities responsible for producing the
corresponding content to be stored.
Expected configuration keys for each FSR version: the keys represent the names used to store the FSR
in the output file, while the values indicate the entities responsible for generating the
corresponding content. New FSR versions can be added when additional information needs to be stored,
ensuring the backward compatibility with each FSR update.
By default, the output FSRs are written using the configuration of the latest version.
"""
config_fsr = {
"1.0": {
......
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