.! cd not working, ROOT syntax

Dear ROOT Talk,

when I try .! cd to another directory nothing happens. Is this normal? I have ROOT 5.08 on both Mac OS X Tiger 10.4.4 and Suse 10 and it doesn’t work with either.

I am newbie to this… What is the difference between

TH1F *h1 = new TH1F(“h1”, “Histogram”, 100, -4, 4)

TH1F h1(“h1”, “Histogram”, 100, -4, 4)

I understand that the first creates a pointer - does the second one as well? According to “A root Cheat Sheet” by Stephen Beach the later is just a syntax shortcut provided by CINT.

Thanks :slight_smile:

The unix command “cd” works for the current shell only. You have the same effect if you run the “cd” command inside a script shell. For instance, try to create a little file in which you change directory using “cd” , execute it the as a shell script (with the “sh” command), then type “pwd”. You will see that the directory has not changed. It was changed only during the script execution. That’s the same in ROOT.

TH1F *h1 = new TH1F(“h1”, “Histogram”, 100, -4, 4) creates a pointer to a TH1F object. You acess the the methods using “->”

TH1F h1(“h1”, “Histogram”, 100, -4, 4) creates an object TH1F (not a pointer). You access the methods using “.” . This in valid C++, this is not CINT shortcut.

You’d better read some C++ book to understand difference between first and second statements. Very primitive explanation is :
In the first statement you declare and initialize a pointer, its initializer is a new-expression.
This new-expression works in several steps :
operator new called (in our case it’s an overloaded operator new) - to allocate dynamic memory for object of type TH1F. After that, constructor for TH1F called with your parameters to initialize new object, address of this new object will be initial value for your pointer.

In second - you declare (and define an object). Implementation allocates memory for it (on stack or somewhere else for object with static storage duration) and call ctor.

Thanks for the explanations.

I had figured out the difference between the two statements yesterday - it partially confused me that CINT allowed you to dereference a pointer with “.”

[quote=“rootmonkey”]

I had figured out the difference between the two statements yesterday - it partially confused me that CINT allowed you to dereference a pointer with “.”[/quote]

Yes, this is really confusing - it’s not a C++, it’s the CINT’s C++ dialect :slight_smile:
IMHO it’s better to avoid such ill-formed (for C++) constructs in your code, not to have problems in future.

[quote=“rootmonkey”]Dear ROOT Talk,

when I try .! cd to another directory nothing happens. Is this normal? I have ROOT 5.08 on both Mac OS X Tiger 10.4.4 and Suse 10 and it doesn’t work with either.
Thanks :slight_smile:[/quote]

Probably you should use the C++ method

instead
( See: root.cern.ch/root/htmldoc//TSyst … eDirectory )

See $ROOTSYS/tutorials/rootalias.C macro for examples.
root.cern.ch/viewcvs/tutorials/r … cvs-markup