Skip to content

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

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

[rfile] Allow setting object titles when writing#22898
silverweed wants to merge 5 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

    20 files      20 suites   3d 9h 4m 35s ⏱️
 3 856 tests  3 803 ✅ 0 💤 53 ❌
67 379 runs  67 325 ✅ 1 💤 53 ❌

For more details on these failures, see this check.

Results for commit c1f3eb3.

♻️ 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.

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.

4 participants