Skip to content

Unset DISPLAY to avoid importing ROOT when not showing plots #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 13, 2025

Conversation

jmcarcell
Copy link
Member

@jmcarcell jmcarcell commented May 14, 2025

BEGINRELEASENOTES

  • Unset DISPLAY to avoid importing ROOT when not showing plots

ENDRELEASENOTES

In my testing unsetting the environment variable DISPLAY seems to be enough to disable showing plots. The reason to do this is that importing ROOT is slow (on my desktop it is ~0.5 seconds) so it's better if we can avoid it.

If DISPLAY is set, then batch mode is guaranteed not to be set: https://github.com/root-project/root/blob/ee9e36b3c7b9209a5ae1f1f4f7a8e4afba104c25/core/base/src/TROOT.cxx#L875

Can you please test it @Zehvogel (since you found this originally in #207)? You can copy and paste the k4run script in this PR without building anything.

I also thought about changing the option from --interactive-root to --interactive-graphics since all graphics will be disabled (I think), but it's true that most likely it's ROOT graphics what someone wants to see.

@Zehvogel
Copy link
Contributor

If DISPLAY is set, then batch mode is guaranteed not to be set: https://github.com/root-project/root/blob/ee9e36b3c7b9209a5ae1f1f4f7a8e4afba104c25/core/base/src/TROOT.cxx#L875

Do we want to rely on this implementation detail of ROOT? Or is this documented as an actual guarantee somewhere?
Also, testing anything with graphics from my side will have to wait until end of next week.

@jmcarcell
Copy link
Member Author

jmcarcell commented May 14, 2025

Well it's more a Linux thing since DISPLAY is set by the display managers, and it's not set if you don't have graphics (so programs have to also handle this case). In a desktop session, f you unset DISPLAY lots of things will not work, and it is used to know where to display things (you can have multiple displays). This is why I say that in that case maybe --interactive-graphics is a better option than --interactive-root since you are disabling probably all graphics (although most of the time it is ROOT anyway). So I don't think it's that much of an implementation detail, actually it is more general as we are probably stopping any graphics output.

@tmadlener
Copy link
Contributor

tmadlener commented May 14, 2025

Do we want to rely on this implementation detail of ROOT?

Also that line has last changed (according to git) 25 years ago, when ROOT went from cvs to svn, so I would consider the behavior fairly stable for now ;). We should document that k4run unsets DISPLAY by default however to avoid surprises for users.

edit: One thing that might break with this is https://github.com/key4hep/k4MarlinWrapper/blob/main/k4MarlinWrapper/examples/event_display.py . I am not entirely sure since technically glced is started before k4run in an environment where DISPLAY is still set, but I don't know whether connecting to that from the wrapped marlin processor needs DISPLAY or not.

@andresailer
Copy link
Contributor

BTW: this issue in ROOT is probably relevant for the general issue: root-project/root#18744

@jmcarcell
Copy link
Member Author

I'm happy with this as it is. Once root-project/root#18744 is merged we can also use that but in the meanwhile this works as intended for me.

@jmcarcell jmcarcell enabled auto-merge (squash) June 13, 2025 11:43
@jmcarcell jmcarcell merged commit a072995 into main Jun 13, 2025
7 checks passed
@jmcarcell jmcarcell deleted the unset-DISPLAY branch June 13, 2025 11:46
@jmcarcell
Copy link
Member Author

Unfortunately this seems not to be so easy. Running the ported Conformal Tracking prints what seems to be harmless errors:

TUnixSystem::Se...  ERROR Can't figure out DISPLAY, set it manually
In case you run a remote ssh session, restart your ssh session with:
=========>  ssh -Y
TUnixSystem::Se...  ERROR Can't figure out DISPLAY, set it manually
In case you run a remote ssh session, restart your ssh session with:
=========>  ssh -Y

This doesn't happen when running other algorithms that create ROOT histograms and write them to a file. Also, it doesn't happen when running the CLD reconstruction. I'm not sure why it happens for Conformal Tracking, maybe something that is done related to ROOT from DDKaltest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants