1.2.2. ROOT interpreter and runtime compiler
Uranie can be used through the C++ interpreter of ROOT, either using the command line, or in batch mode, the successive commands being stored in a file called a ROOT macro.
To run the macro "MyMacro.C" from a shell prompt, use the command:
root -l MyMacro.C
The -l option prevents from launching the ROOT login window. Other options that may be useful
are:
-q: quit ROOT interpreter when the script is run.-b: run in batch mode (without DISPLAY)
These options are typically used when your job needs to be distributed.
To execute a Macro from the ROOT prompt, use the command:
.x MyMacro.C
ROOT interpreter offers some facilities for macro writing. In particular, it takes care of loading
the needed libraries, and does not need the #include directives.
WARNING WITH ROOT6: The new versions of ROOT (from ROOT 6.0) is now using Cling the interpreter that does also a compilation on the fly thanks to LLVM and Clang. It is now much more compliant with the C++ syntax that previous version, allowing only few simplifications (some namespace loaded and include lines brought).
Another way to run a macro in a compile way is to append one or two “+” at the end of the script.
root -l MyMacro.C+
A “+” compiles the macro if the source changes, while “++” forces a recompilation. From ROOT 6,
this method does not go faster that the “interpreted” one. The only difference remaining now is to
produce easily a library (.so) file.
This runtime compiler still deals with libraries auto-load, but needs the #include directives.
ROOT looks for include files in standard location and in the $ROOTSYS/include directory. If
Uranie is installed elsewhere, you have to specify where to find its include files.
One way to do so is to use the .rootrc file. Here is an example:
.rootrc
ACLiC.IncludePaths: -DJIT -I$URANIESYS/include -I/another/include/path
It defines a list of C++ compiler options that are added at compile time: -I adds an include path;
-D defines a CPP macro. This CPP macro can be used to write a single source code for both
interpreted or compiled runs, hiding or showing part of source lines (#include declarations for
example).
Another way is to use the rootlogon.C file. If this file is available in the active directory, it
will be systematically loaded by ROOT before the application is launched. A more thorough
discussion on this file can be found in Uranie namespace.
rootlogon.C
gInterpreter->AddIncludePath("$URANIESYS/include");
gInterpreter->AddIncludePath("/another/include/path");
This allows both the interpreter and the compiler to find the needed files.
One important advantage of runtime compilation is that error messages are more easily understandable.