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 :
install Fastjet
update my system variables so that any program shoud be able to find the libraries :
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]
root [3] .include
Any information in how to tell ROOT where are the libraries I want him to be able to use ?
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() #--------------------------------------------------------------------------
[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 ?
[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.
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 .
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.
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.
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).
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
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 #ifndefCINT macro guard).
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 #ifndefCINT 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.
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.