if I run my macro with .x analysys.cxx, it works fine. When I try to compile it, ROOT fails to load the shared library.
I’ve searched over the internet and, as far as I’ve understood, I should modify my .rootrc configuration file, but I was not able to do it. Could someone help me finding an easy way to let ROOT load the librarary properly?
Thank you in advance.
Cheers,
Matteo
ROOT 5.34/30 (v5-34-30@v5-34-30, Apr 23 2015, 18:31:46 on linuxx8664gcc)
CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
and here is a minimal version of my macro which reproduces the error:
#include <TSystem.h>
#include <TLorentzVector.h>
#include <TMath.h>
#include <TChain.h>
#include <TFile.h>
#include <TClonesArray.h>
#include <iostream>
using namespace std;
void analisi(){
// Load shared library
gSystem->Load("/home/matteo/MG5_aMC_v2_2_3/ExRootAnalysis/libExRootAnalysis.so");
gSystem->Load("libPhysics");
// Create chain of root trees
TChain c_lhe("LHEF");
c_lhe.Add("lhe.root");
TChain c_hep("STDHEP");
c_hep.Add("hep.root");
Int_t Particle_size;
// Create object of class ExRootTreeReader
ExRootTreeReader *lheReader = new ExRootTreeReader(&c_lhe);
ExRootTreeReader *hepReader = new ExRootTreeReader(&c_hep);
Long64_t numberOfEntries = lheReader->GetEntries();
cout<<numberOfEntries<<" eventi"<<endl;
// Get pointers to branches used in this analysis
TClonesArray *branchParticle = lheReader->UseBranch("Particle");
TClonesArray *branchRwgt = lheReader->UseBranch("Rwgt");
TClonesArray *branchGenParticle = hepReader->UseBranch("GenParticle");
//array contenenti i pesi
Double_t w_cent, *w_scale, *w_pdf;
Int_t scale, pdf;
Int_t num_pdf;
scale=1;
pdf=1;
//determina il numero di variazioni
if (scale==1)
w_scale=new Double_t[8];
if (pdf==1){
if (scale==1){
lheReader->ReadEntry(0);
num_pdf=branchRwgt->GetEntries()-9;
w_pdf=new Double_t[num_pdf];
}
else{
lheReader->ReadEntry(0);
num_pdf=branchRwgt->GetEntries()-1;
w_pdf=new Double_t[num_pdf];
}
}
}
and here is the error output:
root [0] .x analisi.cxx+
Info in <TUnixSystem::ACLiC>: creating shared library /home/matteo/analysis_MG5/fraffaa/./analisi_cxx.so
In file included from /home/matteo/analysis_MG5/fraffaa/analisi_cxx_ACLiC_dict.h:34:0,
from /home/matteo/analysis_MG5/fraffaa/analisi_cxx_ACLiC_dict.cxx:17:
/home/matteo/analysis_MG5/fraffaa/./analisi.cxx: In function ‘void analisi()’:
/home/matteo/analysis_MG5/fraffaa/./analisi.cxx:26:3: error: ‘ExRootTreeReader’ was not declared in this scope
ExRootTreeReader *lheReader = new ExRootTreeReader(&c_lhe);
^
/home/matteo/analysis_MG5/fraffaa/./analisi.cxx:26:21: error: ‘lheReader’ was not declared in this scope
ExRootTreeReader *lheReader = new ExRootTreeReader(&c_lhe);
^
/home/matteo/analysis_MG5/fraffaa/./analisi.cxx:26:37: error: expected type-specifier before ‘ExRootTreeReader’
ExRootTreeReader *lheReader = new ExRootTreeReader(&c_lhe);
^
/home/matteo/analysis_MG5/fraffaa/./analisi.cxx:27:21: error: ‘hepReader’ was not declared in this scope
ExRootTreeReader *hepReader = new ExRootTreeReader(&c_hep);
^
/home/matteo/analysis_MG5/fraffaa/./analisi.cxx:27:37: error: expected type-specifier before ‘ExRootTreeReader’
ExRootTreeReader *hepReader = new ExRootTreeReader(&c_hep);
^
g++: error: /home/matteo/analysis_MG5/fraffaa/analisi_cxx_ACLiC_dict.o: File o directory non esistente
Error in <ACLiC>: Compilation failed!
Error: Function analisi() is not defined in current scope :0:
*** Interpreter error recovered ***
In the “current” subdirectory (in which you work), create a “rootlogon.C” file: {
std::cout << "... rootlogon.C ... loading libraries ..." << std::endl;
gSystem->Load("/home/matteo/MG5_aMC_v2_2_3/ExRootAnalysis/libExRootAnalysis.so");
gSystem->Load("libPhysics");
} and in your “analisi.cxx” file add an appropriate #include for the “ExRootTreeReader” class -> maybe something like: #include “ExRootTreeReader.h”
Instead of “#include absolute path” in your source code, add in the “rootlogon.C” something like:
gInterpreter->AddIncludePath("/full/path/to/all/your/ExRootAnalysis/includes/directory");
and then in your “analisi.cxx”, you can simply: #include “SomeIncludeFile.h”
Just for completeness … instead of:
gInterpreter->AddIncludePath("/some/directory");
you can also (note “-I” below):
gSystem->AddIncludePath("-I/some/directory");