Tips & Tricks

Key generation for SSH

If you do not like to keep having to enter your password, have a look at generating an ssh key here and here.

  1. Generate a key with the command ssh-keygen. You can choose to leave the password empty.

  2. Add the SSH key to the ssh-agent and create a corresponding public key with the commands:

    eval $(ssh-agent -s); ssh-add ~/.ssh/id_rsa
  3. Copy the public key to the server using:

    ssh-copy-id -i ~/.ssh/id_rsa.pub <your user name>@lxlogin.ihep.ac.cn

    You will be asked for your IHEP account password.

  4. Try to log in to the server with:

    ssh -Y <your user name>@lxlogin.ihep.ac.cn

    If all went correctly, you don’t have to enter your password anymore.

Installing ROOT

The BOSS Starter Kit comes with a handy bash script to download and install CERN ROOT6 on a Ubuntu platform. It requires you to have sudo (admin) rights. The script can be run in one go using:

wget https://raw.githubusercontent.com/redeboer/BOSS_StarterKit/master/utilities/InstallCernRoot.sh
sudo bash InstallCernRoot.sh

For more information, see the official pages:

Warning

You will download around 1 GB of source code.

Visual Studio Code

Visual Studio Code (VSCode) is a popular IDE that is regularly updated, is configurable with easy-to-access json files, and offers a growing number of user-developed extensions. In recent years, it is has become the most widely used editor on the market.

Remote SSH

For working with VSCode on lxlogin, you can use the Remote - SSH extension. This lets you with VSCode work on the server with full functionality, such as using the Source Control Manager and language navigation from any other VSCode extensions you installed. See here for a tutorial on how to connect to a remote SSH server.

There is one thing you need to change in your VSCode settings. Following these instructions, set the following option:

VSCode also recommends settings "remote.SSH.showLoginTerminal": true, but this seems not to be required to get VSCode to run on the IHEP server.

  "remote.SSH.useLocalServer": false,

VSCode Remote SSH installs some files into your home directory on the server, in a folder called .vscode-server. It is therefore recommended that you set the installation location for the .vscode-server folder to a directory where you always have read-write access. This can be done in VSCode by the setting:

  "remote.SSH.serverInstallPath": {
    "ihep": "/besfs5/users/<USERNAME>"
  },

The <USERNAME> needs to be replaced with your clustering account name.

In addition, you may need to set the remote platform to "linux":

  "remote.SSH.remotePlatform": {
    "lxlogin.ihep.ac.cn": "linux"
  },

where "lxlogin.ihep.ac.cn" is the name of the host in your SSH Config file.

Tip

As an alternative you can move the .vscodefolder and create a symbolic link in your home directory. Do this as follows:

cd ~
mkdir /besfs5/users/$USER/.vscode-server
ln -s /besfs5/users/$USER/.vscode-server

An existing .vscode-server folder in your home directory can cause Visual Studio Code to get stuck at trying to download the server configuration. The solution is to move the existing .vscode-server folder to the new location:

cd ~
mv -f .vscode-server /besfs5/users/$USER/
ln -s /besfs5/users/$USER/.vscode-server

For the (rather common) problem of a permission error when trying to move the directory, see here.

Another major advantage of this set-up is that you won’t have problems with data quota when the .vscode-server grows over time.

Language navigation for BOSS

It is highly recommended to install the VS Code C++ extension when you are developing BOSS packages. One of its killer features is intellisense, which gives language navigation on C++ libraries. To get full language navigation for BOSS, create a c_cpp_properties.json file under the .vscode folder in your workspace with the following content:

Note

Please comment here if you still see squiggle lines under #include statements in your source code. It could be that the list of include paths has to be updated.

