Thanks to visit codestin.com
Credit goes to github.com

Skip to content

SpyrosJani/root2data

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

76 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ROOT2Data_1

DOI

Convert .root files to other data formats

from ROOT.. to HDF5/ SQLite/ Parquet πŸ’» βš™οΈ

Abstract

This repository provides a Python toolset for converting ROOT files to another format. It includes functionalities for reading data from ROOT files branches and saving them as other file formats.

Additionally, we can explore the file structure & print a dataframe. Ξ€he mutual compatibility and installation of the Python packages used to read and convert .root files ensure minimal dependency conflicts.

The scope of this work, was to create a general tool for converting ROOT files to other formats.

Usage

  1. Directory Structure - Construct the following directories in your project:

    • data/root: Ensure that you have this directory containing ROOT files.
    • data/h5: Directory where HDF5 files will be saved (if not present it will be created).
    • data/sqlite: Directory where SQLite files will be saved (if not present it will be created).
    • data/parquet: Directory where Parquet files will be saved (if not present it will be created).
  2. User Interface - Upon running the script, you'll be prompted to choose one of the following options:

    • Read a HDF5 | SQLite | Parquet file
    • Convert ROOT files to HDF5 | SQLite | Parquet
    • Exit the program.

Project structure

root2data/
β”‚
β”œβ”€β”€ .gitignore
β”œβ”€β”€ LICENCSE
β”œβ”€β”€ README.md
β”œβ”€β”€ create_env.sh
β”œβ”€β”€ main.py
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ data/ # this folder is created if not present
β”‚   β”œβ”€β”€ h5/
β”‚   β”œβ”€β”€ parquet/
β”‚   β”œβ”€β”€ root/
β”‚   └── sqlite/
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ __init__.py 
β”‚   β”œβ”€β”€ conversion.py
β”‚   β”œβ”€β”€ data_ops.py
β”‚   β”œβ”€β”€ file_ops.py
β”‚   β”œβ”€β”€ hdf5_ops.py
β”‚   β”œβ”€β”€ parquet_ops.py
β”‚   β”œβ”€β”€ sqlite_ops.py
β”‚   └── ui_ops.py
└── src/
    └── transform.py

ROOT file structure

Our ROOT files have the following simple structure:
root_file/
β”‚
β”œβ”€β”€ Tree;1/
β”‚   β”œβ”€β”€ variable_1.1
β”‚   β”œβ”€β”€ variable_1.2
β”‚   β”œβ”€β”€ variable_1.3
β”‚   ...
β”‚   └── variable1_N
β”‚
β”œβ”€β”€ Tree;2
β”‚   β”œβ”€β”€ variable_2.1
β”‚   β”œβ”€β”€ variable_2.2
β”‚   β”œβ”€β”€ variable_2.3
β”‚   ...
β”‚   └── variable_2.N
...
└── Tree;M/
    β”œβ”€β”€ variable_M.1
    β”œβ”€β”€ variable_M.2
    β”œβ”€β”€ variable_M.3
    ...
    └── variable_M.N

Prerequisites

Method 1:

The following will create a python virtual environment and at the same time activate it:

source create_env.sh

Method 2:

Another way is to create the virtual environment manually:

python3 -m venv root2data

After that, activate the virtual environment:

source root2data/bin/activate

Then execute the following to install required packages:

pip install -r requirements.txt

Both methods, assure that you have created a virtual env called root2data

Walkthrough

  1. Clone the repository.
git clone https://github.com/appINPP/root2data.git

Screenshot from 2024-10-03 12-44-40

  1. Create the virtual environment, as discusssed above in the prerequisites section.

  2. Execute the main.py and select the desired features (seperate them with space).

python3 main.py --features event feature_X feature_Y feature_Z
  1. You are prompted to select an action (here, we select 2).

    alt text

  2. In this section, we can determine the format of the output file (here, we select 1).

    alt text

  3. You can choose to convert all detected root files or choose specific files (here, we select 1).

    alt text

  4. The conversion pipeline is initiated and the files are converted. Our process indicates if the declared features are found and in which root file tree.

alt text

  1. After conversion you are ready read the h5 files that you created by.

alt text

  1. For the h5 file, you can also read the data structure and print it as a dataframe.

alt text

Conversion Time Comparisons

1 random ROOT file

Screenshot

10 ROOT files

Screenshot

1 bigger ROOT file

Screenshot

Communication

Please feel free to contact

[email protected]

License

This project is licensed under the Apache License. See the LICENSE for details.

Contributing

User contributions can be submitted via pull request on GitHub. We recommend that you create your own fork of root2data on GitHub and use it to submit your patches.

About

A repository to convert .root files to .h5 or .sqlite data format

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.7%
  • Shell 0.3%