How to call external libraries

Dir sir,

In ROOT command line, you are in an environment which allow you to compile and execute any program which calls any classes of ROOT. Correct ? You just have to add the correct “#include <classe.h>” in the beginning of the code. It works because the ROOT environnement “knows” where to find in the system the corresponding ROOT libraries.

Now, my point is how to allow the call to external classes such as that of FASTJET from within ROOT code ? What I have done is :

  1. install Fastjet

  2. update my system variables so that any program shoud be able to find the libraries :

    DYLD_LIBRARY_PATH=/usr/OpenMotif/lib:/usr/local/root/lib:/cern/fastjet-install/lib:
    LD_LIBRARY_PATH=/usr/local/root/include:/usr/local/root/lib:/cern/LEDA-6.2-free-FC8_686x64-g+±4.1.2-mt:/usr/local/boost/lib:/usr/OpenMotif/lib:/cern/fastjet-install/include:/cern/fastjet-install/lib:/usr/local/gcc-4.5.1/gcc:
    PATH=/usr/local/root/bin:/cern/LEDA-6.2-free-FC8_686x64-g+±4.1.2-mt/Manual/cmd:/cern/fastjet-install/bin:/usr/local/gcc-4.5.1/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/cern/root:/cern/root/bin:/cern/fastjet-install:/cern/fastjet-install/bin:/usr/texbin:/usr/X11/bin

  3. Re-compile ROOT

What I have got :

a) g++ short-example.cc -o short-example -I/cern/fastjet-2.4.2/../fastjet-install/include -Wl,-rpath,/cern/fastjet-2.4.2/../fastjet-install/lib -lm -L/cern/fastjet-2.4.2/../fastjet-install/lib -lfastjet
=> Working fine

b) root [2] .L short_example.cc++
=> Not working, with the following log message :

[quote]Undefined symbols:
“fastjet::ClusterSequence::~ClusterSequence()”, referenced from:
_main in short_example_cc_ACLiC_dict.o
_main in short_example_cc_ACLiC_dict.o
"fastjet::PseudoJet::PseudoJet(double, double, double, double)", referenced from:
_main in short_example_cc_ACLiC_dict.o
_main in short_example_cc_ACLiC_dict.o
(…)
ld: symbol(s) not found
collect2: ld returned 1 exit status
*** Interpreter error recovered ***[/quote]

Any information in how to tell ROOT where are the libraries I want him to be able to use ?

Regards.

before doing

root [2] .L short_example.cc++ do

root[1] gSystem->Load("xx/yy/libfastjet"); //ie dynamically link your fastjet library
Rene

Hi René,

Thanks to you because it works now ! Just in case :

FASTJET is generating extensions such as:

[ul]".la" (to be used by “libtool” I suppose ?)[/ul]
[ul]".a"[/ul]
[ul]".dylib" (“dynamic libraries” free ones equivalent to “.dll” ?)[/ul]
while the ROOT function 'gSystem->Load()" is expecting the following ones:

[ul]".so"[/ul]
[ul]".sl"[/ul]
[ul]".dl"[/ul]
[ul]".a"[/ul]
[ul]".dll"[/ul]
As a result of the following command…

…I was getting the following error message :

[quote]dlopen error: dlopen(/cern/fastjet-install/lib/libfastjet.a, 9): no suitable image found. Did find:
/cern/fastjet-install/lib/libfastjet.a: unknown file type, first eight bytes: 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A
Load Error: Failed to load Dynamic link library /cern/fastjet-install/lib/libfastjet.a
(int)(-1)
*** Interpreter error recovered ***[/quote]
So, in order to use the dynamic libraries generated by FASTJET which extensions are not “.so” or “.dll”, I have add a symlink in FASTJET library directory like this :

That allowed me to use successfuly the following command in ROOT :

root [0] gSystem->Load("/cern/fastjet-install/lib/libfastjet.so") (int)0
and then to compile my “short_example.cc” code inside ROOT :

[code]root [1] .L /cern/ana/short-example.cc++
Info in TUnixSystem::ACLiC: creating shared library /cern/ana/short-example_cc.so
root [2] main()
#--------------------------------------------------------------------------

