Cannot import libDelphes when working in python


ROOT Version: 6.16/00
Platform: MacOS Mojave 10.14
Compiler: brew gcc


Dear ROOT experts,
I’m going mad in trying to use ExRootAnalysis and Delphes libraries in order to analyse Delphes .root outputs. I want to work in python because I already have some ready to go scripts in there for reading Delphes trees.

The problem is as follows.
I can import Delphes libraries while I’m in Delphes directory directly from root:

root [1] gSystem ->Load( "libDelphes.so")

(int) 1

Now I made a .py script to do the exact same in the exact same location inside Delphes directory:

import ROOT
ROOT.gSystem.Load("libDelphes.so")

And it crashes as follows:

Giacomos-MBP:Delphes bcoder$ python prova.py 
cling::DynamicLibraryManager::loadLibrary(): dlopen(/Users/bcoder/MG5_aMC_v2_6_6/Delphes/libDelphes.so, 9): Library not loaded: @rpath/libHist.so
  Referenced from: /Users/bcoder/MG5_aMC_v2_6_6/Delphes/libDelphes.so
  Reason: image not found

I tried anything and still I cannot load libraries.
I can load some single headers as follows:

ROOT.gInterpreter.Declare('#include "/Users/bcoder/MG5_aMC_v2_6_6/Delphes/classes/SortableObject.h"')
ROOT.gROOT.ProcessLine('.include .')
ROOT.gInterpreter.Declare('#include "/Users/bcoder/MG5_aMC_v2_6_6/Delphes/classes/DelphesClasses.h"')

But still I cannot acmes the tree because I do not even have ExRootLibraries.
My bash_profile is as follows:

#root
source /Users/bcoder/buildroot/bin/thisroot.sh

export ROOTSYS=/cern/root
export DYLD_LIBRARY_PATH=$ROOTSYS/lib:$DYLD_LIBRARY_PATH
export PATH=$ROOTSYS/bin:$PATH
export DYLD_LIBRARY_PATH=$ROOTSYS/lib/root:$DYLD_LIBRARY_PATH

#ExRootAnalysis
export ExRoot=$MADGRAPH5/ExRootAnalysis
export DYLD_LIBRARY_PATH=$ExRoot:$DYLD_LIBRARY_PATH

#Delphes
export Delphes=$MADGRAPH5/Delphes
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$Delphes

Help, what am I missing???
Cheers, Giacomo

If your python is /usr/bin/python, you may be affected by Mac OS X security features. Otherwise, you may have problems with your library install_names. Either way, the links below should help. Cheers,

Thank you really much Amadio,
Solved simply by installing brew’s python3 and recompile ROOT against it.

One more question, why do I have to import libDelphes two times in order for it to work? Also for ExRooTAnalysis (since it is in the external directory of my path to Delphes) .The first time I get errors, the second time I don’t.
Furthermore I cannot work for much time on the same project without it crashing and saying “Too many files open” from that point on I can no longer work and I have to restart the jury notebook (in a python script it just won’t work).
It’s just annoying because I can run a cell doing say 2h of computations and then I cannot save the results due to this problem. Would really appreciate your help.

Cheers, Giacomo

Without seeing the actual errors, I cannot know.

I guess the “too many files open” problem is a consequence of running in notebook form and never calling close on the files that are eventually opened.

From python console

 import ROOT

 ROOT.gSystem.Load("libDelphes.so")

0

 ROOT.gSystem.Load("libDelphes.so")

1

I guess the “too many files open” problem is a consequence of running in notebook form and never calling close on the files that are eventually opened.

But I have only one .root open, never had this problem before. I would close it but I need it for computations and still I need Delphes classes to access branches like particles of a jets and so on. Is this normal?

Does this also happen at the prompt or just when loading the library with Python?

also at prompt (sorry for the late reply). I cannot work on a python script because of this can only just work with Jupyter notebooks.

Giacomos-MacBook-Pro:Bonesini_qq_gg bcoder$ root -l
root [0] gSystem->Load("libDelphes")
Error in cling::AutoloadingVisitor::InsertIntoAutoloadingState:
   Missing FileEntry for ExRootAnalysis/ExRootTreeReader.h
   requested to autoload type ExRootTreeReader
