Loading compiled libraries into PyROOT

Hello,

I’m trying to use some compiled code in PyROOT. I compile it as standalone code, producing two .so files, and they work with other compiled C ROOT code, but I can’t yet figure out how to make it work in Python. Could someone point out what I’m doing wrong?

my simpleminded script:

from ROOT import gSystem
gSystem.Load(’/CalibrationDataInterfaceROOT_cxx’)
gSystem.Load(’/libBTagCalib’)

all fine to here

from ROOT import CalibrationDataInterfaceROOT

gives ImportError: cannot import name CalibrationDataInterfaceROOT

do I need to put “#pragma link” sorts of things into the C code?

Thanks!

Hi,

how did you compile the C++ code? Did you generate dictionaries for it? You say that you use it from C. For C, python has the ctypes module if need be.

Cheers,
Wim

Hi,

The code have two headers and two source files. From them, the standalone make command that the developers provide creates:
BTagCalib_Dict.h
BTagCalib_Dict.C
obj
libBTagCalib.so
obj/CalibrationDataInterfaceBase.o
obj/CalibrationDataInterfaceROOT.o
obj/BTagCalib_Dict.o
obj/dep/CalibrationDataInterfaceROOT.d
obj/dep/CalibrationDataInterfaceBase.d

The BTagCalib_Dict.h file has things like
extern G__linked_taginfo G__BTagCalib_DictLN_AnalysiscLcLCalibrationDataInterfaceROOT;
which I guess is the CalibrationDataInterfaceROOT that I’m trying to import.

I just gSystem.Load the libBTagCalib.so file. Do I need to add in the others as well?

Hi,

I would assume that the .so build from the _Dict.C file is linked against the original library, and that that is the library to load.

Cheers,
Wim

The code’s developer has explained to me how it’s to be done! What they do in their Python script is

import ROOT
ROOT.gSystem.Load(‘libBTagCalib’)
bjet_SF = ROOT.Analysis.CalibrationDataInterfaceROOT(‘SV0’, ‘EnvTestFile.env’)

Maybe that’s the syntax because CalibrationDataInterfaceROOT in in the Analysis namespace? I’m not sure. Anyway, it works for me now!