After running script, prevent root from deleting everything!

Hi,

I’m a new user of ROOT. How do I change my script so that when it’s finished I can still manipulate my TGraph objects and plot them. My script is called lvis_opt_mol_static.C

#include <iostream>
#include <iomanip>
#include <ctime>

void lvis_opt_mol_static()
{
......
}

Thanks

please look at the many examples in the ROOT tutorials.

Rene

I’ve tried the tutorials, but the behavior is the same. For example, I ran this tutorial http://root.cern.ch/root/html/tutorials/graphs/graph.C.html

root -l graph.C)

The graph was properly displayed. I then closed it and tried replotting using:

But I got an error saying the Symbol gr was not defined in this scope and thus it failed to evaluate it.
It seems my installation of root wipes out everything from memory as soon as the script is done…
I installed root 5.26/00c from source on Debian GNU/Linux (testing/squeeze) with gcc 4.4.4. Is there a configuration parameter I missed that could have caused this?

I talked to a friend who uses root and he said he had never had this behavior before. I’m using CINT legacy 5.17.00, and not the experimental one, should I be using the experimental one instead? Is it possible gcc 4.4.4 and root are having issues?

When I ran the configure script I had to disable xrootd. Could this be the problem?

I also checked gEnv and couldn’t find anything that related to this.

Please help! I don’t really know what to do

Thanks

TGraph *grkeep = 0;
void myscript() {
TGraph *gr_goaway = new TGraph(…);
grkeep = new TGraph(…);
}[/code]After the running the script (.x myscript.C), grkeep will be accessible but gr_goaway will not be available since it scope is limited to the function myscript. However since both graph very allocated with ‘new’ and neither was ‘deleted’, both are slight used up memory (even though you no longer have access to the one that used to be associated with gr_goaway.

Note that CINT is also trying to be helpful and if an object is attached to the current directory in ROOT, using its name even if you have not declared any variable pointing to it will succeed. Thus with void myhist() { TFile *f = new TFile("test.root","RECREATE"); // This file now becomes the current directory. TH1F *h = new TH1F("ahisto",....); // Histogram and TTree are attached automatically to the current directory. }if you type .x myhist.C ahisto->Draw();CINT will in reality execute:

.x myhist.C TH1F *ahisto = (TH1F*)gDirectory->Get"ahisto");

For mode details re-read your favorite C++ reference on variable scope and object lifetime and the User’s Guide chapter on object ownership (and also on CINT).

Cheers,
Philippe.

Oh…
I knew about C++ variable scope…I guess what I didn’t know was CINT respected it

Thanks

PS: feeling pretty dumb right now