Self-compiling macro

I’m trying to come up with a way to have a self-compiling macro. In other words, I’m looking for the moral equivalent of

#include <iostream>
#include "TSystem.h"

using namespace std;

void loadTest (const char prefix[] = "")
   cout << "Hi " << prefix <<endl>ProcessLine (".L loadTest.C+");
   gROOT->ProcessLine ("other()");

void other()
   cout << "hello" << endl;

If I try this, I get (not surprisingly) complaints that the file is busy.

Processing loadTest.C...
Warning in <ACLiC>: script has already been loaded in interpreted mode
Warning in <ACLiC>: unloading /mnt/autofs/cdf/home/cplager/analysis/pdf2/topToPdfWeights/pdfweights/./loadTest.C and compiling it
Function loadTest() busy. loaded after "/mnt/autofs/cdf/home/cplager/analysis/pdf2/topToPdfWeights/pdfweights/./loadTest.C"
Error: G__unloadfile() Can not unload "/mnt/autofs/cdf/home/cplager/analysis/pdf2/topToPdfWeights/pdfweights/./loadTest.C", file busy  FILE:loadTest.C LINE:12
*** Interpreter error recovered ***

I’m trying this in Root 4.00.08 and above. Is this possible?


p.s. Is there a way to get the full name of the file in the macro? I.e.,


OK, so it does work. But it needs one ugly hack, and we will fix this if we remember this issue (we == Philippe :-). If you see a TAclic showing up in ROOT, and it doesn’t have a flag “IgnoreBusy”, then please remind us.

There is one important caveat: do not create a function that is visible in both compiled and interpreted mode, or CINT’s dictionary will get utterly confused, especially after unloading either the script or the library. You have been warned :slight_smile:

The macro is attached; I hope it has a sufficient amount of comments.

Cheers, Axel.
autobuild.C (2.45 KB)

Boy, that is ugly! :smiley: :smiley: :smiley:

I’ll try it in a bit to see if it works for me.

Thank you for the effort. It is most appreciated :smiley: :smiley: :smiley:

(I can’t stop smiling after reading that code).

Hi Charles,

just to clarify: this is ugly because I’m hacking CINT’s perfectly reasonable protection not to load a file twice. CINT’s dictionary relies on functions being unique per process. Still, the future TAclic should probably allow users to disable this check, in some half-hidden way.

Cheers, Axel.

It works beautifully! :smiley: