The AIDA ITree interface provide two capabilities. The ability to group analysis objects such as Histograms, Clouds, Tuples etc. into hierarchical directories (or folders), and the ability to save and restore sets of analysis objects into files or databases.
Here is an example of how to create a set of histograms in several different folders:
import hep.aida.*; import java.util.Random; public class Tree { public static void main(String[] argv) { IAnalysisFactory af = IAnalysisFactory.create(); ITree tree = af.createTreeFactory().create(); IHistogramFactory hf = af.createHistogramFactory(tree); hf.createHistogram1D("test 1d",50,-3,3); hf.createHistogram2D("test 2d",50,-3,3,50,-3,3); tree.mkdir("/folder1"); tree.cd("/folder1"); hf.createHistogram1D("test 1d",50,-3,3); hf.createHistogram2D("test 2d",50,-3,3,50,-3,3); tree.mkdir("/folder2"); tree.cd("/folder2"); hf.createHistogram1D("test 1d",50,-3,3); hf.createHistogram2D("test 2d",50,-3,3,50,-3,3); } }
Each IHistogramFactory has an ITree associated with it. The ITree is set when the IHistogramFactory is created. Whenever the IHistogramFactory creates a new IHistogram it implicitly inserts it into the current directory of the associated ITree. The ITree initially contains a single folder (the "root folder"). New folders can be added using the mkdir(path) or mkdirs(path) method. You can change the current directory of the tree using the cd(path) method. All methods that take a path as an argument interpret that path using Unix conventions, so:
Trees also have methods for removing objects or directories, for locating objects within the tree, and for listing the contents of directories.
A second use for trees is to allow objects to be stored and retrieved from files or databases. So far we have always used the ITreeFactory.create() method to create ITree's. This method creates an ITree that is not associated with any storage, so the objects associated with this type of Tree are only valid within the current process. The other methods of ITreeFactory allow ITree's to be associated with a file or database. The following example shows how to create a set of histograms and store them in a file.
import hep.aida.*; import java.util.Random; import java.io.IOException; public class Store { public static void main(String[] argv) throws IOException { IAnalysisFactory af = IAnalysisFactory.create(); ITree tree = af.createTreeFactory().create("myFile.aida","xml",false,true); IHistogramFactory hf = af.createHistogramFactory(tree); IHistogram1D h1d = hf.createHistogram1D("test 1d",50,-3,3); IHistogram2D h2d = hf.createHistogram2D("test 2d",50,-3,3,50,-3,3); Random r = new Random(); for (int i=0; i<10000; i++) { h1d.fill(r.nextGaussian()); h2d.fill(r.nextGaussian(),r.nextGaussian()); } tree.commit(); } }
In this case we are creating a compressed XML file. The precise types of files or databases which can be used will depend on which implementation of AIDA you are using, however all AIDA implementations should support reading and writing XML files to allow easy interchange of objects. The next example shows how to read an XML file back in.
import hep.aida.*; import java.util.Random; import java.io.IOException; public class Restore { public static void main(String[] argv) throws IOException { IAnalysisFactory af = IAnalysisFactory.create(); ITree tree = af.createTreeFactory().create("myFile.aida","xml"); IHistogram1D h1d = (IHistogram1D) tree.find("test 1d"); IHistogram2D h2d = (IHistogram2D) tree.find("test 2d"); IPlotter plotter = af.createPlotterFactory().create("Test"); plotter.createRegions(2,1); plotter.region(0).plot(h1d); plotter.region(1).plot(h2d); plotter.show(); } }
In designing the ITree interface we have borrowed some other concepts from Unix. In particular ITree's allow other ITree's to be mounted and unmounted at an arbitrary point in the tree. This allows a whole set of files to be opened but be viewed by the AIDA user as a single ITree. ITree's also support symbolic links.
Table of Contents -- Next Section