---+!! How to compile root Macros %TOC% ---++ Why compile with g++ and not CINT? CINT the root interpreter is dead slow and have seen a very noticeable increase in the execution time of my analysis code when compiled with g++ instead of root. ---++ Creating a script to do the compile the macro below is a script needed to compile the root macro, the first commands prints the subsequent commands, the second compiles your code and the third links the object file with the libraries needed to run root. <verbatim>#!/bin/bash set -x g++ -O2 -pipe -Wall -W -Woverloaded-virtual -fPIC -Iinclude -pthread \ -I $ROOTSYS/include -o $1.o -c $1 g++ -O2 -m32 $1.o -L$ROOTSYS/lib -lCore -lCint -lRIO -lNet -lHist -lGraf \ -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore \ -lThread -pthread -lm -ldl -lRooFit -rdynamic -o $1.exe</verbatim> ---++ Editing your macro to make it compile ---+++ Adding missing headers First off to make it run you will have to make sure all the correct headers are included, this will be macro dependant. The ones I have included are listed below. <verbatim>#include <iostream> #include <sstream> #include <string> #include <stdlib.h> #include <cmath> #include <TROOT.h> #include <TChain.h> #include <TCanvas.h> #include <TH1D.h> #include <TH2D.h> #include <TString.h> #include <RooRealVar.h> #include <RooPolynomial.h> #include <RooGaussian.h> #include <RooDataHist.h> #include <RooAddPdf.h> #include <RooPlot.h></verbatim> If you get error messages about a class being undefined just add a header for that class like #include ---+++ Make the code standards compliant You might need to explicitly cast variables to the correct type or make sure you are accessing pointers with -> and objects with a dot. Again you will have to work out the bugs in tyourr own code. ---++ Compile it I called the script above rootg++ so to compile Macro.C I run the following <verbatim>SetupProject Ganga ./rootg++ Macro.C</verbatim> This produces an executable (assuming it compiled on the first time which it won't) called Macro.C.exe which can be directly run. <verbatim>./Macro.C.exe</verbatim> -- Main.ThomasBird - 2010-07-30
This topic: LHCb
>
WebHome
>
ComputingResources
>
HowTos
>
HowToCompileRootMacros
Topic revision: r1 - 2010-07-30 - ThomasBird
Copyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback