Skip to content

Commit df3c0db

Browse files
committed
Add Tools section
1 parent 2e08b47 commit df3c0db

File tree

11 files changed

+552
-8
lines changed

11 files changed

+552
-8
lines changed

docs/datamodel/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sort: 9
2+
sort: 10
33
title: Appendix: data model reference
44
---
55

docs/gettingstarted/gitbasics.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ Selected sections:
4848
- [git - the simple guide](https://rogerdudler.github.io/git-guide/)
4949
- [Oh Shit, Git!?!](https://ohshitgit.com/)
5050

51-
## Tips
52-
53-
### Tools
54-
55-
[Visual Studio Code (VS Code)](https://code.visualstudio.com/) – Integrated development environment
51+
## Tools
5652

5753
[Meld](https://meldmerge.org/) – Visual diff and merge tool that can be used with Git commands `git difftool` and `git mergetool`
5854

docs/gettingstarted/installing.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ Note that this directory tends to grow in size over time, and it is the one you
204204

205205
When `aliBuild`is installed on your computer and your prerequisits are statisfied, you can move to the next step.
206206

207+
See also [shell rc utilities](../tools/README.md#shell-rc-utilities).
208+
207209
## Prepare your source code
208210

209211
We assume your work area is `~/alice`.
@@ -318,6 +320,8 @@ For example: `ninja PWGCF/Tasks/install`
318320
ninja install > ../log 2>&1 && echo "Good" || echo "Bad"
319321
```
320322

323+
See also [shell rc utilities](../tools/README.md#shell-rc-utilities).
324+
321325
A specific executable can be built in the staging directory `stage/bin` with
322326

323327
```bash

docs/tools/README.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
sort: 8
3+
title: Tools
4+
---
5+
6+
# Tools
7+
8+
Tools which are not part of the O2(Physics) analysis framework and can make your work with it much more effective.
9+
10+
## Setup diagnostic tool
11+
12+
This simple Bash script prints a summary of some basic information about your system and your O2Physics installation setup.
13+
14+
It can be useful to provide this summary when [requesting support](../troubleshooting/README.md#reporting-problems) concerning a problem with your analysis framework.
15+
16+
Download the [`summarise_o2p_setup.sh`](summarise_o2p_setup.sh) script and run it with `bash` in your `alice` directory.
17+
18+
## Dependency finder
19+
20+
Tool to explore input/output dependencies between O2Physics workflows and tables.
21+
22+
See the dedicated [Dependency finder](dependencyFinder.md) page.
23+
24+
## O2 linter
25+
26+
Tool to detect O2-specific (and some common C++) issues in the code.
27+
28+
See the dedicated [O2 linter](o2linter.md) page.
29+
30+
## Pre-commit hooks
31+
32+
[Git hooks](https://git-scm.com/book/ms/v2/Customizing-Git-Git-Hooks) are scripts hooked to certain Git commands.
33+
Pre-commit hooks run when you execute `git commit` and are used to validate the staged changes that are about to be committed.
34+
If any hook fails, the commit is not made.
35+
36+
In the O2Physics repository, pre-commit hooks are [configured](https://github.com/AliceO2Group/O2Physics/blob/master/.pre-commit-config.yaml) to format C++ code with [clang-format](https://clang.llvm.org/docs/ClangFormat.html) and lint it (check for issues) with [cpplint](https://github.com/cpplint/cpplint).
37+
This way you can make sure that your changes will pass the C++ formatting check and the cpplint check in [MegaLinter](https://megalinter.io/) when you make your pull request.
38+
39+
### How to use pre-commit hooks
40+
41+
1. [Install pre-commit](https://pre-commit.com/#installation) (typically `pip install pre-commit`).
42+
1. Enter the `O2Physics` directory.
43+
1. [Install the Git hook scripts](https://pre-commit.com/#3-install-the-git-hook-scripts): `pre-commit install`.
44+
45+
Next time you execute `git commit`, the hooks will run automatically.
46+
47+
- If the clang-format hook fails, it means your staged files have been formatted.
48+
- If the cpplint hook fails, the linter has found issues that need to be fixed.
49+
- Updated files need to be staged with `git add` before attempting `git commit` again.
50+
51+
## [clang-tidy](https://clang.llvm.org/extra/clang-tidy/)
52+
53+
`clang-tidy` is a clang-based C++ linter tool for diagnosing and fixing typical programming errors, like style violations or bugs.
54+
(See the [list of checks](https://clang.llvm.org/extra/clang-tidy/checks/list.html).)
55+
56+
### Prerequisites for using clang-tidy
57+
58+
- You need to have O2Physics successfully compiled.
59+
- Verify that there is a valid symbolic link `compile_commands.json` in the O2Physics directory pointing to the `alice/sw/BUILD/.../O2Physics` directory.
60+
61+
### Tips
62+
63+
#### Cleaning `#include`s
64+
65+
The [`misc-include-cleaner`](https://clang.llvm.org/extra/clang-tidy/checks/misc/include-cleaner.html) check can fix missing and unused `#include`s.
66+
This helps to apply the [Include What You Use](https://github.com/AliceO2Group/O2Physics/issues/8357) principle which allows to maintain header dependencies clean.
67+
68+
#### Sorting `#include`s
69+
70+
The [`llvm-include-order`](https://clang.llvm.org/extra/clang-tidy/checks/llvm/include-order.html) check sorts `#include`s from most specific to least specific to ensure that the headers does not have any hidden dependencies.
71+
72+
Unfortunately, the [LLVM include style](https://llvm.org/docs/CodingStandards.html#include-style) is incompatible with the [Google include style](https://google.github.io/styleguide/cppguide.html#Names_and_Order_of_Includes) applied by `cpplint`.
73+
74+
#### Testing (and fixing) many files at once
75+
76+
Here is an example of how to run the `misc-include-cleaner` check in parallel on all `.h` and `.cxx` files in the current directory.
77+
78+
```bash
79+
parallel "clang-tidy --fix -checks=-*,misc-include-cleaner {}; echo \"{} \$?\"" ::: $(find -name "*.h" -o -name "*.cxx") > "clang-tidy.log"
80+
```
81+
82+
The [`parallel`](https://www.gnu.org/software/parallel/) command is used to parallelise the execution of the `clang-tidy` command for all files.
83+
84+
For each file, `clang-tidy` will first try to compile it and then run the enabled check(s) and fix found problems (the `--fix` option).
85+
The messages are redirected into `clang-tidy.log`.
86+
The file name and the exit code are printed below the output of `clang-tidy` so that you can get the list of files for which `clang-tidy` failed with `grep " 1$" "clang-tidy.log"`.
87+
88+
## [Visual Studio Code (VS Code)](https://code.visualstudio.com/)
89+
90+
Integrated development environment
91+
92+
See [how to run O2 linter from VS Code](o2linter.md#in-visual-studio-code)
93+
94+
### Useful extensions
95+
96+
- [clangd](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd) - C/C++ completion, navigation, and insights
97+
- [json](https://marketplace.visualstudio.com/items?itemName=ZainChen.json) - Json for Visual Studio Code
98+
- [Markdown All in One](https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one) - All you need to write Markdown (keyboard shortcuts, table of contents, auto preview and more)
99+
- [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) - Python language support with extension access points for IntelliSense (Pylance), Debugging (Python Debugger), linting, formatting, refactoring, unit tests, and more.
100+
- [Ruff](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff) - A Visual Studio Code extension with support for the Ruff linter and formatter.
101+
- [ShellCheck](https://marketplace.visualstudio.com/items?itemName=timonwong.shellcheck) - Integrates ShellCheck into VS Code, a linter for Shell scripts.
102+
- [YAML](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml) - YAML Language Support by Red Hat, with built-in Kubernetes syntax support
103+
- [Remote - SSH](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh) - Open any folder on a remote machine using SSH and take advantage of VS Code's full feature set.
104+
- [PDF Viewer](https://marketplace.visualstudio.com/items?itemName=mathematic.vscode-pdf) - Portable document format (PDF) viewer for Visual Studio Code.
105+
106+
## Shell rc utilities
107+
108+
You can use the [`bashrc-alice.sh`](bashrc-alice.sh) file to add ALICE-related utilities in your Bash environment.
109+
110+
The file provides:
111+
112+
- variables needed to [configure aliBuild](../gettingstarted/installing.md#installing-alibuild)
113+
- utility functions for [recompiling with `ninja`](../gettingstarted/installing.md#building-partially-for-development-using-ninja)
114+
- utility functions for [debugging compilation and runtime failures](../troubleshooting/README.md#finding-problems)
115+
116+
Add the [`bashrc-alice.sh`](bashrc-alice.sh) file in your home directory (`~`) and source it in your Bash environment by adding the following line in the `~/.bashrc` file.
117+
118+
```bash
119+
source bashrc-alice.sh
120+
```
121+
122+
## [Run 3 validation framework](https://github.com/AliceO2Group/Run3AnalysisValidation)
123+
124+
The Run 3 validation framework is a tool for an easy execution, testing and validation of any O2Physics analysis code on large local data samples.
125+
126+
It is extensively configurable and provides similar features as AliHyperloop, such as:
127+
128+
- Dataset management
129+
- Support of linked-derived-data input
130+
- Automatic JSON configuration based on input properties
131+
- Automatic workflow topology generation based on "wagon" dependencies
132+
- Job parallelisation
133+
- Table saving
134+
- Output merging
135+
- Diagnostics
136+
137+
Among several other utilities, it includes a [maintenance script](https://github.com/AliceO2Group/Run3AnalysisValidation?tab=readme-ov-file#keep-your-repositories-and-installations-up-to-date-and-clean) for automated maintenance of Git repositories and aliBuild packages.

docs/tools/bashrc-alice.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/bash
2+
3+
# alice
4+
5+
# aliBuild
6+
export ALIBUILD_WORK_DIR="$HOME/alice/sw"
7+
eval "$(alienv shell-helper)"
8+
9+
# aliases
10+
alias loadali='alienv enter AliPhysics/latest'
11+
alias loado2='alienv enter O2/latest'
12+
alias loado2p='alienv enter O2Physics/latest'
13+
alias root='root -l'
14+
15+
# Recompile an aliBuild development package with ninja.
16+
# Usage: recompile <package> <branch> <target>
17+
# Arguments <branch> and <target> are optional.
18+
# Command "recompile O2Physics" will invoke "ninja install" for the "master" branch of O2Physics.
19+
# Command "recompile O2Physics my-branch" will invoke "ninja install" for the "my-branch" branch of O2Physics.
20+
# Command "recompile O2Physics my-branch Common" will invoke "ninja Common/install" for the "my-branch" branch of O2Physics.
21+
recompile() {
22+
# set -o xtrace # to print out each command
23+
[ "$1" ] || { echo "Provide a package name"; return 1; }
24+
package="$1"
25+
branch="master"
26+
[ "$2" ] && branch="$2"
27+
target=""
28+
target_name="all"
29+
[ "$3" ] && { target="$3/"; target_name="$3"; }
30+
dir_pwd=$(pwd)
31+
dir_build="$ALIBUILD_WORK_DIR/BUILD/${package}-latest-${branch}/${package}"
32+
log="$(dirname "$dir_build")/log"
33+
log_err="$(dirname "$dir_build")/log_err"
34+
cd "$dir_build" || { echo "Could not enter $dir_build"; return 1; }
35+
direnv allow || { echo "Failed to allow direnv"; return 1; }
36+
eval "$(direnv export "$SHELL")"
37+
echo "Recompiling ${package}_${branch}_${target_name}..."
38+
start=$(date +%s)
39+
ninja "${target}install" > "$log" 2>&1
40+
ec=$?
41+
end=$(date +%s)
42+
echo "Compilation exited with: $ec"
43+
echo "See the log at: $log"
44+
if [ "$ec" != "0" ]; then
45+
grep -e "FAILED:" -e "error:" "$log" > "$log_err"
46+
echo "See the errors at: $log_err"
47+
fi
48+
echo "Took $((end - start)) seconds."
49+
cd "$dir_pwd" || return 1
50+
# set +o xtrace
51+
return $ec
52+
}
53+
54+
# Recompile O2 with ninja.
55+
recompile-o2() { recompile "O2" "$1" "$2"; }
56+
# Recompile O2Physics with ninja.
57+
recompile-o2p() { recompile "O2Physics" "$1" "$2"; }
58+
59+
# Find the workflow that produces a given table.
60+
# Limited functionality. Use find_dependencies.py for a full search.
61+
find-o2-table-producer() {
62+
# Check that we are inside the O2 or the O2Physics directory.
63+
[[ "$PWD/" != *"/O2"*"/"* ]] && { echo "You must be inside the O2 or the O2Physics directory."; return 1; }
64+
[ ! "$1" ] && { echo "Provide a table name."; return 1; }
65+
# Find files that produce the table.
66+
table="$1"
67+
echo "Table $table is produced in:"
68+
files=$(grep -r -i --include="*.cxx" "<aod::$table>" | grep -E 'Produces|Spawns' | cut -d: -f1 | sort -u)
69+
for f in $files; do
70+
# Extract the workflow name from the CMakeLists.txt in the same directory.
71+
wf=$(grep -B 1 "$(basename "$f")" "$(dirname "$f")/CMakeLists.txt" | head -n 1 | cut -d\( -f2)
72+
echo "$wf in $f"
73+
done
74+
}
75+
76+
# Find compilation error messages in a compilation log.
77+
debug-o2-compile() {
78+
[ "$1" ] || { echo "Provide a log file"; return 1; }
79+
grep -n -e "FAILED:" -e "error:" -e "warning:" "$1"
80+
}
81+
82+
# Find runtime error messages in an execution log.
83+
debug-o2-run() {
84+
[ "$1" ] || { echo "Provide a log file"; return 1; }
85+
grep -n -e "\\[ERROR\\]" -e "\\[FATAL\\]" -e "segmentation" -e "Segmentation" -e "SEGMENTATION" -e "command not found" -e "Program crashed" -e "Error:" -e "Error in " -e "\\[WARN\\]" -e "Warning in " "$1"
86+
}

0 commit comments

Comments
 (0)