[Root7] A path to reducing global object registration and management.#18083
Open
hageboeck wants to merge 10 commits intoroot-project:masterfrom
Open
[Root7] A path to reducing global object registration and management.#18083hageboeck wants to merge 10 commits intoroot-project:masterfrom
hageboeck wants to merge 10 commits intoroot-project:masterfrom
Conversation
89bd358 to
4d29c60
Compare
pcanal
reviewed
Mar 20, 2025
Test Results 22 files 22 suites 3d 7h 37m 40s ⏱️ For more details on these failures, see this check. Results for commit cdbb2be. ♻️ This comment has been updated with latest results. |
silverweed
reviewed
Mar 21, 2025
4d29c60 to
1224a4b
Compare
b894456 to
167c0cc
Compare
342a3cb to
0ca4f8a
Compare
0ca4f8a to
68de9c4
Compare
1 task
68de9c4 to
9c5ce87
Compare
9c5ce87 to
b79032e
Compare
74a6279 to
8d9511a
Compare
0b52df2 to
c9f787b
Compare
3878984 to
0587de2
Compare
ea71574 to
d64008f
Compare
b3832cb to
69aac58
Compare
69aac58 to
04c468b
Compare
The ROOT 7 ownership settings don't affect TH1::AddDirectoryStatus, so objects read from a TFile associate themselves with that file. In light of adding the ROOT 7 mode "auto registration off", the doxygen was improved a bit.
- Don't rely on implicit registration to directories. - Make the test insensitive to any defaults by always adding the histogram to the file. - Make ruff happier.
- When the object auto registration is switched to ROOT 7 mode, the corresponding notification needs to be masked from output diffs and/or the RootTestDriver checks. - Ruff formatting
- Add Enable/DisableObjectAutoRegistration() in ROOT::Experimental. - Add a function to test if registration is on or off. - Allow for setting defaults using - The environment variable ROOT_OBJECT_AUTO_REGISTRATION - The rootrc variable Root.ObjectAutoRegistration
…ph2D. In locations where TH1::AddDirectoryStatus is queried, also query ObjectAutoRegistrationEnabled(). This extends the ROOT 7 testing mode to TH1 and derived classes, TGraph2D and TEfficiency.
This is supposed to test auto registration off across all platforms. Once approved, this commit will be removed, and a dedicated build will be used to keep testing this functionality until the release of ROOT 7.
04c468b to
cdbb2be
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the start of a longer-term effort to transform ROOT into working with less globals, making ownership of objects clearer, and going more towards standard C++ behaviour instead of implicit ownership. One could call this the "ROOT 7 mode". In order to allow for early testing, this mode is introduced as an opt-in feature in ROOT 6.
What this PR brings
TROOT.hgets three new functions (names up for discussion):https://github.com/hageboeck/root/blob/040980428a842a3314c75bde1ba9e6ae208fe8b1/core/base/inc/TROOT.h#L100-L104
The naming and API is inspired by
EnableImplicitMT()and its colleagues. These determine whether TObject-derived classes auto-register themselves togDirectorywhen created. A well-known example is TH1 and all its derived classes, but what's covered by these functions will be extended further on the path to ROOT 7. Currently, this mode also covers RooFit objects, TGraph, and TEfficiency.An extensive list of objects with auto registration and their state (maybe not fully complete) can be found below.
A lot of preparatory work was done to prepare ROOT to work both with auto registration on and off. A detailed list of this work can be found at the end. Currently, there is one commit that switches auto registration off across the entire CI to demonstrate that ROOT already today works in this mode. Once the PR is ready to merge, this commit will be removed to not break the workflows of ROOT's users who did not opt in. A single (or a few; TBD) builds with auto registration off will be added to the CI to keep test coverage for this feature.
TODO:
Difference to
TH1::AddDirectoryStatus()The ROOT 7 mode with auto registration off might look similar to
TH1::AddDirectoryStatus(), but there are important differences:ObjectAutoRegistrationEnabled()isthread_localTFile::Get.file->Get("name"); file->Get("name")returns the same object when directory status istrue, and it reads a new object every time when it'sfalse. I consider it best to not interfere here, because one can use TFile if such behaviour is desired, and RFile if not.AutoRegistrationEnabled()should only decide what happens to new objects, not objects read from a file.AutoRegistrationEnabled()can be initialised from the environment (thread safe), and its state can be changed per thread, which might be vital for using it in MT frameworks.Setting defaults
Some users or frameworks might be interested in operating in ROOT 7 mode already today, but they don't want to add calls to the above functions in each thread of their code. Especially for testing, they should be able to set a default without recompiling. Defaults can be set in a .rootrc:
and also using an environment variable:
When any object queries
ObjectAutoRegistrationEnabled(), a thread-safe initialisation is performed, taking defaults from the environment above. If no defaults are set, registration defaults to "on" in ROOT 6 and "off" in ROOT 7.This, however, might lead to an "it worked on my machine" problem: Some users might have altered their environment, while others might have chosen the opposite. To make it obvious when a ROOT 6 runs in ROOT 7 preview mode, info messages such as the following are printed if the environment modifies the default:
(A similar message exists for rootrc)
List of classes covered (or intended to be covered) by "DisableObjectAutoRegistration"
DisableObjectAutoRegistration()gDirectorybut to a global list of functions. Way forward to be decided.TODOs:
TH1::AddDirectory()as suggested in ReplaceTH1::AddDirectorybyTDirectory::TContext#21523 ?Preparatory work
The following PRs were part of this branch, and have been split off over time to separate the introduction of this feature from preparing ROOT to work both with auto registration off and on:
gDirectory, use TContext instead. #21287TH1::AddDirectorybyTDirectory::TContext#21523