Skip to content

3. ReadROOT's IOClasses

Chloé Legué edited this page Jun 28, 2023 · 2 revisions

The IOClasses

The IOClasses that are coded in the ReadROOT package allow for some modification of the C++ files. The current C++ code needs very specific header files and to save time, the IOClasses allow to save a configuration. This means if you use a different computer, you can create and load different configurations of the C++ header files.

FileExplorer Class

The FileExplorer class simply uses Tkinter's filedialog. You can either ask the FileExplorer to find files or find a specific folder. In both cases the initial search directory can be selected.

>>> import ReadROOT as r
>>> file_explorer = r.fileexp()
>>> #For files:
>>> file_explorer.FindFiles()
>>> #For folders:
>>> file_explorer.FindFolder()

Configuration Class

The Configuration class will allow you to save the paths to the C++ header files needed for the C++ code. In order to create a configuration, a name and a .json file are used to first initialize the configuration. If the configuration already exists in the .json file, it can be loaded back up. If you just made a new configuration, you can save it to a .json file or simply keep it in memory (this will be deleted if Python is closed).

Search for the C++ header files, loading a configuration and saving a configuration

By default creating a Configuration instance will not do anything. After calling find_required_headers the Configuration's required headers and pybind headers will be updated. By default, only 3 header files are needed. If extra files are needed the number of required headers can be changed using set_required_headers. If autosave is set to True, the Configuration instance will automatically be saved to the selected .json file.

>>> import ReadROOT as r
>>> new_config = r.config("Name of your configuration", "config.json") #Here we use "config.json" since this file already exists in the ReadROOT package.
>>> new_config.find_required_headers(autosave=True) #This will allow you to look for the header files and automatically save their path in the json file.

SetUpCpp Class

The SetUpCpp class only needs a file path (a C++ file) to update in order to be initialized. Using a selected configuration, one can update the C++ files.

Update the C++ code with the new header files

After making a Configuration, it is possible to update two C++ files. The following code will show you how to update both the funcs.hpp and wrap.cpp which are the two C++ files that need to be updated if a different computer or Python version is used.

>>> import ReadROOT as r
>>> new_setup = r.setup("funcs.hpp")
>>> new_setup.load_configuration(new_config)
>>> new_setup = r.setup("wrap.cpp")
>>> new_setup.load_pybind11(new_config)

Forcing ReadROOT to reload its configuration

Currently, the config.json file (file that comes with ReadROOT and contains some saved configurations) contains an extra parameter called LoadConfig. If set to True, upon importing the ReadROOT package, you will be able to select a Configuration in the list of configurations saved in config.json. If you want to force the configuration reload, the following commands can be executed:

>>> import ReadROOT as r
>>> r.do_config()

Clone this wiki locally