Recompile plugin macro when source changes

Hi,
I have an interactive appli in which a user-supplied analysis class is
loaded using the plugin mechanism, i.e. I add dynamically a handler for the class like this:

gROOT->GetPluginManager()->AddHandler("BaseClassName", "UserClassName", "UserClassName", "UserClassName.cpp+", "UserClassName()");

then I check the compilation & (if it works) load it using

TPluginHandler* ph = (TPluginHandler*)gROOT->GetPluginManager()->FindHandler("BaseClassName", "UserClassName");
if( !ph->CheckPlugin() && !ph->LoadPlugin() ) {
   BaseClassName* obj =  (BaseClassName*)ph->ExecPlugin(0);
}

This basically happens when the user hits the “Process” button in
a GUI, in order to run her analysis.

The problem is that if, after a first successful compilation & load of the user’s code, the user then changes her code & hits “Process” again, the class is not recompiled, and the user unwittingly re-executes exactly the same analysis as before.

How can I make this happen ? I think I have found the way to make it recompile the code every time:

gSystem->Unload("UserClassName_cpp.so");
gROOT->GetPluginManager()->RemoveHandler("BaseClassName", "UserClassName");
TClass::RemoveClass(TClass::GetClass("UserClassName"));

but this is not what I want. How can I get it to recompile the code
only when the code changes ?

Cheers
John

John,

Simply use ACLIC

If the cpp file is not modified since the previous call, the corresponding shared lib will be dynamically linked, otherwise the file will be recompiled.

Rene

Dear Rene,

Thanks for the reply, of course if things were that simple I would do as you suggest! :smiley:
Unfortunately, for various reasons, I need to use plugins. Is there a way to get the same behaviour with a plugin ?

Thanks
John

Hi John,

[quote]
How can I make this happen ? I think I have found the way to make it recompile the code every time: [/quote]This is strange, given your code, I would expect the library to be recompiled only on demand (which your proposed work-around).

Can you provide me with a complete running example?

Thanks,
Philippe

Hi Philippe,

In fact, you’re absolutely right! :blush:
I attach a fully-functioning version of my code,
to use it do:

+L BaseClass.cpp+
+L GetInstanceOfUserClass.cpp+

Then to test it do:

TObject*obj=0
obj=GetInstanceOfUserClass("DerivedClass","BaseClass")
delete obj
obj=GetInstanceOfUserClass(...
etc. etc.

Only when one modifies DerivedClass.cpp is it recompiled.
It’s perfect!
Thanks a lot
Cheers
John
GetInstanceOfUserClass.cpp (3.82 KB)
DerivedClass.h (439 Bytes)
DerivedClass.cpp (693 Bytes)
BaseClass.h (399 Bytes)
BaseClass.cpp (590 Bytes)