Skip navigation links

Package rootio

Several tools to read and browser ROOT files.

See: Description

Package rootio Description

Several tools to read and browser ROOT files. This package is modernized freehep-rootio project suitable for Java scripting. It also includes partial ROOT6 support. It includes:

  1. The basic root IO (hep.io.root) package
  2. A Root Object Browser, demo/debug application
  3. A Java "interface builder" for dynamically creating Java Interfaces for user defined objects in the ROOT file
Here is a typical Java example:
import hep.io.root.*;
import hep.io.root.interfaces.*;
import java.io.IOException;

public class RootTest
{
    public static void main(String[] argv) throws IOException
    {
        RootFileReader rfr = new RootFileReader("Example.root");
        TKey key = rfr.getKey("mainHistogram");
        TH1 histogram = (TH1) key.getObject();
        double entries= histogram.getEntries();
        System.out.println("entries="+entries);
   }    
}

Reading User Defined Objects

Before reading the file you must first use the Interface Builder to create the Java Interface for the user-defined objects contained in your file. The InterfaceBuilder has created an interface with accessor methods for each data member inside the user defined object. Using this interface it is now easy to write a routine to access the objects from the file:
import hep.io.root.*;
import hep.io.root.interfaces.*;
import java.io.IOException;

public class MoyTest
{
    public static void main(String[] argv) throws IOException
    {
        RootFileReader rfr = new RootFileReader("Moy.root");
        TKey key = rfr.getKey("MeanPedBF_0");
        Moyennes moy = (Moyennes) key.getObject();
        // Now we have the user define object we can call any method 
        int size = moy.getSize();
        System.out.println("Size="+size);
   } 
}

Skip navigation links

Jas4pp 1.5 © Java Analysis Studio for Particle Physics