TProcessLine problem with scope

Hello Rooters!

I have the following code fragment that runs within a loop. I need to use the ProcessLine commands primarily because I call the “check_draw” script, which is built by a previous stage of the program. I have found that the only way I can get the sequence of commands to work is to use the ProcessLine for all of them.

      gROOT->ProcessLine("TFile s_f(\"sim_nt.root\")");
      gROOT->ProcessLine("s_tree = (TTree *) s_f.Get(\"h2\")");
      gROOT->ProcessLine(".L check_draw.C");
      found_sim = gROOT->ProcessLineFast("check_draw()");

It is inefficient to constantly create and destroy the tree within the loop, not to mention the TFile as well. I would like to create them at the beginning of the program. However, if I try to do such a thing, I get a scope error b/c “check_draw” calls s_tree->Draw(…). Is there a way around this?

Sorry in advance if my explanation came out a little convoluted. Any help, as always, is greatly appreciated.


You just have to use:gROOT->ProcessLine(Form("TTree *s_tree = (TTree*)0x%x;",s_tree);where s_tree is your local variable/datamember.


“s_tree->Delete()”. Do not use the Delete member function unless you have a good reason to. You probably meant to use delete s_tree;