CINT Shortcuts
CINT is the C INTerpreter, the tool that takes C++ macros and processes them.
When you are typing in commands or playing macros, it is CINT that is
processing them.
C++ has a strict, and unforgiving syntax and does not make a good macro
language. So CINT relaxes a number of rules as, with the help of the ROOT,
it knows a lot more about the program than any C++ compiler
ever could. For example it knows the name of every object, so if a user refers to
an object without first declaring it, it can go and locate it. This all
helps to make using the system easier, but it comes at a price: using these shortcuts
won't work when writing C++ programs. So, although it is fine to use them, its
important to understand what they are before taking the next step of writing
compilable code.
Here are the extensions (if you don't understand what follows then you are not
ready to write C++ code):-
- When creating new objects on the
heap
the object type may be omitted, i.e.:-
TFile* f = new TFile("hsimple.root")
may be written without declaring the leading TFile:-
f = new TFile("hsimple.root")
Frankly this is not much of a saving, and it is hardly worth acquiring
a bad habit for the time it saves.
- For objects created on the heap, as in the above example, the pointer
may be treated as if it were actually the object, i.e. instead of writing e.g.:-
f->ls();
it is O.K. to write:-
f.ls();
As with the previous extension, this shortcut is not worth the price.
- If a variable is used without first being declared, CINT will ask ROOT
to see if it can find an object whose name exactly matches the variable name.
For example, in MINFAST, there is a
global
pointer called revt which is pointer to the REROOT_Event object from which
all information about the current event can be located. If a macro refers
to revt, without first declaring it, CINT will locate it.
This is both a natural and powerful extension for a macro language
and its use is recommended
for global variables. When it comes time to write real code, then it will
be necessary to pass the object as a member function argument or
include an extern statement, e.g.:-
extern REROOT_Event revt;
- In a similar way, CINT knows about ROOT classes, so there is no need to
include ROOT
header files
before using its classes. This shortcut does save a bit of time and the
headers have sensible names, for example, when writing code to access
objects of the TClonesArray class, include:-
#include "TClonesArray.h"
so this shortcut is worth using.
- Each time a carriage return is pressed all displays are updated.
This is done by sending
TCanvas
objects their Update message. This shortcut is both unavoidable and
useful, but user code must update TCanvas objects explicity.
- Also a carriage return will signal the end of a C++ statement which means
that the trailing ';' can be omitted. Omitting ; when compiling C++ code can
lead to very confusing error messages - don't do it!
- CINT interprets ** as exponetiation i.e. like FORTRAN, sady there is no
exponetiation opeator in C++, the math.h functions exp and log have to be used.
Try to avoid the temptation.
-
Stack
objects don't go out of scope (and hence don't get deleted, when control leaves the
compound statement
in which the are declared. In C++, the following is futile:-
{ Int_t num = 3; }
as num disappears as soon as control passes the trailing }. CINT does
not deleted objects like that. Instead to clear the stack the command:-
gROOT->Reset();
has to be given.
Where CINT shortcuts are employed in the example macros, their use will be
noted in this section.
Go Back to the
The Example Macros Top Page
If you have any comments about this page please send them to
Nick West