TMapFile in pyROOT

Hi,
I’d like to read .map shared memory files in my pyROOT script. However, if I try to call TMapFile.Create(‘file.map’), I get the following error message:

Error in TMapFile::TMapFile: no memory mapped file capability available
Use rootn.exe or link application against “-lNew”

Well, if it was in an app or within root, I would do what it says, but what am I supposed to do in a python script? Is there a possibility to use TMapFile from within pyROOT? Should I load some additional library (but how?) in the script? I need it badly, bc I want to be able to read constantly updated histograms from a mapfile that contains data from online monitoring in my experiment. And from what I know, simultaneous read and write operations are only supported by TMapFiles.

Any advice will be helpful!
best regards,
pawel.

Hi,

You could load libNew into python, e.g. using ctypes.CDLL(), before importing PyROOT and before creating the TMapFile. Does that help?

Cheers, Axel.

That doesn’t seem to change anything:( The code is as follows:

import ROOT
from ctypes import *
libNew = CDLL("libNew.so") #I added this line following your advice
from ROOT import TFile, TH1F, TH1D, TMapFile

f = TMapFile.Create('backend/histograms.map');
hist = f.Get('trig_t2_2h');
histname = hist.GetName()

What I get is:

Error in <TMapFile::TMapFile>: no memory mapped file capability available
Use rootn.exe or link application against "-lNew"
Traceback (most recent call last):
  File "root1.py", line 19, in <module>
    histname = hist.GetName()
ReferenceError: attempt to access a null-pointer

Any further ideas? Maybe I should somehow reference the TMapFile type using ctypes? But I don’t know how.

Cheers,
Pawel.

Hi Pawel,
I’ll see tomorrow how we can convince Python to make libNew available.
Axel.

An update: this works for me:

$ LD_PRELOAD=$ROOTSYS/lib/libNew.so python
>>> from ROOT import TFile, TH1F, TH1D, TMapFile
>>> f = TMapFile.Create('histograms.map', 'RECREATE');

This doesn’t:

$ python
>>> from ctypes import *
>>> libNew = CDLL("libNew.so") #I added this line following your advice
>>> from ROOT import TFile, TH1F, TH1D, TMapFile
Fatal in <operator delete>: storage area overwritten
aborting

I’m trying to find out what’s going wrong and how to fix that.

Axel.

Hi Axel,
thanks a lot for trying to help!
Just to clarify:

$ LD_PRELOAD=$ROOTSYS/lib/libNew.so python

means you set LD_PRELOAD environment variable to “$ROOTSYS/lib/libNew.so” and then run the script? Hm, I tried that (I’m using ROOT 5.34/36 on a Mac) but it didn’t work in my case… (nothing’s changed , error message is the same).

Cheers,
pawel.

Hi,

Right, Macs forbid LD_PRELOAD AFAIR…

Looks like TMapFile and Python on MacOS is a no-go :-/

Axel.

If using CDLL, make sure to add ctypes.RTLD_GLOBAL as a second argument, and note that it does not respect LD_LIBRARY_PATH on Linux (only on Mac; is/was disagreement among the developers).

You’re using ROOT anyway, so go with: ROOT.gSystem.Load("libNew").