Error in cling::AutoloadingVisitor::InsertIntoAutoloadingState:
   Missing FileEntry for ExRootAnalysis/ExRootTreeWriter.h
   requested to autoload type ExRootTreeWriter
Error in cling::AutoloadingVisitor::InsertIntoAutoloadingState:
   Missing FileEntry for ExRootAnalysis/ExRootTreeBranch.h
   requested to autoload type ExRootTreeBranch
Error in cling::AutoloadingVisitor::InsertIntoAutoloadingState:
   Missing FileEntry for ExRootAnalysis/ExRootResult.h
   requested to autoload type ExRootResult
Error in cling::AutoloadingVisitor::InsertIntoAutoloadingState:
   Missing FileEntry for ExRootAnalysis/ExRootClassifier.h
   requested to autoload type ExRootClassifier
Error in cling::AutoloadingVisitor::InsertIntoAutoloadingState:
   Missing FileEntry for ExRootAnalysis/ExRootFilter.h
   requested to autoload type ExRootFilter
Error in cling::AutoloadingVisitor::InsertIntoAutoloadingState:
   Missing FileEntry for ExRootAnalysis/ExRootProgressBar.h
   requested to autoload type ExRootProgressBar
Error in cling::AutoloadingVisitor::InsertIntoAutoloadingState:
   Missing FileEntry for ExRootAnalysis/ExRootConfReader.h
   requested to autoload type ExRootConfParam
Error in cling::AutoloadingVisitor::InsertIntoAutoloadingState:
   Missing FileEntry for ExRootAnalysis/ExRootConfReader.h
   requested to autoload type ExRootConfReader
Error in cling::AutoloadingVisitor::InsertIntoAutoloadingState:
   Missing FileEntry for ExRootAnalysis/ExRootTask.h
   requested to autoload type ExRootTask
(int) 0
root [1] gSystem->Load("libDelphes")
(int) 1

How did you install Delphes, and where are the headers? Can you #include <ExRootAnalysis/ExRootTreeReader.h> from the prompt without errors?

Delphes was installed through MadGraph so the headers are under MG5 folder:

/Users/bcoder/MG5_aMC_v2_6_6/Delphes

Also ExRootAnalysis was installed through Madgraph consolle and it is under the external folder of Delphes

/Users/bcoder/MG5_aMC_v2_6_6/Delphes/external/ExRootAnalysis

I cannot include it like this (outside MG5 folder):

root [1] #include <ExRootAnalysis/ExRootTreeReader.h>
ROOT_prompt_1:1:10: fatal error: 'ExRootAnalysis/ExRootTreeReader.h' file not found
#include <ExRootAnalysis/ExRootTreeReader.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

can only include specifying the full path to the header. Which is what I do In python and works:

root [6] #include </Users/bcoder/MG5_aMC_v2_6_6/ExRootAnalysis/ExRootAnalysis/ExRootTreeReader.h>
root [7] 

You should never include headers by full path, or your code will stop working when you move to another computer, etc. To make it possible to load the library and find the headers, I recommend setting the right variables (like LD_LIBRARY_PATH, ROOT_INCLUDE_PATH) so that cling/root can find them at runtime without needing to specify the full path. Cheers,

Yes I know including with full path is not the way to work.
Given the before said path to header I have the following in my bash_profile:

#ExRootAnalysis
export ExRoot=$MADGRAPH5/ExRootAnalysis
export PATH=$ExRoot:$PATH
export LD_LIBRARY_PATH=$ExRoot:$LD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=$ExRoot:$DYLD_LIBRARY_PATH
export ROOT_INCLUDE_PATH=$ExRoot

#Delphes
export Delphes=$MADGRAPH5/Delphes
export PATH=$Delphes:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$Delphes
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$Delphes
export ROOT_INCLUDE_PATH=$Delphes

Not an expert in this path thing so any comment is much appreciated. Should I give ExRoot the path in the external folder of Delphes in order for them to work together?

You probably need to append bin, lib, include, etc, to the variables above to make stuff work. Depends on the structure of files installed files under $ExRoot.

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