|
| 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. |
0 commit comments