A ROOT script called from inside compiled code

Hi. I have a ROOT script – let’s call it myscript.C – which I run interactively from CINT. It contains the following lines:

      gROOT->Macro("cut.C"); //load a graphical cut file
      TCutG *mycut=(TCutG*)cutg->Clone("mycut"); //clone it, and delete it immediately
      delete cutg;

The object cutg as you probably guessed is created by cut.C:

   TCutG *cutg = new TCutG("cut0",33);

Now, I would like to compile myscript.C and run it as a stand-alone executable. I set up main(), all the #include lines and all that…however, when I try to compile it the compiler (understandably) complains about cutg being undefined. The trouble is that cutg is dynamically created by cutg.C…

I still would like to retain the ability to read in cutg.C by the (new) compiled code. I am really not sure how to do that (other than use an ugly solution involving parsing cutg.C into a table). Any ideas? Any insight would be much appreciated!!


in your outer code (the one you want to compile) you instead write

TCutG* cutg = (TCutG*) gROOT->GetListOfSpecials()->FindObject("cut0");
TCutG *mycut=(TCutG*)cutg->Clone("mycut"); //clone it, and delete it immediately
delete cutg;

Cheers, Axel.

Axel, thanks a gazillion! Works like a charm!