{
  "configurations": [
    {
      "cStandard": "c99",
      "cppStandard": "c++03",
      "includePath": [
        "${workspaceFolder}/**",
        "/cvmfs/bes3.ihep.ac.cn/bes3sw/Boss/7.0.9/InstallArea/include/**",
        "/cvmfs/bes3.ihep.ac.cn/bes3sw/ExternalLib/SLC6/ExternalLib/external/BesGDML/2.8.0/x86_64-slc6-gcc46-opt/include",
        "/cvmfs/bes3.ihep.ac.cn/bes3sw/ExternalLib/SLC6/ExternalLib/external/BesGDML/2.8.0/x86_64-slc6-gcc46-opt/include/Common/Saxana",
        "/cvmfs/bes3.ihep.ac.cn/bes3sw/ExternalLib/SLC6/ExternalLib/external/BesGDML/2.8.0/x86_64-slc6-gcc46-opt/include/Common/Schema",
        "/cvmfs/bes3.ihep.ac.cn/bes3sw/ExternalLib/SLC6/ExternalLib/external/BesGDML/2.8.0/x86_64-slc6-gcc46-opt/include/G4Binding/**",
        "/cvmfs/bes3.ihep.ac.cn/bes3sw/ExternalLib/SLC6/ExternalLib/external/ROOT/5.34.09/x86_64-slc6-gcc46-opt/root/include",
        "/cvmfs/bes3.ihep.ac.cn/bes3sw/ExternalLib/SLC6/ExternalLib/external/clhep/2.0.4.5/x86_64-slc6-gcc46-opt/include",
        "/cvmfs/bes3.ihep.ac.cn/bes3sw/ExternalLib/SLC6/ExternalLib/external/geant4/10.4/include/**",
        "/cvmfs/bes3.ihep.ac.cn/bes3sw/ExternalLib/SLC6/ExternalLib/external/mysql/5.5.14/x86_64-slc6-gcc46-opt/include",
        "/cvmfs/bes3.ihep.ac.cn/bes3sw/ExternalLib/SLC6/ExternalLib/gaudi/GAUDI_v23r9/InstallArea/x86_64-slc6-gcc46-opt/include",
        "/usr/include/c++/4.8.2"
      ],
      "name": "Linux"
    }
  ],
  "version": 4
}

This file can be downloaded here. On the server, you can quickly do this by navigating to your .vscode folder and running:

wget https://raw.githubusercontent.com/redeboer/bossdoc/main/appendices/c_cpp_properties.json
Tip

For BOSS language navigation locally, have a look at BOSS_ExternalLibs.

Compiling

For compiling outside ROOT (that is, not using the ROOT interpreter), you will need to use a compiler like g++. The compiler needs to be told where the libraries for included ROOT header files are located. You can do this using flags that ROOT set during its installation. In case of g++, use:

g++ YourCode.C -I$(root-config --incdir) $(root-config --libs --evelibs --glibs) -o YourBinaryOutput.o
TipPro bash tip

You might like to create an easy command for this. You can do this by adding the following lines to your ~/.bashrc.

function rtcompile () {
  g++ "$1"
    -I$(root-config --incdir) \
    $(root-config --libs --evelibs --glibs) \
    -lRooFit -lRooFitCore -lRooStats -lMinuit -o "${1/._/.o}"
}
function rtcompilerun () {
  rtcompile "$1"
  if [ $? -eq 0 ]; then
    ./${1/._/.o}
  fi
}
function rtdebugcompile () {
  g++ "$1"
    -I$(root-config --incdir) \
    $(root-config --libs --evelibs --glibs) \
    -lRooFit -lRooFitCore -lRooStats -lMinuit -fsanitize=address -g -o "${1/.\*/}"
}
export -f rtcompile
export -f rtcompilerun
export -f rtdebugcompile

Note the flags added through root-config: there are includes (preceded by option -I) and linked libraries (following that option, and preceding output option -o). Note also that flags have been added for RooFit. For more information about ROOT flags, see this page.

Here, we give three examples of commands, one for compiling only (rtcompile), one for compiling and executing if successful (rtcompilerun), and one for compiling with fsanitize activated (rtdebugcompile). The latter is useful if you want to look for memory leaks etc — only use if you are interested in this, because it will decrease run-time. In addition, there are many issues in root (like TString) that are identified by fsanitize.

Compiling on Windows 10

Although it is highly recommended to on a Linux OS such as Ubuntu or CentOS, there are still -certain advantages of working on Windows. As a developer, that brings problems, however, if you want to start compiling your code.

Since Windows 10, there exists an easy solution: Windows Subsystem for Linux (WSL). In the newest versions can be easily installed from the Windows Store (search for “Ubuntu”). After installing, search for “Ubuntu” in the start menu. This is a bash terminal that has full access to your windows system, but entirely through bash commands.

As such, you have access to convenient commands like apt install, vi, and g++. Best of all is that you can use this to install ROOT. If you are having trouble installing ROOT through bash, have a look at this script (ROOT6).