colstore.to_root

colstore.to_root(source, path, *, backend='auto', treename='events', columns=None, batch_size='512 MiB', compression_level=0, compression_algorithm=None, output_format=None, multithreading=True, show_progress=True)[source]

Write a colstore reader, dataset, or selection out to a ROOT file.

The columns are streamed to path in bounded memory, one batch_size batch at a time, so a store larger than memory writes fine. Column names that are not valid ROOT branch names (containing spaces, brackets, or other symbols) are reduced to word characters first, with a warning naming each change; colliding results are disambiguated with a numeric suffix.

Parameters:
  • source (colstore reader or dataset, str, or os.PathLike) – An opened reader or dataset, or a path to a .cstore file.

  • path (str or os.PathLike) – Destination .root file; recreated if it already exists.

  • backend (str, optional) – Backend to write with: "auto" (default) uses PyROOT if importable, else uproot; "ROOT" forces PyROOT/RDataFrame; "uproot" forces uproot. Raises if the requested backend is missing.

  • treename (str, optional) – Name of the tree to write. Defaults to "events".

  • columns (list[str] or None, optional) – Columns to write, in this order. None (default) writes every column. Naming a column absent from the store is an error.

  • batch_size (int, str, or None, optional) – Per-batch memory budget: an int is rows per batch; a str (default "512 MiB") is a byte budget; None writes in a single pass.

  • compression_level (int) – ROOT-backend options (ignored by the uproot backend). compression_level defaults to 0 (uncompressed; ROOT’s own default is 5). The string compression_algorithm ("zlib"/"lzma"/"lz4"/"zstd") and output_format ("default"/"ttree"/"rntuple") name ROOT enums; any other value is passed through. multithreading toggles implicit MT for the Snapshot (an int sets the thread count), restored afterward; MT may reorder rows, so pass False to preserve order.

  • compression_algorithm (str | int | None) – ROOT-backend options (ignored by the uproot backend). compression_level defaults to 0 (uncompressed; ROOT’s own default is 5). The string compression_algorithm ("zlib"/"lzma"/"lz4"/"zstd") and output_format ("default"/"ttree"/"rntuple") name ROOT enums; any other value is passed through. multithreading toggles implicit MT for the Snapshot (an int sets the thread count), restored afterward; MT may reorder rows, so pass False to preserve order.

  • output_format (str | int | None) – ROOT-backend options (ignored by the uproot backend). compression_level defaults to 0 (uncompressed; ROOT’s own default is 5). The string compression_algorithm ("zlib"/"lzma"/"lz4"/"zstd") and output_format ("default"/"ttree"/"rntuple") name ROOT enums; any other value is passed through. multithreading toggles implicit MT for the Snapshot (an int sets the thread count), restored afterward; MT may reorder rows, so pass False to preserve order.

  • multithreading (bool | int) – ROOT-backend options (ignored by the uproot backend). compression_level defaults to 0 (uncompressed; ROOT’s own default is 5). The string compression_algorithm ("zlib"/"lzma"/"lz4"/"zstd") and output_format ("default"/"ttree"/"rntuple") name ROOT enums; any other value is passed through. multithreading toggles implicit MT for the Snapshot (an int sets the thread count), restored afterward; MT may reorder rows, so pass False to preserve order.

  • show_progress (bool, optional) – Whether to display a progress bar. Defaults to True.

Returns:

pathlib.Path – The path the ROOT file was written to.

Return type:

Path