the CINT interpreter Interface: ------------------------------- CINT = command line interpreter as well as macro processor embedded in ROOT macros = are "small" (up to at least 60000 loc) C++ programs - to execute any of the CINT commands within ROOT they need to be preceded by a . (dot) "?" command = get a list of all available interpreter commands - the ROOT command line interface supports emacs style command line editing - the command history is saved between sessions A MULTI-LINE COMMAND: - starts always with a "{" and ends with a "}" - in multi line input mode you are prompted with "end with '}'>" - after typing the closing "}" the command will be executed - you have to terminate every line, like in C++, with a ";" - requires typing without making any errors. There is no way to correct a once entered line - it is much easier to put such a sequence of commands in a macro file CINT AS MACRO PROCESSOR: - CINT macro files contain pure C++ code - they can contain a simple sequence of statements, but also arbitrarily complex class and function definitions - a macro containing a simple list of statements must start with a "{" and end with a "}" - to execute the stream of statements in macro1.C do root[0] .x macro1.C // loads the contents of file macro1.C and // executes all statements in the global scope - one can re-execute the statements by re-issueing ".x macro1.C" - the macro macro2.C containing a function statement does not require surrounding "{" and "}" - to execute function main() in macro2.C do root[0] .L macro2.C // load the contents of file macro2.C in memory root[1] main() // execute entry point main() - optional: root[2] main() // execute main() again root[3] .func // list all functions known by CINT - in the macro macro3.C is the function name changed from main() to macro3(int j = 10) - to execute macro3() in macro3.C type: root[1] .x macro3.C(8) // loads the contents of file macro3.C and // executes entry point macro3(8) - the above only works when the filename (minus extension) and function entry point are both the same - macro3() can still be executed multiple times: root[2] macro3() root[3] macro3(33) A MACRO CONTAINING A CLASS DEFINITION: - you can define new classes in a macro - a class defined in a macro cannot derive from a compiled class - it can have members that are compiled classes - to execute macro4.C do: root[0] .L macro4.C root[1] MyClass *a = new Child root[2] a.Print() RESETING THE INTERPRETER ENVIRONMENT: - there are basically two way to reset the environment: root[1] .reset // clears the complete interpreter environment root[2] gROOT.Reset() // clears the environment to the status just before executing the last macro - multi command line macros often start with the statement gROOT.Reset() DEBUGGING MACROS: - possible, see http://root.cern.ch/root/CintInterpreter.html ROOT/CINT EXTENSIONS TO C++: - three of the most important extensions ROOT/CINT makes to C++: root[1] f = new TFile("hsimple.root") - the declaration of "f" may be omitted when "new" is used root[2] f.ls() - although "f" is a pointer to "TFile" we don't have to use the pointer dereferencing syntax "->" but can use the simple "." notation root[3] hpx.Draw() - in case CINT can not find an object being referenced it will ask ROOT to search for an object with an identical name in the search path defined by TROOT::FindObject(). If ROOT finds the object it returns CINT a pointer to this object and a pointer to its class definition and CINT will execute the requested member function - This shortcut is quite natural for an interactive system and saves a lot of typing, e.g.: root[4] TH1 *hpx = (TH1*)gROOT.FindObject("hpx") root[5] hpx.Draw() Of course when writing large macros, it is best to stay away from these shortcuts since otherwise you will later have problems compiling your macros using a real C++ compiler.