Tags:
view all tags
---+!! 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 `root-config --cflags` -o $1.o -c $1 g++ -O2 $1.o `root-config --glibs` -lRooFit -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
Edit
|
Attach
|
Watch
|
P
rint version
|
H
istory
:
r4
<
r3
<
r2
<
r1
|
B
acklinks
|
V
iew topic
|
Raw edit
|
More topic actions...
Topic revision: r2 - 2010-08-06
-
ThomasBird
Home
Site map
Atlas web
CMS web
Computing web
Documentation web
PPDITForum web
LHCb web
PPDLabSpace web
Sandbox web
TWiki web
LHCb Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
P
P
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
Register User
Edit
Attach
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