Re load macro in pyroot

Hi,

I have a macro, myMacro.C, and part of its code is generated from inside a python script.

When the macro is finally ready, I load that macro as well as another one:

gROOT.LoadMacro("myMacro.C+") gROOT.LoadMacro("myStudies.C+")

And I use the functions in the macros without any problem.

However, later on I change part of the code and try to load it again:

[code]applyCodeChangesToMacro(“myMacro.C”)
gSystem.Unload(“myStudies_C.so”)
gSystem.Unload(“myMacro_C.so”)
gROOT.Reset()

gROOT.LoadMacro(“myMacro.C+”)
gROOT.LoadMacro(“myStudies.C+”)[/code]

However, this seems to cause a segmentation violation which is hard to trace back:

"Thread 1 (Thread 0x2b35626dcc70 (LWP 14760)):
#0 0x00000033f4699def in waitpid () from /lib64/libc.so.6
#1 0x00000033f463c761 in do_system () from /lib64/libc.so.6
#2 0x00000033f463cab7 in system () from /lib64/libc.so.6
#3 0x00002b3564172af0 in TUnixSystem::StackTrace() () from /afs/naf.desy.de/group/cms/sw/slc5_amd64_gcc462/cms/cmssw-patch/CMSSW_5_3_3_patch2/external/slc5_amd64_gcc462/lib/libCore.so
#4 0x00002b3564175333 in TUnixSystem::DispatchSignals(ESignals) () from /afs/naf.desy.de/group/cms/sw/slc5_amd64_gcc462/cms/cmssw-patch/CMSSW_5_3_3_patch2/external/slc5_amd64_gcc462/lib/libCore.so
#5
#6 0x00002b3567422180 in METStudies(int, TString, TString, TString) () from /afs/naf.desy.de/user/e/eron/scratch/UserCode/RA4bHead/UserCode/DesySusy/ra4b_2012/./METStudies_C.so
#7 0x000000000211dc30 in ?? ()
#8 0x01012b3500000001 in ?? ()
#9 0x000000000000001a in ?? ()
#10 0x000000001dedb796 in ?? ()
#11 0x0000000000000001 in ?? ()
#12 0x0000b213000081e4 in ?? ()
#13 0x00000000000003f1 in ?? ()
#14 0x0000000000000001 in ?? ()
#15 0x00000000000036ec in ?? ()
#16 0x0000000000001000 in ?? ()
#17 0x000000000000001c in ?? ()
#18 0x0000000051b9cc1e in ?? ()
#19 0x0000000000000000 in ?? ()

"
At the end, I get:

Traceback (most recent call last):
File “METStudies.py”, line 464, in
METStudies(isData,file,‘same’,outFile)
SystemError: problem in C++; program state has been reset

Is there anything that I am doing obviously wrong in the macro re-loading operation?

Thanks a lot.

Hi,

the Unload() will not reset the python side functions that point to the (old) C++ code, so that is most likely the cause of the crash. The python side can be removed (“del ROOT.SomeFunc; del ROOT.ROOT.SomeFunc”), but for some reason the function on reload does not show up anymore in the list of global functions that gROOT maintains, so PyROOT can not find it a second time.

I don’t think this is going to work in a clean way. (Note that in python itself, reloading of extension modules is not even possible.)

Cheers,
Wim

Thanks for your help.

I think I will also change the macro from within python to change the macro name and the function name and load that instead. As you say, it’s far from clean.