Running ROOT macro in python

Hello experts,

I haave only two simple questions:

  1. How to run ROOT macro from python?
  2. Hot to pass array of integers as input to the ROOT macro.

The intention is to measure speed of alghorithm written in ROOT, thus I don’t want to use nor pyROOT neither any fancy root-python core bindings. There has to be something simple when the macro is pre-compiled, correct?

Thanks, Tomas.

Hi Tomas,

if you do not want to use PyROOT I think you are left with bare Python and subprocess https://docs.python.org/2/library/subprocess.html, where the process you want to run is root -b -l -q myMacro.C.
For passing an array of integers in this situation, I am not sure how to proceed. If you choose not to use PyROOT but you still want to invoke a function in a ROOT macro, I think there is no solution, not even ctypes can help - but perhaps I do not understand the problem fully.

In any case, I think that the usage of PyROOT cannot pollute your measurement but again it depends on many factors, e.g. the time needed for your algorithm to run.

Cheers,
D

Thanks for help anyway. I decided to try pyROOT, but with that I have problem with remote access to the input file:

-bash-4.1$ python RemoteAccess.py 1
Error in TPSocket::Authenticate: could not load properly Root authentication plugin
Error in TNetFile::TNetFile: can’t open connection to rootd on host webdav.bfg.uni-freiburg.de at port 2880
Error in TNetFile::Create: server does not accept connection from this host: contact server administrator
Error in TNetFile::Create: failing on file https://webdav.bfg.uni-freiburg.de:2880/pnfs/bfg.uni-freiburg.de/data/atlasscratchdisk/rucio/user/tjavurek/d9/c7/ESS_DDM_test_tree.root

It looks like some problems with authentications. I tried both https and root protocol. For comprarison in ROOT:

root [1] #include "TFile.h"
root [2]
root [2] TFile f = TFile::Open(“root://sedoor1.bfg.uni-freiburg.de:1094//pnfs/bfg.uni-freiburg.de/data/atlasscratchdisk/rucio/user/tjavurek/d9/c7/ESS_DDM_test_tree.root”);
root [3] f->ls()
TNetXNGFile
* root://sedoor1.bfg.uni-freiburg.de//pnfs/bfg.uni-freiburg.de/data/atlasscratchdisk/rucio/user/tjavurek/d9/c7/ESS_DDM_test_tree.root
TNetXNGFile* root://sedoor1.bfg.uni-freiburg.de//pnfs/bfg.uni-freiburg.de/data/atlasscratchdisk/rucio/user/tjavurek/d9/c7/ESS_DDM_test_tree.root
KEY: TTree testTree;1 a Tree with fake data
root [4]

Kind regards, Tomas.

To put more details, in case of root protocol:

here I used f = TFIle(“xrootd:…”)
-bash-4.1$ python RemoteAccess.py 1
Error in TFile::TFile: file pnfs/bfg.uni-freiburg.de/data/atlasscratchdisk/rucio/user/tjavurek/d9/c7/ESS_DDM_test_tree.root does not exist

here I used f = TFIle.Open(“xrootd:…”)
-bash-4.1$ vim RemoteAccess.py
-bash-4.1$ python RemoteAccess.py 1
Error in TNetXNGFile::Open: [ERROR] Server responded with an error: [3010] Opening relative path ‘pnfs/bfg.uni-freiburg.de/data/atlasscratchdisk/rucio/user/tjavurek/d9/c7/ESS_DDM_test_tree.root’ is disallowed.

full path of file:
root://sedoor1.bfg.uni-freiburg.de:1094//pnfs/bfg.uni-freiburg.de/data/atlasscratchdisk/rucio/user/tjavurek/d9/c7/ESS_DDM_test_tree.root

and using TNetFile:

SysError in TUnixSystem::UnixRecv: recv (Connection reset by peer)
Error in TNetFile::TNetFile: can’t open connection to rootd on host sedoor1.bfg.uni-freiburg.de at port 1094
Error in TNetFile::Create: server does not accept connection from this host: contact server administrator
Error in TNetFile::Create: failing on file root://sedoor1.bfg.uni-freiburg.de///pnfs/bfg.uni-freiburg.de/data/atlasscratchdisk/rucio/user/tjavurek/d9/c7/ESS_DDM_test_tree.root

however, from sam lxplus machin access through ROOT is possible.

Discussion is continuing here:

https://sft.its.cern.ch/jira/browse/ROOT-8743

please feel free to comment here or there. I am happy for any suggestion.

Thanks, Tomas.

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