Skip to content

[rfile] Allow setting object titles when writing - #22898

Closed
silverweed wants to merge 8 commits into
root-project:masterfrom
silverweed:rfile_cleanups
Closed

silverweed wants to merge 8 commits into
root-project:masterfrom
silverweed:rfile_cleanups

Conversation

@silverweed

Copy link
Copy Markdown
Contributor

This Pull request:

Adds the ability of storing object titles when writing objects to RFile.

CAVEATS/to be discussed:

  • TObjects are not treated specially, meaning that if your TObject has a title it won't be used automatically when storing the object (for that you need an explicit rfile->Put("obj", obj, obj->GetTitle()));
  • Doing a rfile->Put("obj", myTObject, "My Title") will not set myTObject's title, but only its key's. This means that this potentially unexpected behavior will occur:
rfile->Put("myobj", myobj, "obj title");
auto myobj2 = rfile->Get<MyTObj>("myobj");
cout << myobj2->GetTitle() << "\n";  // prints ""

In order to retrieve the object's title you'd need to do it from the key:

auto keyInfo = rfile->GetKeyInfo("myobj").value();
cout << keyInfo.GetTitle() << "\n"; // prints "obj title"

To be discussed: are we ok with this behavior or do we want bespoke TObject/TNamed code in the implementation to mitigate these pitfalls?

@github-actions

github-actions Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Test Results

    23 files      23 suites   3d 18h 36m 4s ⏱️
 3 895 tests  3 890 ✅ 0 💤 5 ❌
79 613 runs  79 608 ✅ 0 💤 5 ❌

For more details on these failures, see this check.

Results for commit df0866b.

♻️ This comment has been updated with latest results.

@jblomer jblomer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am actually more in favor of special behavior for TObject arguments that understands/uses their title member. We can discuss.

Comment thread io/io/inc/TDirectoryFile.h Outdated
@hageboeck

Copy link
Copy Markdown
Member

To be discussed: are we ok with this behavior or do we want bespoke TObject/TNamed code in the implementation to mitigate these pitfalls?

I tend to lean towards bespoke code. Should we discuss this in a (zoom) meeting with a few people?

@silverweed

silverweed commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor Author

I am actually more in favor of special behavior for TObject arguments that understands/uses their title member. We can discuss.

I tend to lean towards bespoke code. Should we discuss this in a (zoom) meeting with a few people?

To be clear:

  1. I can add the following behavior:
// since a title wasn't passed to `Put`, the object key's title is implicitly set to `myTNamed.GetTitle()`
rfile->Put("myTNamed", myTNamed); 
  1. but I cannot add the following:
TNamed myTNamed;
// `myTNamed`'s title gets set to `"my title"`
rfile->Put("myTNamed", myTNamed, "my title");

This is because myTNamed is passed as a const &, so it cannot be modified.

Disadvantage of implementing 1: if we want a concise way to tell rfile "ignore this object's title and save it without title" for TNamed objects we need to implement an overload of Put that allows distinguishing between passing an empty title and no title at all (because currently "no title passed" is the same as "empty title passed")

EDIT: for reference, see latest commit.

@pcanal

pcanal commented Oct 21, 2026

Copy link
Copy Markdown
Member

rfile->Put("myTNamed", myTNamed, "my title");
This is because myTNamed is passed as a const &, so it cannot be modified.

I am confused why this is an issue? rfile->Put("myTNamed", myTNamed); use the first parameter whether or not it matches the name of the TNamed, so why wouldn't Put("myTNamed", myTNamed, "my title"); use the third parameter as a title whether or not it matches the TNamed's title?

And since we are overloading, can't we also support:

Put(const TNamed &obj) { PutInternal(obj.GetName(), obj, obj.GetTitle()); } 

@silverweed

silverweed commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

rfile->Put("myTNamed", myTNamed, "my title");
This is because myTNamed is passed as a const &, so it cannot be modified.

I am confused why this is an issue? rfile->Put("myTNamed", myTNamed); use the first parameter whether or not it matches the name of the TNamed, so why wouldn't Put("myTNamed", myTNamed, "my title"); use the third parameter as a title whether or not it matches the TNamed's title?

It's not really an issue, unless the user expects the object's name/title to be changed by the Put call (which they shouldn't expect given the signature).

And since we are overloading, can't we also support:

Put(const TNamed &obj) { PutInternal(obj.GetName(), obj, obj.GetTitle()); } 

I actually might like this option better than my current one. With this we could have:

  • the "regular" overload of Put(string_view path, const T &obj, string_view title = "") which sets the title to whichever string the user passes/doesn't pass (no special treatment of TNamed)
  • the TNamed-specific overload of Put(const TNamed &obj) which does what you wrote.

@silverweed

Copy link
Copy Markdown
Contributor Author

Replaced by #23807

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants