Skip to content
Snippets Groups Projects
Commit 7d7083fb authored by Eduardo Rodrigues's avatar Eduardo Rodrigues
Browse files

Merge branch 'return_lfns' into 'master'

Added command to return LFNs

See merge request !36
parents 542f741f c0b9a1b8
No related branches found
No related tags found
1 merge request!36Added command to return LFNs
Pipeline #5851191 passed
...@@ -44,6 +44,7 @@ console_scripts = ...@@ -44,6 +44,7 @@ console_scripts =
apd-logout = apd.command:cmd_logout apd-logout = apd.command:cmd_logout
apd-cache-info = apd.command:cmd_cache_ap_info apd-cache-info = apd.command:cmd_cache_ap_info
apd-list-pfns = apd.command:cmd_list_pfns apd-list-pfns = apd.command:cmd_list_pfns
apd-list-lfns = apd.command:cmd_list_lfns
apd-list-samples = apd.command:cmd_list_samples apd-list-samples = apd.command:cmd_list_samples
apd-summary = apd.command:cmd_summary apd-summary = apd.command:cmd_summary
apd-cache-files = apd.command:cmd_cache_ap_files apd-cache-files = apd.command:cmd_cache_ap_files
......
############################################################################### ###############################################################################
# (c) Copyright 2021 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 # # This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
......
...@@ -351,8 +351,8 @@ class AnalysisData: ...@@ -351,8 +351,8 @@ class AnalysisData:
): ):
# pylint: disable-msg=too-many-locals # pylint: disable-msg=too-many-locals
"""Main method that returns the dataset info. """Main method that returns the dataset info.
The normal behaviour is to return the PFNs for the samples but setting The normal behaviour is to return the PFNs for the samples, but setting
return_pfns to false returns the SampleCollection""" return_type to ApdReturnType.SAMPLE returns the SampleCollection"""
# Establishing the list of samples to run on # Establishing the list of samples to run on
samples = self._samples samples = self._samples
......
############################################################################### ###############################################################################
# (c) Copyright 2021-2023 CERN for the benefit of the LHCb Collaboration # # (c) Copyright 2021-203 CERN for the benefit of the LHCb Collaboration #
# # # #
# This software is distributed under the terms of the GNU General Public # # This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
...@@ -21,7 +21,12 @@ import click # type: ignore[import] ...@@ -21,7 +21,12 @@ import click # type: ignore[import]
import click_log # type: ignore[import] import click_log # type: ignore[import]
import requests import requests
from .analysis_data import APD_DATA_CACHE_DIR, APD_METADATA_CACHE_DIR, get_analysis_data from .analysis_data import (
APD_DATA_CACHE_DIR,
APD_METADATA_CACHE_DIR,
ApdReturnType,
get_analysis_data,
)
from .ap_info import cache_ap_info from .ap_info import cache_ap_info
from .authentication import get_auth_headers, logout from .authentication import get_auth_headers, logout
from .data_cache import DataCache from .data_cache import DataCache
...@@ -192,6 +197,67 @@ def cmd_list_pfns( ...@@ -192,6 +197,67 @@ def cmd_list_pfns(
click.echo(f) click.echo(f)
@click.command()
@click.argument("working_group")
@click.argument("analysis")
@click.option(
"--cache_dir",
default=os.environ.get(APD_METADATA_CACHE_DIR, None),
help="Specify location of the cache for the analysis metadata",
)
@click.option("--tag", default=None, help="Tag to filter datasets", multiple=True)
@click.option(
"--value",
default=None,
help="Tag value used if the name is specified",
multiple=True,
)
@click.option(
"--eventtype", default=None, help="eventtype to filter the datasets", multiple=True
)
@click.option(
"--datatype", default=None, help="datatype to filter the datasets", multiple=True
)
@click.option(
"--polarity", default=None, help="polarity to filter the datasets", multiple=True
)
@click.option(
"--config", default=None, help="Config to use (e.g. lhcb or mc)", multiple=True
)
@click.option("--name", default=None, help="dataset name")
@click.option("--version", default=None, help="dataset version")
@click.option("--date", default=None, help="analysis date in ISO 8601 format")
@click_log.simple_verbosity_option(logger)
@common_docstr()
def cmd_list_lfns(
working_group,
analysis,
cache_dir,
tag,
value,
eventtype,
datatype,
polarity,
config,
name,
version,
date,
):
"""List the LFNs for the analysis, matching the tags specified.
This command checks that the arguments are not ambiguous."""
# Loading the data and filtering/displaying
datasets = get_analysis_data(
working_group, analysis, metadata_cache=cache_dir, ap_date=date
)
filter_tags = _process_common_tags(
eventtype, datatype, polarity, config, name, version
)
filter_tags |= dict(zip(tag, value))
for f in datasets(**filter_tags, return_type=ApdReturnType.LFN):
click.echo(f)
@click.command() @click.command()
@click.argument("working_group") @click.argument("working_group")
@click.argument("analysis") @click.argument("analysis")
...@@ -249,7 +315,9 @@ def cmd_list_samples( ...@@ -249,7 +315,9 @@ def cmd_list_samples(
eventtype, datatype, polarity, config, name, version eventtype, datatype, polarity, config, name, version
) )
filter_tags |= dict(zip(tag, value)) filter_tags |= dict(zip(tag, value))
matching = datasets(check_data=False, return_pfns=False, **filter_tags) matching = datasets(
check_data=False, return_type=ApdReturnType.SAMPLE, **filter_tags
)
click.echo(matching) click.echo(matching)
......
...@@ -16,7 +16,8 @@ try: ...@@ -16,7 +16,8 @@ try:
from snakemake.remote.XRootD import RemoteProvider as XRootDRemoteProvider # type: ignore[import] from snakemake.remote.XRootD import RemoteProvider as XRootDRemoteProvider # type: ignore[import]
except Exception as exc: except Exception as exc:
raise Exception("apd.snakemake requires snakemake to be available") from exc raise Exception("apd.snakemake requires snakemake to be available") from exc
# isort: on
from .analysis_data import ApdReturnType
from .analysis_data import get_analysis_data as std_get_analysis_data from .analysis_data import get_analysis_data as std_get_analysis_data
from .eos import auth as std_auth from .eos import auth as std_auth
from .eos import authw as std_authw from .eos import authw as std_authw
...@@ -68,8 +69,8 @@ class AnalysisDataWrapper: ...@@ -68,8 +69,8 @@ class AnalysisDataWrapper:
def __call__(self, *args, **kwargs): def __call__(self, *args, **kwargs):
results = self.analysisData(*args, **kwargs) results = self.analysisData(*args, **kwargs)
return_pfns = kwargs.get("return_pfns", True) return_type = kwargs.get("return_type", ApdReturnType.PFN)
if not return_pfns: if return_type != ApdReturnType.PFN:
return results return results
return [remote(f) for f in results] return [remote(f) for f in results]
......
############################################################################### ###############################################################################
# (c) Copyright 2021 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 # # This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
......
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