FastJet release 2.4.2

Written by M. Cacciari, G.P. Salam and G. Soyez

http://www.fastjet.fr

Longitudinally invariant Kt, anti-Kt, and inclusive Cambridge/Aachen

clustering using fast geometric algorithms, with area measures and optional

external jet-finder plugins.

Please cite Phys. Lett. B641 (2006) [hep-ph/0512210] if you use this code.

This package uses T.Chan’s closest pair algorithm, Proc.13th ACM-SIAM

Symp. Discr. Alg, p.472 (2002), S.Fortune’s Voronoi algorithm and code .

#-------------------------------------------------------------------------
pt y phi
jet 0: 100 0 3.14159
jet 1: 100 0 0
(int)0
[/code]
So Thx and hope this help.

2 things to do now for me :

[ul]1) Include this call to “gSystem->Load()” in my code or make a script that includes the ROOT command lines “gSystem->Load()” & “.L short_example.cc++” & any other command lines…[/ul]
[ul]2) Find a way to call more than one library at a time. I mean loading a directory containing the libraries instead of loading a particular library.[/ul]

By the way, do configuration files exist in ROOT which could set where libraries or include files should be searched by ROOT at run time ?

#-o

[quote]do configuration files exist in ROOT which could set where libraries should be searched by ROOT at run time?[/quote]Simply use LD_LIBRARY_PATH to inform ROOT (and DYLD_LIBRARY_PATH on MacOS).

[quote]do configuration files exist in ROOT which could set where include files should be searched by ROOT at run time ?[/quote]You can set ACLiC.IncludePaths in a .rootrc file. You can call gSystem->AddIncludePath in a script, for example in rootlogon.C. You can also use the CINT command .include.

Cheers,
Philippe.

Hello,

I’m trying to have FastJet working with ROOT. Despite the explanations given in this threat I didn’t manage…
Could you summarise what I need to do?

Many thanks,

Mathieu

Hi,

Something like: gSystem->Load("/cern/fastjet-install/lib/libfastjet.so"); gSystem->AddIncludePath("/cern/fastjet-install/include"); .L /cern/ana/short-example.cc+

Philippe.

Thanks a lots it works now! I just had to change the name of the routine in the short-example.cc since apparently “main” was used for something else…

thanks again

mathieu

Dear All,

Despite following the discussion above (and in many other external library and fastjet discussions in root forum), I am not able to make fastjet work through my root macros. Can anybody help me in this please?

My code (in initial stage) is:

#include <vector>
#include <iostream.h>
#include <string>
#include "TString.h"


#ifdef __CINT__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclasses;
#pragma link C++ class fastjet::PseudoJet+;
#pragma link C++ class std::vector<fastjet::PseudoJet>+;

#endif

//---------------------------------------------------------------

void EFTdelphes2(const char *inputFile)
{
  gSystem->Load("libDelphes");
  gSystem->Load("~/Programs/fastjet-install/lib/libfastjet.so");
  gSystem->Load("~/Programs/fastjet-install/lib/libfastjettools.so");
  gSystem->AddIncludePath("~/Programs/fastjet-install/include");
 
  // Create chain of root trees
  TChain chain("Delphes");
  chain.Add(inputFile);
  
  // Create object of class ExRootTreeReader
  ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
  Long64_t numberOfEntries = treeReader->GetEntries();
  
  // Get pointers to branches used in this analysis
  TClonesArray *branchJet = treeReader->UseBranch("Jet");
    
  // Book histograms
  TH1 *histJetPT = new TH1F("jet_pt", "jet P_{T}", 25, 0.0, 1000.0);
    
   // Fastjet input
      vector <PseudoJet> sjets;
       
   	 // Loop over all events
  			for(Int_t entry = 0; entry < numberOfEntries; ++entry)
  			{
    		// Load selected branches with data from specified event
    		treeReader->ReadEntry(entry);
  
    			// If event contains at least 1 jet
    				if(branchJet->GetEntries() > 0)
    				{
      			// Take first jet
      			Jet *jet = (Jet*) branchJet->At(0);
      			
      			}
      			
  // Plot jet transverse momentum
      histJetPT->Fill(jet->PT);
      
  // Print jet transverse momentum
      cout << jet->PT << endl;
  }

  // Show resulting histograms
  histJetPT->Draw();
 }

