hepconvert.copy_root

Defined in hepconvert.copy_root on line 15.

hepconvert.copy_root(out_file, in_file, *, keep_branches=None, drop_branches=None, keep_trees=None, drop_trees=None, cut=None, expressions=None, progress_bar=None, force=False, fieldname_separator='_', title='', field_name=<function <lambda>>, initial_basket_capacity=10, resize_factor=10.0, counter_name=<function <lambda>>, step_size='100 MB', compression='ZLIB', compression_level=1)
Parameters:
  • out_file (path-like) – Name of the output file or file path.

  • in_file (str) – Local ROOT file to copy.

  • keep_branches (list of str, str, or dict, optional) – To keep only certain branches and remove all others. To remove certain branches from all TTrees in the file, pass a list of names of branches to keep, wildcarding accepted (“Jet_*”). If removing branches from one of multiple trees, pass a dict of structure: {tree: [branch1, branch2]} to keep only branch1 and branch2 in ttree “tree”. Defaults to None. Command line option: --keep-branches.

  • drop_branches (list of str, str, or dict, optional) – To remove branches from all trees, pass a list of names of branches to remove. Wildcarding supported (“Jet_*”). If removing branches from one of multiple trees, pass a dict of structure: {tree: [branch1, branch2]} to remove branch1 and branch2 from TTree “tree”. Defaults to None. Command line option: --drop-branches.

  • keep_branches – To keep only specified branches from all trees, pass a list of names of branches to remove. If removing branches from one of multiple trees, pass a dict of structure: {tree: [branch1, branch2]} to remove branch1 and branch2 from TTree “tree”. Defaults to None. Command line option: --keep-branches.

  • drop_trees (str or list of str, optional) – To remove a TTree from a file, pass a list of names of trees to remove. Defaults to None. Command line option: --drop-trees.

  • keep_trees (str or list of str, optional) – To keep only certain a TTrees in a file, pass a list of names of trees to keep. All others will be removed. Defaults to None. Command line option: --keep-trees.

  • cut (None or str) – If not None, this expression filters all of the expressions.

  • expressions (None, str, or list of str) – Names of TBranches or aliases to convert to arrays or mathematical expressions of them. Uses the language to evaluate. If None, all TBranches selected by the filters are included.

  • progress_bar (Bool, tqdm.std.tqdm object) – Displays a progress bar. Can input a custom tqdm progress bar object, or set True for a default tqdm progress bar. Must have tqdm installed.

  • force (Bool, optional) – If true, replaces file if it already exists. Default is False. Command line options -f or --force.

  • fieldname_separator (str, optional) – If data includes jagged arrays, pass the character that separates TBranch names for columns, used for grouping columns (to avoid duplicate counters in ROOT file). Defaults to “_”.

  • title (str, optional) – to change the title of the ttree, pass a new name. Defaults to None. Command line option: --title.

  • field_name (callable of str → str, optional) – Function to generate TBranch names for columns of an Awkward record array or a Pandas DataFrame. Defaults to lambda outer, inner: inner if outer == "" else outer + "_" + inner.

  • initial_basket_capacity (int, optional) – Number of TBaskets that can be written to the TTree without rewriting the TTree metadata to make room. Defaults to 10. Command line option: --initial-basket-capacity.

  • resize_factor (float, optional.) – When the TTree metadata needs to be rewritten, this specifies how many more TBasket slots to allocate as a multiplicative factor. Defaults to 10.0. Command line option: --resize-factor.

  • counter_name (callable of str → str, optional) – Function to generate counter-TBranch names for Awkward Arrays of variable-length lists. Defaults to lambda counted: "n" + counted.

  • step_size (int or str, optional) – If an integer, the maximum number of entries to include in each iteration step; if a string, the maximum memory size to include. The string must be a number followed by a memory unit, such as “100 MB”. Defaults to @. Command line option: --step-size.

  • compression (str) – Sets compression level for root file to write to. Can be one of “ZLIB”, “LZMA”, “LZ4”, or “ZSTD”. Defaults to “ZLIB”. Command line option: --compression.

  • compression_level (int) – Use a compression level particular to the chosen compressor. Defaults to 1. Command line option: --compression-level.

Examples:

Copies contents of one ROOT file to a new file. If the file is in nanoAOD-format, copy_root can drop branches from a tree while copying. RNTuple can not yet be copied.

>>> hepconvert.copy_root("copied_file.root", "original_file.root")

To copy a file and drop branches with names “branch1” and “branch2”:

>>> hepconvert.copy_root("copied_file.root", "original_file.root", drop_branches=["branch1", "branch2"])

Command Line Instructions:

This function can be run from the command line. Use command

hepconvert copy-root [options] [of] [IN_FILE]