root_mcp.core.io package
Core I/O operations for ROOT files.
- class root_mcp.core.io.DataExporter(config)[source]
Bases:
objectExport TTree data to various formats.
Supports JSON, CSV, and Parquet exports with compression options.
- Parameters:
config (Config)
- __init__(config)[source]
Initialize data exporter.
- Parameters:
config (Config) – Server configuration
- class root_mcp.core.io.FileCache(max_size)[source]
Bases:
objectLRU 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
- class root_mcp.core.io.FileManager(config)[source]
Bases:
objectManages 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
- get_branch_schema(path, tree_name, branch_name=None)[source]
Get detailed schema information for branches.
- class root_mcp.core.io.HistogramReader(config, file_manager)[source]
Bases:
objectHigh-level interface for reading histograms.
Provides access to TH1, TH2, TH3, and TProfile objects.
- Parameters:
config (Config)
file_manager (FileManager)
- __init__(config, file_manager)[source]
Initialize HistogramReader.
- Parameters:
config (Config) – Server configuration
file_manager (FileManager) – File manager instance
- class root_mcp.core.io.PathValidator(config)[source]
Bases:
objectValidates file paths against security constraints.
- Parameters:
config (Config)
- __init__(config)[source]
Initialize validator with configuration.
- Parameters:
config (Config) – Server configuration
- check_file_pattern(path, resource)[source]
Check if a file matches resource patterns.
- Parameters:
path (Path) – File path
resource (ResourceConfig) – Resource configuration
- Returns:
True if file matches allowed patterns and not excluded
- Return type:
- validate_output_path(path)[source]
Validate an output path for exports.
- Parameters:
path (str) – Destination path for export
- Returns:
Validated path
- Raises:
SecurityError – If path is not allowed for output
- Return type:
- validate_path(path, resource=None)[source]
Validate a file path against security constraints.
- Parameters:
path (str) – File path or URI to validate
resource (ResourceConfig | None) – Optional resource context
- Returns:
Resolved, validated Path object
- Raises:
SecurityError – If path violates security constraints
- Return type:
Path
- validate_write_operation(input_path, output_path, allow_overwrite=False)[source]
Validate a write operation to ensure security constraints.
This method enforces critical security rules: 1. Input and output paths must be different 2. Output path must be in allowed output directory 3. Cannot overwrite existing files unless explicitly allowed
- Parameters:
- Returns:
Tuple of (validated_input_path, validated_output_path)
- Raises:
SecurityError – If security constraints are violated
- Return type:
- class root_mcp.core.io.TreeReader(config, file_manager)[source]
Bases:
objectHigh-level interface for reading TTree data.
Provides safe, efficient access to TTree branches with chunking, filtering, and pagination.
- Parameters:
config (Config)
file_manager (FileManager)
- __init__(config, file_manager)[source]
Initialize TreeReader.
- Parameters:
config (Config) – Server configuration
file_manager (FileManager) – File manager instance
- compute_branch_stats(path, tree_name, branches, selection=None)[source]
Compute statistics for branches.
- read_branches(path, tree_name, branches, selection=None, limit=None, offset=0, flatten=False, defines=None)[source]
Read branch data from a TTree.
- Parameters:
path (str) – File path
tree_name (str) – Tree name
branches (list[str]) – List of branch names to read (can include derived branches from defines)
selection (str | None) – Optional ROOT-style cut expression
limit (int | None) – Maximum number of entries to return
offset (int) – Number of entries to skip
flatten (bool) – Flatten jagged arrays
defines (dict[str, str] | None) – Optional derived variable definitions {name: expression}
- Returns:
Dictionary with data and metadata
- Return type:
- sample_tree(path, tree_name, size=100, method='first', branches=None, seed=None)[source]
Get a sample from a tree.
Submodules
- root_mcp.core.io.exporters module
- root_mcp.core.io.file_manager module
FileCacheFileManagerFileManager.__init__()FileManager.clear_cache()FileManager.get_branch_schema()FileManager.get_cache_stats()FileManager.get_file_info()FileManager.get_tree()FileManager.get_tree_info()FileManager.list_histograms()FileManager.list_objects()FileManager.list_trees()FileManager.open()FileManager.validate_file()
- root_mcp.core.io.readers module
- root_mcp.core.io.validators module