With #pragma link C++ class fastjet::PseudoJet+; #pragma link C++ class std::vector<fastjet::PseudoJet>+; not commented, it gives an error:

Error: link requested for unknown class fastjet::PseudoJet examples/EFTdelphes2.C:16: *** Interpreter error recovered ***

With these lines commented it gives error as:

dlopen error: ~/Programs/fastjet-install/include: cannot open shared object file: No such file or directory Load Error: Failed to load Dynamic link library ~/Programs/fastjet-install/include Error: rootcint: failed to open /home/swasti/Programs/MG5_aMC_v2_0_1/Delphes/AutoDict_vector_PseudoJet__cxx_ACLiC_dict.h in ReplaceBundleInDict() /home/swasti/Programs/MG5_aMC_v2_0_1/Delphes/AutoDict_vector_PseudoJet__cxx_ACLiC_dict.cxx:17:55: fatal error: AutoDict_vector_PseudoJet__cxx_ACLiC_dict.h: No such file or directory #include "AutoDict_vector_PseudoJet__cxx_ACLiC_dict.h" ^ compilation terminated. g++: error: /home/swasti/Programs/MG5_aMC_v2_0_1/Delphes/AutoDict_vector_PseudoJet__cxx_ACLiC_dict.o: No such file or directory Error in <ACLiC>: Compilation failed! Error: class,struct,union or type PseudoJet not defined defalloc.h:137: *** Interpreter error recovered ***

If I include fastjet header files (like PseudoJet.hh) which I need to write my code as I will be using definitions defined in them, it cannot find the fastjet header files.

To mention, I have fastjet environment variable and libraries defined and it works well when used with other programs like Pythia8.

