ftag.find_metadata#

Attributes#

Classes#

MetadataFinder

Find PMG metadata for .h5 files and optionally inject it.

Functions#

main(→ None)

Command line entry point to fetch and inject PMG metadata.

Module Contents#

ftag.find_metadata.XSECDB_MAP#
ftag.find_metadata.XSECDB_URL_BASE = 'https://atlas-groupdata.web.cern.ch/atlas-groupdata/dev/PMGTools/'#
class ftag.find_metadata.MetadataFinder(h5_path: str)#

Find PMG metadata for .h5 files and optionally inject it.

Parameters:

h5_path (str) – Path to the HDF5 file where metadata should be injected.

h5_path#
_extract_taskid() → str | None#

Extract the 8-digit BigPanDA Task ID from the filename.

Returns:

The extracted Task ID, or None if no match is found.

Return type:

str | None

_fetch_taskinfo(taskid: str) → dict | None#

Fetch task details from the BigPanDA JSON API.

Parameters:

taskid (str) – The BigPanDA Task ID.

Returns:

The first task record from the API response, or None if unavailable.

Return type:

dict | None

_extract_container(info: dict) → str | None#

Find the MC container name within the task information.

Parameters:

info (dict) – The task information dictionary from BigPanDA.

Returns:

The container name (e.g., ‘mc16_13TeV…’ or ‘mc23_13p6TeV…’), or None if not found.

Return type:

str | None

_parse_info(container: str) → tuple[int, str, str] | None#

Parse DSID, etag, and campaign from a container name.

Parameters:

container (str) – The full MC container name.

Returns:

A tuple of (DSID, etag, campaign), or None if parsing fails. Note: ‘mc20’ is automatically mapped to ‘mc16’.

Return type:

tuple[int, str, str] | None

_download_db(campaign: str) → str#

Download the PMG database for a specific campaign.

Parameters:

campaign (str) – The MC campaign name (e.g., ‘mc16’).

Returns:

The local path to the downloaded database file.

Return type:

str

_query_xsecdb(campaign: str, dsid: int, etag: str) → dict | None#

Search the PMG database for metadata matching a DSID and etag.

Parameters:
  • campaign (str) – The MC campaign name.

  • dsid (int) – Dataset ID.

  • etag (str) – The AMI tag (e.g., ‘e1234’).

Returns:

Dictionary containing ‘cross_section_pb’, ‘genFiltEff’, and ‘kfactor’, or None if no matching record is found.

Return type:

dict | None

fetch_metadata() → tuple[int, dict]#

Look up the PMG metadata for the HDF5 file without modifying it.

This method coordinates Task ID extraction, API fetching and DB querying.

Returns:

The DSID and a dictionary containing ‘cross_section_pb’, ‘genFiltEff’ and ‘kfactor’.

Return type:

tuple[int, dict]

Raises:

RuntimeError – If any step fails and no metadata can be found.

inject_metadata() → None#

Find the metadata and write it into the HDF5 file.

Metadata is stored in a group named metadata/{dsid}. A RuntimeError from fetch_metadata() is passed on if no metadata can be found.

ftag.find_metadata.main() → None#

Command line entry point to fetch and inject PMG metadata.