How to call certain file whenever one is in the ROOT environment in terminal?

Hello ROOTers,

I want to execute certain C++ code whenever I enter into the ROOT environment from the terminal. For example, the welcome message is printed all the time as shown here

d@d:~$ root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.24/08                        https://root.cern |
  | (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Sep 29 2022, 13:04:57                 |
  | From tags/v6-24-08@v6-24-08                                      |
  | With                                                             |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0] 

Similarly, I want to execute, let’s say

std::cout << "Hello from ROOT env!!!" << std::endl;

Is it possible? This will save a lot of time similar to VS Code Snippets.

Best,
Divyang.

ROOT Version: 6.24/08
Platform: Ubuntu 20.04.6
Compiler: g++ 9.4.0

https://root.cern/doc/master/rootlogon_8C.html

Hi, this solution worked. However, is it possible to call this file whenever I’m in the subdirectories of the main project directory? Otherwise, I have to keep this file in all the subdirectories.

1 Like

FYI

I realized that rootalias.C is a better option compared to rootlogon.C. The reason is that the loading time for “root -l” is longer when rootlogon file is created in ${ROOTSYS}/macros.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.