Kindly please help as my efforts have been fruitless so far [-o< .

Regards,
Swasti.

Hi,

[quote]Error: link requested for unknown class fastjet::PseudoJet examples/EFTdelphes2.C:16:
*** Interpreter error recovered ***[/quote]

You must put the pragma after the actual declaration and indeed they are necessary.

Cheers,
Philippe.

Thank you very much for your reply. I tried this but it still doesn’t work. Can I simply use fastjet header files using following lines in code:

#include "fastjet/PseudoJet.hh"  
#include "fastjet/ClusterSequence.hh"
#include "fastjet/Selector.hh"

gSystem->Load("~/Programs/fastjet-install/lib/libfastjet.so");
gSystem->Load("~/Programs/fastjet-install/lib/libfastjettools.so");
gSystem->AddIncludePath("~/Programs/fastjet-install/include");

Even if I make root access the header files somehow, it still shows an error (Using Fasjet Header Files in Root). I tried a lot of things but couldn’t make this work. #-o

Regards,
Swasti

How did it fail?

Philippe.

[quote=“pcanal”]Hi,

Something like: gSystem->Load("/cern/fastjet-install/lib/libfastjet.so"); gSystem->AddIncludePath("/cern/fastjet-install/include"); .L /cern/ana/short-example.cc+

Philippe.[/quote]

Hi,

I am doing this on Mac OS 10.8.5, root version 5.34/05. I make the fastjet, go into the fastjet-install/lib, make symbolic links i.e.

      fastjet-install/lib/libfastjet.so -> libfastjet.0.dylib

Then inside root
root [0] .include /Users/gerstein/fastjet/fastjet-install/include
root [1] int a = gSystem->Load(“fastjet-install/lib/libfastjet.so”); cout<<a<<"\n";
0
root [2] .L shortex.cc++
Info in TUnixSystem::ACLiC: creating shared library /Users/gerstein/fastjet/./shortex_cc.so
Error: Template class JetDefinition::operator not defined /Users/gerstein/fastjet/fastjet-install/include/fastjet/ClusterSequence.hh:993:
Warning: Error occurred during reading source files
Warning: Error occurred during dictionary source generation
!!!Removing /Users/gerstein/fastjet/shortex_cc_ACLiC_dict.cxx /Users/gerstein/fastjet/shortex_cc_ACLiC_dict.h !!!
Error: /Users/gerstein/root/bin/rootcint: error loading headers…
Error in : Dictionary generation failed!
Info in : Invoking compiler to check macro’s validity
/Users/gerstein/fastjet/./shortex.cc:35:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
1 warning generated.
Info in : The compiler has not found any problem with your macro.
Probably your macro uses something rootcint can’t parse.
Check root.cern.ch/viewvc/trunk/cint/doc/limitati.txt for Cint’s limitations.

any advice would be appreciated.

Hi,

What is the content of your file[quote]Error: Template class JetDefinition::operator not defined /Users/gerstein/fastjet/fastjet-install/include/fastjet/ClusterSequence.hh:993:[/quote]you are indeed likely hitting a CINT limitation (i.e. you might to give version 6 of ROOT a try, as it completely replaces CINT with a new interpreter based on clang).

Cheers,
Philippe.

[quote=“pcanal”]Hi,

What is the content of your file[quote]Error: Template class JetDefinition::operator not defined /Users/gerstein/fastjet/fastjet-install/include/fastjet/ClusterSequence.hh:993:[/quote]you are indeed likely hitting a CINT limitation (i.e. you might to give version 6 of ROOT a try, as it completely replaces CINT with a new interpreter based on clang).

Cheers,
Philippe.[/quote]

Hi Philippe,

I thought I avoid CINT if I compile my macro?
In any case, I posted all the details in the new thread here

thanks
Yuri

Hi Yuri,

When compiling with ACliC, the macro still goes through CINT as part of the dictionary generation step. However you can usually simply hide most of the offending code part (like your operator, behind #ifndef CINT macro guard).

Cheers,
Philippe.

[quote=“pcanal”]Hi Yuri,

When compiling with ACliC, the macro still goes through CINT as part of the dictionary generation step. However you can usually simply hide most of the offending code part (like your operator, behind #ifndef CINT macro guard).

Cheers,
Philippe.[/quote]

Hi Philippe,

this makes sense now. I also followed your reply to the other thread and things are working now.

many thanks.
Yuri

Hello,
I am just trying example file short_example.cc from the http://fastjet.fr/quickstart.html1 using the root analyser.
But something is going wrong.

root [0] gSystem->AddIncludePath("-I/home/bulgaa/fastjet-install/include")
root [1] gSystem->Load("/home/bulgaa/fastjet-install/lib/libfastjet.so")
(int) 0
root [2] .L short_example.cc++
Info in TUnixSystem::ACLiC: creating shared library /home/bulgaa/./short_example_cc.so
In file included from /home/bulgaa/./short_example.cc:1:0,
from /home/bulgaa/short_example_cc_ACLiC_dict.cxx:40:
/home/bulgaa/./fastjet/ClusterSequence.hh:372:44: warning: ‘template class std::auto_ptr’ is deprecated [-Wdeprecated-declarations]
inline void plugin_associate_extras(std::auto_ptr extras_in){
^
In file included from /usr/include/c++/5/bits/locale_conv.h:41:0,
from /usr/include/c++/5/locale:43,
from /usr/include/c++/5/iomanip:43,
from /home/bulgaa/Downloads/test_build/include/RWrap_libcpp_string_view.h:40,
from /home/bulgaa/Downloads/test_build/include/RStringView.h:26,
from /home/bulgaa/Downloads/test_build/include/TString.h:41,
from /home/bulgaa/Downloads/test_build/include/TNamed.h:29,
from /home/bulgaa/Downloads/test_build/include/TDictionary.h:45,
from /home/bulgaa/Downloads/test_build/include/TClass.h:25,
from /home/bulgaa/short_example_cc_ACLiC_dict.cxx:13:
/usr/include/c++/5/bits/unique_ptr.h:49:28: note: declared here
template class auto_ptr;
^
root [3] main()
Error in TApplication::TApplication: only one instance of TApplication allowed
| Welcome to ROOT 6.08/00 http://root.cern.ch |
| © 1995-2016, The ROOT Team |
| Built for linuxx8664gcc |

Can somebody help me?
Thanks in advance.