root_mcp.core.io.file_manager module

File manager for opening, caching, and managing ROOT files.

class root_mcp.core.io.file_manager.FileCache(max_size)[source]

Bases: object

LRU cache for open ROOT files.

Parameters:

max_size (int)

__init__(max_size)[source]

Initialize file cache.

Parameters:

max_size (int) – Maximum number of files to keep open

clear()[source]

Clear the cache.

Return type:

None

get(path)[source]

Get file from cache.

Parameters:

path (str) – File path

Returns:

Open file object or None if not cached

Return type:

Any | None

put(path, file_obj)[source]

Add file to cache.

Parameters:
  • path (str) – File path

  • file_obj (Any) – Open file object

Return type:

None

size()[source]

Get current cache size.

Return type:

int

class root_mcp.core.io.file_manager.FileManager(config)[source]

Bases: object

Manages opening and caching of ROOT files.

Provides safe, efficient access to local and remote ROOT files with automatic caching and connection pooling.

Parameters:

config (Config)

__init__(config)[source]

Initialize file manager.

Parameters:

config (Config) – Server configuration

clear_cache()[source]

Clear the file cache.

Return type:

None

get_branch_schema(path, tree_name, branch_name=None)[source]

Get detailed schema information for branches.

Parameters:
  • path (str | Path) – File path

  • tree_name (str) – Tree name

  • branch_name (str | None) – Optional specific branch (None = all branches)

Returns:

Dictionary with branch schema information

Return type:

dict[str, Any]

get_cache_stats()[source]

Get cache statistics.

Returns:

Dictionary with cache stats

Return type:

dict[str, int]

get_file_info(path)[source]

Get basic information about a ROOT file.

Parameters:

path (str | Path) – File path

Returns:

Dictionary with file metadata

Return type:

dict[str, Any]

get_tree(path, tree_name)[source]

Get a specific TTree from a file.

Parameters:
  • path (str | Path) – File path

  • tree_name (str) – Name or path to tree

Returns:

uproot TTree object

Raises:

KeyError – If tree doesn’t exist

Return type:

Any

get_tree_info(path, tree_name)[source]

Get comprehensive metadata about a TTree or RNTuple.

Parameters:
  • path (str | Path) – File path

  • tree_name (str) – Tree name

Returns:

Dictionary with comprehensive tree metadata

Return type:

dict[str, Any]

list_histograms(path)[source]

List all histograms in a ROOT file.

Parameters:

path (str | Path) – File path

Returns:

List of histogram metadata dictionaries

Return type:

list[dict[str, Any]]

list_objects(path)[source]

List all objects in a ROOT file.

Parameters:

path (str | Path) – File path

Returns:

List of object metadata dictionaries

Return type:

list[dict[str, Any]]

list_trees(path)[source]

List all TTrees and RNTuples in a ROOT file.

Parameters:

path (str | Path) – File path

Returns:

List of tree metadata dictionaries

Return type:

list[dict[str, Any]]

open(path, **kwargs)[source]

Open a ROOT file with caching.

Parameters:
  • path (str | Path) – File path or URI

  • **kwargs (Any) – Additional arguments to pass to uproot.open()

Returns:

Open uproot file object

Raises:
Return type:

Any

validate_file(path)[source]

Validate ROOT file integrity and readability.

Parameters:

path (str | Path) – File path

Returns:

Dictionary with validation results

Return type:

dict[str, Any]