Load, Unload, and Reload Root macros automatically?

Hello, I have a problem when loading and reloading “*.C” macros in root.
I’m using root version 5.10/00.
It’s a general reloading problem, so I’m using a general Macro name.
Heres’s the beginning of my root script “fill_l1.C”:

[code]int fill_l1(TString mode, TString cut = “”, TString action=“his”)
{
gROOT->LoadMacro(“ksphig_l1.C”);
gROOT->LoadMacro(“ksphig_cut.C”);

//… my code then starts … …
}
[/code]

When I run the script using  `.x fill_l1.C("blabla")' for the first time,

it runs well. But when I run again using `.x fill_l1.C(“other_option”)’ , the
CINT reports:

Function fill_l1() busy. loaded after "/a05home/lijin/WORK/ana/dotC/ksphig_l1.C" Error: G__unloadfile() Can not unload "/a05home/lijin/WORK/ana/dotC/ksphig_l1.C" , file busy /a05home/lijin/WORK/ana/dotC/fill_l1.C:5: *** Interpreter error recovered *** Function fill_l1() busy. loaded after "/a05home/lijin/WORK/ana/dotC/ksphig_l1.C" Error: G__unloadfile() Can not unload "/a05home/lijin/WORK/ana/dotC/ksphig_l1.C" , file busy /a05home/lijin/WORK/ana/dotC/fill_l1.C:6: *** Interpreter error recovered ***

It seems CINT can’t reload the script “ksphig_l1.C” automatically,
and any changes I made to “ksphig_l1.C” later will not be in effect.
I can only quit root, and restart root to re-run the main “fill_l1.C”.
Or I can type `.L ksphig_l1.C’ explicitly, in this case, the above error
message still remains.
The reason that I use “gROOT->LoadMacro(…)” in a script is that I
don’t want to type many “.L xxxx.C” before executing my main script. And the
files “*.C” to load will depend on my options passed to my main script, as
I have the following-alike code in my main script:

[code] //…
gROOT->LoadMacro(“option_general.C”);
if (!strcmp(action,“opt1”))
{ gROOT->LoadMacro(“option1.C”);
gROOT->LoadMacro(“option1_dependent.C”);
}
else if (!strcmp(action,“opt2”))
{ gROOT->LoadMacro(“option2_dependent.C”); }
//…

[/code]

Any way to let CINT automatically reload my scripts, and avoild the above
error messages? Thanks.

Hi,

Could you provide a running example showing this problem so that I can investigate (my attempts to reproduce the problem failed)?

Thanks,
Philippe

Hi, I attached a very simple example code to illustrate the problem. In the attachment “root_report.tar.gz”, there are four files:

  mainproj.C  option1.h option1.C option2.C
 This is the run output:

[code] *******************************************

  •                                     *
    
  •    W E L C O M E  to  R O O T       *
    
  •                                     *
    
  • Version 5.11/02 19 April 2006 *
  •                                     *
    
  • You are welcome to visit our Web site *
  •      http://root.cern.ch            *
    
  •                                     *
    

Compiled on 6 July 2006 for linux with thread support.

CINT/ROOT C/C++ Interpreter version 5.16.11, April 14, 2006
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] .x mainproj.C()
this is option1 : 1
this is option2.
root [1] .x mainproj.C()
Function mainproj() busy. loaded after “/sdisk1/lijin/WORK/ana/dotC/root_report
/./option1.C”
Error: G__unloadfile() Can not unload “/sdisk1/lijin/WORK/ana/dotC/root_report/
./option1.C”, file busy mainproj.C:2:
*** Interpreter error recovered ***
this is option1 : 1
this is option2.
root [2]
[/code]

Here’s the contents of the files:
mainproj.C:

void mainproj(){ gROOT->LoadMacro("option1.C"); gROOT->LoadMacro("option2.C"); option1(); option2(); }
option1.h

const int num = 1;

option1.C:

[code]#include “option1.h”

void option1(){
cout<< " this is option1 : "<<num<<endl;
}
[/code]
option2.C:

void option2(){
  cout<< " this is option2."<<endl;
}

If I remove the “include option1.h” in “option1.C”, then the error message does not appear and I can edit “option1.C” to be reloaded. It seems the “include” statement can’t automatically be reloaded.
root_report.tar.gz (476 Bytes)

Hi,

To achieve the result you want use the following construct (it even has the advantage that it will work in compile code :slight_smile: ).

#include "option1.C" #include "option2.C" void mainproj() { option1(); option2(); }

Cheers,
Philippe.