BARS as an application framework

In ROOT you create a macro for data analysis. In BARS you can create an application - a compiled program that uses BARS as a library.

Compiled applications have several advantages over ROOT macros:

  • Your compiler (whether gcc or clang) will likely provide a better optimization then ROOT's interpreter or even ROOT's own compiler.
  • Compiler warnings will enforce a better coding style, which will help preventing both bugs and analysis errors.
  • Crashing a compiled program produces a usable stack trace. If a ROOT macro crashes, it can take the whole session down.
  • BARS provides a built-in facility for documentation and argument parsing. This makes sharing your code with colleagues much easier.
  • Compiled programs are regular UNIX processes and behave as such (signal handling etc). They can be piped to each other, killed wth Ctrl+C and manipulated by standard tools.
  • You can also debug BARS applications using established standard software (for example gdb). Debugging ROOT macros is notoriously complex.

Overall, we highly encourage use of the compiled BARS applications over interpreted ROOT macros.

You can download an application template with git, and start writing analysis code immediately - CMake will take care of linking your programm to ROOT and BARS.

See here for instructions on creating your first app and here for detailed documentation on BARS capabilities as an application framework.

Building your own application

To create a BARS appplication, simply clone this repository to a directory with the same name as your application.

Requirements

Only BARS installation is required. The exact steps are described here.

Installation and compilation

Clone this repository to a directory named as this app

$ git clone git@git.jinr.ru/Baikal/bars-app-standalone-example.git my-bars-app

Create a build directory.

$ cd my-bars-app
$ mkdir build

Create a Makefile and compile

$ cd build
$ cmake ..
$ make

Install it

$ make install

Congratulations, you've successfully created a BARS app. Here's the same thing, but as a bash script:

#!/usr/bin/env bash

APPNAME=$1

git clone git@git.jinr.ru/Baikal/bars-app-standalone-example.git $APPNAME
cd $APPNAME
mkdir build
cd build
cmake ..
make
make install

Running your app

You can now run my-bars-app in your shell as a standard comand and get a welcome message.

$ my-bars-app
Welcome to your BARS app!

Call --help for usage information.

$ my-bars-app --help

  ┏┓ ┏━┓┏━┓┏━┓
  ┣┻┓┣━┫┣┳┛┗━┓
  ┗━┛╹ ╹╹┗╸┗━┛
  Baikal Analysis and Reconstruction Software

Usage: my-bars-app [ options ]

Required options:

Other options:
    -h, --help                print this message
    -x, --config              path to a custom config file
    -v, --verbose             if set, the program will produce verbose output
    -i, --in                  input path
    -o, --out                 output path

Notice that options are split into 'requried' and 'other'. If a required option is missing, the app won't run.

App structure

Let's look what's inside the app repository we have cloned.

$ ls
build/  cmake/  CMakeLists.txt  README.md  src/

Here:

  • build - your build directory. Call make install in it every time you'd like to recompile your app.
  • cmake, CMakeLists.txt - CMake configuration and modules for finding BARS and ROOT. Do not change anything here, unless you're familiar with cmake.
  • README.md - readme file
  • src - Source code for your app