/root/bat/INSTALL.md
1 Installation instructions {#cha-install}
2 =========================
3 
4 This document provides a short description of how to compile and use
5 BAT on your computer.
6 
7 Platforms
8 ----------
9 
10 BAT has been developed on Linux. The installation, unit tests, and
11 examples are run and known to work on Linux and Mac OS X. On Linux, we
12 test with gcc and on Mac OS X we use clang but both compilers should
13 work on either platform.
14 
15 Windows is not supported.
16 
17 Dependencies
18 -------------
19 
20 It is understood that all commands shown below are to be entered into
21 a terminal.
22 
23 ### Required: Basic tools
24 
25 BAT itself uses only C++03 features. Compilation and tests work
26 fine with gcc >= 4.3 and clang >= 3.3. But recent versions of ROOT
27 (see below) may require a C++11 compliant compiler.
28 
29 Under Debian or Ubuntu, you can install the essential requirements with
30 
31  sudo apt-get install build-essential curl
32 
33 In order to use the development version of BAT instead of an official
34 release, some more packages are needed
35 
36  sudo apt-get install autoconf automake git-core libtool
37 
38 Building and installing works with autoconf >= 2.63 and automake >= 1.10. To run
39 the tests, a more recent automake version is needed, v1.15 is known to be
40 sufficient.
41 
42 ### Required: ROOT
43 
44 ROOT is an object-oriented data-analysis framework. At http://root.cern.ch/, you
45 can obtain the source code as well as binary distributions for a number of Linux
46 distributions and Mac OS X versions. We advise to download the latest production
47 release of ROOT. BAT is compatible with ROOT >=5.34.19 and ROOT 6. We regularly
48 run unit tests with ROOT 5 and ROOT 6 to ensure backward compatibility.
49 
50 On Linux, an alternative is to check your package manager for the availability
51 of ROOT packages. Usually these packages are rather old but often they are good
52 enough to build BAT. For example on Ubuntu systems up to 16.04, you can
53 conveniently install the requirements with
54 
55  sudo apt-get install libroot-graf2d-postscript-dev libroot-graf3d-g3d-dev\
56  libroot-math-foam-dev libroot-math-minuit-dev\
57  libroot-math-physics-dev libroot-math-mathmore-dev\
58  libroot-roofit-dev root-system-bin
59 
60 #### Note
61 
62 For the interface to RooFit/RooStats, ROOT must be compiled with
63 support for RooFit and MathMore, the latter relies on the GNU
64 scientific library (GSL).
65 
66 ### Optional: Cuba
67 
68 Cuba is a library containing general-purpose multidimensional
69 integration algorithms. It can be obtained from
70 http://www.feynarts.de/cuba/. BAT is compatible with Cuba versions 3.3
71 through at least 4.2.
72 
73 Cuba is not necessary to run BAT. We recommend it for model comparison
74 where expensive integrals are needed. Cuba provides integration
75 routines tuned for performance, which are useful for integration in
76 problems with not too many dimensions (~10). By default, Cuba will
77 evaluate in parallel and take all idle cores; the number of cores can
78 be set through an environment variable. For a single core, set
79 
80  CUBACORES=1
81 
82 The recommended way to get Cuba is to configure BAT with the option
83 
84  --with-cuba=download
85 
86 This will download a compatible version of Cuba to the local subdirectory
87 `external/cuba-VERSION`, compile it, and configure BAT to use it.
88 
89 If you want to compile Cuba manually, make sure it is built with
90 position-independent code:
91 
92  ./configure CFLAGS='-fPIC -O3 -fomit-frame-pointer -ffast-math -Wall'
93  make
94  make install
95 
96 Building
97 ----------------------
98 
99 ### Obtaining BAT
100 
101 You can download the latest release of BAT from
102 http://mpp.mpg.de/bat/. Open a terminal, unpack the tarball usually
103 named like BAT-x.x.tar.gz (here x.x is the version number) and switch
104 to the directory
105 
106  tar -xzf BAT-x.x.tar.gz
107  cd BAT-x.x
108 
109 Alternatively, you can clone the git repository https://github.com/bat/bat (we
110 recommend using the master branch):
111 
112  git clone https://github.com/bat/bat
113  cd bat
114  ./autogen.sh
115 
116 Now start the configuration with
117 
118  ./configure
119 
120 This will check your system for all components needed to compile BAT
121 and set up the paths for installation. You can add the option
122 `--prefix=/path/to/install/bat` to `./configure`. The BAT library
123 files will then be installed to `$prefix/lib` and the include files to
124 `$prefix/include`. The default installation prefix is `/usr/local`,
125 which requires super-user privileges.
126 
127 You can list all available options using
128 
129  ./configure --help
130 
131 In the following, we describe the most useful options in detail.
132 
133 ### ROOT
134 
135 The configure script checks for ROOT availability in the system and
136 fails if ROOT is not installed. You can specify the `ROOTSYS` directory
137 using `--with-rootsys=/path/to/rootsys`
138 
139 BAT support for RooFit/RooStats is turned off by default. The feature
140 can be turned on explicitly with `--enable-roostats`. The configure
141 script will check whether the version of ROOT is sufficient and
142 whether ROOT was compiled with RooFit/RooStats support.
143 
144 ### openMP
145 
146 Support for openMP threading to run multiple Markov chains in parallel
147 is available through the configure option `--enable-parallel`;
148 it is disabled by default. This requires a version of gcc accepting
149 the `-fopenmp` flag, anything >= 4.2 should suffice. Note that if
150 threads are enabled, the default number of threads actually used is
151 implementation dependent and may also depend on the current load of
152 the CPU. Manual control over the number of threads is achieved
153 entirely by openMP means such as setting the environment variable
154 `OMP_NUM_THREADS` before running an executable.
155 
156 The default version of clang does not implement openMP.
157 
158 ### Cuba
159 
160 If you configured BAT with the option `--with-cuba=download`, BAT will
161 download, compile, and use Cuba automatically. For manual
162 configuration, use the configure option `--with-cuba[=DIR]` to enable
163 Cuba. If you installed Cuba including the `partview` executable, the
164 Cuba installation path will be derived from its location. Otherwise,
165 the configure script will search for `libcuba.a` and `cuba.h` in the
166 system paths. If you manually specify the Cuba install path as `DIR`,
167 configure will look in `DIR/lib/` and `DIR/include/` instead. For
168 more fine-grained control, use
169 `--with-cuba-include-dir=/path/to/cuba/header` and
170 `--with-cuba-lib-dir=/path/to/cuba/lib`.
171 
172 ### Advanced options
173 
174 If you want to be able to step through BAT line by line with a
175 debugger, use `--enable-debug`. This slows down execution as it turns
176 off code optimization but it improves the compilation time. Another
177 way to speed up the build is to create only shared libraries if you
178 don't need static libraries: `--disable-static`. Finally, you can
179 reduce the output to the terminal with `--enable-silent-rules`.
180 
181 ### Compile
182 
183 After a successful configuration, run
184 
185  make
186  make install
187 
188 to compile and install BAT. Note that depending on the setting of the
189 installation prefix you might need super-user privileges to be able to
190 install BAT and run `sudo make install` instead of plain `make
191 install`. In the former case, you might need to run `sudo ldconfig`
192 just once to help the loader pick up the new libraries immediately.
193 
194 System setup
195 ------------
196 
197 After installation, BAT offers two mechanisms to make BAT available:
198 
199 1. The script `bat-config` returns details of the BAT installation
200  directories and compilation settings; see `bat-config`.
201 
202 2. The file `bat.pc` contains the same information as above and can be
203  used by the more powerful `pkg-config`; e.g.,
204 
205  pkg-config --modversion bat
206  pkg-config --libs bat
207 
208 If you do not install BAT to the system directories, you need to
209 manually add the path to `bat-config`, `bat.pc`, the libraries, and
210 the include files to the search paths. Depending on your shell, the
211 set of commands on linux for bash-compatible shells is
212 
213  BATPREFIX="/bat/install/prefix"
214  export PATH="$BATPREFIX/bin:$PATH"
215  export LD_LIBRARY_PATH="$BATPREFIX/lib:$LD_LIBRARY_PATH"
216  export CPATH="$BATPREFIX/include:$CPATH"
217  export PKG_CONFIG_PATH="$BATPREFIX/lib/pkgconfig:$PKG_CONFIG_PATH"
218 
219 and for csh-compatible shells is
220 
221  set BATPREFIX = /bat/install/prefix
222  setenv PATH "${BATPREFIX}/bin:${PATH}"
223  setenv LD_LIBRARY_PATH "${BATPREFIX}/lib:${LD_LIBRARY_PATH}"
224  setenv CPATH "${BATPREFIX}/include:${CPATH}"
225  setenv PKG_CONFIG_PATH "${BATPREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}"
226 
227 If you want to make BAT permanently available, add the above commands
228 to your login script, for example to `.profile` or to `.bashrc`.
229 
230 On Mac OS X you do not have to set up `LD_LIBRARY_PATH` because we use
231 the `rpath` option to make BAT compatible with the SIP feature enabled
232 by default on Mac OS X starting with El Capitan.
233 
234 Updating `$CPATH` is required if you work with interactive ROOT macros
235 that use BAT (both for ROOT 5 and 6).
236 
237 The minimal setup does not require setting `PKG_CONFIG_PATH` to run
238 BAT unless you want to integrate BAT into another probject using
239 `pkg-config`. BAT itself does not use `pkg-config`.
240 
241 Including BAT in your project
242 -----------------------------
243 
244 The most basic way to compile and link a file `example.cxx` with BAT is
245 
246  gcc `bat-config --cflags` `bat-config --libs` example.cxx -o
247 
248 In a makefile, simply query `bat-config` to set appropriate
249 variables. However, there will be an error at runtime, for example in
250 interactive ROOT macros, if
251 
252  libBAT.so, libBATmodels.so, libBATmtf.so,
253  libBAT.rootmap, libBATmodels.rootmap, libBATmtf.rootmap
254 
255 are not in the directories searched by the library loader; see above how
256 to setup the `LD_LIBRARY_PATH` and the `CPATH`.
257 
258 Interactive ROOT macros
259 -----------------------
260 
261 Due to problems in ROOT 6.02.00, it is important to create an instance
262 of a BAT class before calling any free function defined in the BAT
263 libraries. Else `cling` will emit confusing
264 [error messages](https://github.com/bat/bat/issues/5). For example,
265 the right order would be
266 
267  int main() {
268  BCLog::OpenLog("log.txt");
269  BCAux::SetStyle();
270  ...
271  }
272 
273 instead of the other way around around because `OpenLog` creates a
274 singleton object.
275 
276 Contact
277 -------
278 
279 Please consult the BAT web page http://mpp.mpg.de/bat/ for further
280 information. In case of questions or problems, please don't hesitate
281 to create an issue at https://github.com/bat/bat/issues/ or contact
282 the authors directly via email through bat@mpp.mpg.de.