How to #include <myownheader.h> in rootlogon.C

_ROOT Version:6.29.01

Hi, all,
I’d want to load my own class when open ROOT prompt using rootlogon.C
when I use #include <myownheader.h> in rootlogon.C
meet the same problem with incomplete type

how ever I could use


in prompt, but it’s a little slower
an other way is to #include ".cc" file (I don’t want the way )

Hi @cxwx1 ,

I guess you need to both include the header (with gInterpreter->ProcessLine or gInterpreter->Declare) and load the library (with gInterpreter->Load or gSystem->Load).

Is there a faster way, using gInterpreter always cause 2 second to load the header file.

Declare might be faster than ProcessLine. 2 seconds seems like a lot though. Starting up the ROOT prompt and running a gInterpreter->Declare takes 0.2 seconds on my laptop.

This test uses ROOT v6.28.00 installed via conda:

/tmp cat myclass.h
class C {
  int a = 42;
  int b = 0;
/tmp /usr/bin/time root -l -q -e 'gInterpreter->Declare("#include \"myclass.h\"")' 

(bool) true
Command exited with non-zero status 1
0.14user 0.06system 0:00.21elapsed 100%CPU (0avgtext+0avgdata 266788maxresident)k
0inputs+0outputs (0major+23739minor)pagefaults 0swaps
/tmp /usr/bin/time root -l -q -e 'gInterpreter->Declare("#include \"myclass.h\"")' 

(bool) true
Command exited with non-zero status 1
0.15user 0.06system 0:00.21elapsed 100%CPU (0avgtext+0avgdata 266888maxresident)k
0inputs+8outputs (0major+23717minor)pagefaults 0swaps

I obtain similar runtimes with current head of the ROOT master branch compiled from source.

If you generated a dictionary for your classes, you should just have to load the library (and if you generate a rootmap or a module file as part of the dictionary generation, this loading should be automatic as long as the library location is in the LD_LIBRARY_PATH).

I try to use

#include <my.h>

but it seem che root prompt always starting with #include file first before other operation.
so the only way is to use gInterpreter?

I use header yaml-cpp and spdlog, the two lib’s header cause long time loading whenever using Declare or ProcessLine ?

can I speed up the without compiling the script?

If I understand correctly, when ROOT starts up you immediately declare to the interpreter your own class, which depends on yaml-cpp and spdlog. This is quite a bit of functionality that the interpreter has to just-in-time-compile. 2 seconds does not seem unreasonable for that as a one-time start-up cost. I bet g++ or clang++ would take a similar amount of time.

Maybe one thing you could try is to load your class with .L myclass.h+ (or the equivalent via gSystem->CompileMacro) which should skip recompilation after the first time.


1 Like

thanks, it worked, but still cause ~1 second,
I modify rootlogon.C with


Real Time = 1.12 seconds Cpu Time = 1.12 seconds
may be there are too many template on that two librarys.

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