Open ROOT file (BytesIO format)

Hello,

I am developping a webapp in python3 in which I upload a ROOT file to be analyzed. The uploaded file is an object that effectively is a subclass of BytesIO (I do not have control on that as it comes through a file-uploader widget from the webapp framework), but when I try to open the file I got the following error:

File "/Users/sevilla/cernbox/faser/preshowerapp/root_install/lib/ROOT/_pythonization/_tfile.py", line 100, in _TFileOpen
    f = klass._OriginalOpen(*args)
  File "/Users/sevilla/cernbox/faser/preshowerapp/root_install/lib/ROOT/_pythonization/_tfile.py", line 100, in _TFileOpen
    f = klass._OriginalOpen(*args)
  File "/Users/sevilla/cernbox/faser/preshowerapp/root_install/lib/ROOT/_pythonization/_tfile.py", line 100, in _TFileOpen
    f = klass._OriginalOpen(*args)
  [Previous line repeated 987 more times]
RecursionError: maximum recursion depth exceeded

I was wondering whether there’s a method to open that BytesIO-like file ?

Hi,

Interesting use case.
I am not sure the context here is enough to propose a solution. Could you post a standalone reproducer of the issue?

Cheers,
Danilo

The framework for the webapp is streamlit (https://docs.streamlit.io), and I am using its file uploader widget (st.file_uploader - Streamlit Docs). I’d just like analyze the ROOT file after uploading it (so at least, being able to open it).

Please find below a MWE based on virtual environment to setup a dummy app that includes the file uploader widget:

  1. login to lxplus9.cern.ch
  2. mkdir adir && cd adir
  3. python3 -m venv venv
  4. source venv/bin/activate
  5. source /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.30.04/x86_64-centosstream9-gcc113-opt/bin/thisroot.sh
  6. python -m pip install streamlit
  7. streamlit run mwe.py
  8. open a browser and point to the indicated url

I am also attaching the file mwe.py and a dummy ROOT file.

Many thanks for the help

file.root (3.7 KB)
mwe.py (171 Bytes)

Hi,

Thanks!
It seems still a bit elaborated for a reproducer: could you put us in condition from lxplus to reproduce the problem with a file and a few python lines? Using the LCG view is of course fine.

Cheers,
D

Well, I included a MWE with just few commands, I can’t imagine what else I can do as the streamlit framework is for developping webapps, so it has to run in a browser. There’s no ‘terminal-only’ or alike other possibilities… So I guess this path is a dead-end…

Thanks anyway…

Hi,

Not necessarily. Do you know what happens to the ROOT file, in what it is transformed for the upload?

Best,
D

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.