Skip to content

Conversation

@hageboeck
Copy link
Member

When calling TDirectory::Append(obj, replace=true), and obj is already in the directory, return without doing anything.
If obj has the same name as an existing object, but is physically different, the usual warning is raised.

This will enable workflows such as:

   auto h = new TH1D(...);
   directory->Append(h, true);

After this change, the above lines work both with and without auto registration to gDirectory. This is needed to prepare ROOT for working without auto registration.

@dpiparo dpiparo self-requested a review January 14, 2026 19:52

if (replace && obj->GetName() && obj->GetName()[0]) {
TObject *old;
while (nullptr != (old = GetList()->FindObject(obj->GetName()))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The while loop implies that the list could contains multiple times the same names when this is called. In this case the net result was to remove all duplicates and add only the one passed.
With the new code it seems that if the list contains multiple time the same name and already contains the item being passed we can have:

  • before this PR: list contains only the argument
  • after this PR: list contains the argument and possibly many duplicates.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this should be addressed now!

Copy link
Member

@pcanal pcanal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment.

@github-actions
Copy link

Test Results

    23 files      23 suites   3d 18h 29m 37s ⏱️
 3 812 tests  3 812 ✅ 0 💤 0 ❌
80 407 runs  80 407 ✅ 0 💤 0 ❌

Results for commit 359e187.

When calling TDirectory::Append(obj, replace=true), and obj is already
in the directory, don't issue a warning. Proceed to clear the list of any
duplicates, issuing a warning for each.

This will enable workflows such as:
   auto h = new TH1D(...);
   directory->Append(h, true);

After this change, the above lines work both with implicit object
ownership off and on.
@hageboeck hageboeck requested a review from pcanal January 15, 2026 09:31
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.

3 participants